OSDN Git Service

Fix untranslated strings
[winmerge-jp/winmerge-jp.git] / Src / DiffItemList.cpp
1 /**
2  *  @file DiffItemList.cpp
3  *
4  *  @brief Implementation of DiffItemList
5  */ 
6
7 #include "DiffItemList.h"
8 #include <cassert>
9
10 /**
11  * @brief Constructor
12  */
13 DiffItemList::DiffItemList()
14 {
15 }
16
17 /**
18  * @brief Destructor
19  */
20 DiffItemList::~DiffItemList()
21 {
22         RemoveAll();
23 }
24
25 /**
26  * @brief Add new diffitem to structured DIFFITEM tree.
27  * @param [in] parent Parent item, or NULL if no parent.
28  * @return Pointer to the added item.
29  */
30 DIFFITEM* DiffItemList::AddDiff(DIFFITEM *parent)
31 {
32         DIFFITEM *p = new DIFFITEM;
33         if (parent)
34                 parent->children.Append(p);
35         else
36                 m_root.Append(p);
37         p->parent = parent;
38         return p;
39 }
40
41 /**
42  * @brief Remove diffitem from structured DIFFITEM tree
43  * @param diffpos position of item to remove
44  */
45 void DiffItemList::RemoveDiff(uintptr_t diffpos)
46 {
47         DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
48         p->RemoveSelf();
49         delete p;
50 }
51
52 /**
53  * @brief Empty structured DIFFITEM tree
54  */
55 void DiffItemList::RemoveAll()
56 {
57         while (m_root.IsSibling(m_root.Flink))
58                 RemoveDiff((uintptr_t)m_root.Flink);
59 }
60
61 /**
62  * @brief Get position of first item in structured DIFFITEM tree
63  */
64 uintptr_t DiffItemList::GetFirstDiffPosition() const
65 {
66         return (uintptr_t)m_root.IsSibling(m_root.Flink);
67 }
68
69 /**
70  * @brief Get position of first child item in structured DIFFITEM tree
71  * @param  parentdiffpos [in] Position of parent diff item 
72  * @return Position of first child item
73  */
74 uintptr_t DiffItemList::GetFirstChildDiffPosition(uintptr_t parentdiffpos) const
75 {
76         DIFFITEM *parent = reinterpret_cast<DIFFITEM *>(parentdiffpos);
77         if (parent)
78                 return (uintptr_t)parent->children.IsSibling(parent->children.Flink);
79         else
80                 return (uintptr_t)m_root.IsSibling(m_root.Flink);
81 }
82
83 /**
84  * @brief Get position of next item in structured DIFFITEM tree
85  * @param diffpos position of current item, updated to next item position
86  * @return Diff Item in current position
87  */
88 const DIFFITEM &DiffItemList::GetNextDiffPosition(uintptr_t & diffpos) const
89 {
90         DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
91         if (p->HasChildren())
92         {
93                 diffpos = GetFirstChildDiffPosition(diffpos);
94         }
95         else
96         {
97                 DIFFITEM *cur = p;
98                 do
99                 {
100                         if (cur->parent)
101                                 diffpos = (uintptr_t)cur->parent->children.IsSibling(cur->Flink);
102                         else
103                                 diffpos = (uintptr_t)m_root.IsSibling(cur->Flink);
104                         cur = cur->parent;
105                 } while (!diffpos && cur);
106         }
107         return *p;
108 }
109
110 /**
111  * @brief Get position of next item in structured DIFFITEM tree
112  * @param diffpos position of current item, updated to next item position
113  * @return Diff Item (by reference) in current position
114  */
115 DIFFITEM &DiffItemList::GetNextDiffRefPosition(uintptr_t & diffpos)
116 {
117         return (DIFFITEM &)GetNextDiffPosition(diffpos);
118 }
119
120 /**
121  * @brief Get position of next sibling item in structured DIFFITEM tree
122  * @param diffpos position of current item, updated to next sibling item position
123  * @return Diff Item in current position
124  */
125 const DIFFITEM &DiffItemList::GetNextSiblingDiffPosition(uintptr_t & diffpos) const
126 {
127         DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
128         if (p->parent)
129                 diffpos = (uintptr_t)p->parent->children.IsSibling(p->Flink);
130         else
131                 diffpos = (uintptr_t)m_root.IsSibling(p->Flink);
132         return *p;
133 }
134
135 /**
136  * @brief Get position of next sibling item in structured DIFFITEM tree
137  * @param diffpos position of current item, updated to next sibling item position
138  * @return Diff Item (by reference) in current position
139  */
140 DIFFITEM &DiffItemList::GetNextSiblingDiffRefPosition(uintptr_t & diffpos)
141 {
142         return (DIFFITEM &)GetNextSiblingDiffPosition(diffpos);
143 }
144
145 /**
146  * @brief Alter some bit flags of the diffcode.
147  *
148  * Examples:
149  *  SetDiffStatusCode(pos, DIFFCODE::SAME, DIFFCODE::COMPAREFLAGS)
150  *   changes the comparison result to be the same.
151  * 
152  *  SetDiffStatusCode(pos, DIFFCODE::BOTH, DIFFCODE::SIDEFLAG)
153  *   changes the side status to be both (sides).
154  *
155  * SetDiffStatusCode(pos, DIFFCODE::SAME+DIFFCODE::BOTH, DIFFCODE::COMPAREFLAGS+DIFFCODE::SIDEFLAG);
156  *  changes the comparison result to be the same and the side status to be both
157  */
158 void DiffItemList::SetDiffStatusCode(uintptr_t diffpos, unsigned diffcode, unsigned mask)
159 {
160         assert(diffpos);
161         DIFFITEM & di = GetDiffRefAt(diffpos);
162         assert(! ((~mask) & diffcode) ); // make sure they only set flags in their mask
163         di.diffcode.diffcode &= (~mask); // remove current data
164         di.diffcode.diffcode |= diffcode; // add new data
165 }
166
167 /**
168  * @brief Update difference counts.
169  */
170 void DiffItemList::SetDiffCounts(uintptr_t diffpos, unsigned diffs, unsigned ignored)
171 {
172         assert(diffpos);
173         DIFFITEM & di = GetDiffRefAt(diffpos);
174         di.nidiffs = ignored; // see StoreDiffResult() in DirScan.cpp
175         di.nsdiffs = diffs;
176 }
177
178 /**
179  * @brief Returns item's custom (user) flags.
180  * @param [in] diffpos Position of item.
181  * @return Custom flags from item.
182  */
183 unsigned DiffItemList::GetCustomFlags1(uintptr_t diffpos) const
184 {
185         assert(diffpos);
186         const DIFFITEM & di = GetDiffAt(diffpos);
187         return di.customFlags1;
188 }
189
190 /**
191  * @brief Sets item's custom (user) flags.
192  * @param [in] diffpos Position of item.
193  * @param [in] flag Value of flag to set.
194  */
195 void DiffItemList::SetCustomFlags1(uintptr_t diffpos, unsigned flag)
196 {
197         assert(diffpos);
198         DIFFITEM & di = GetDiffRefAt(diffpos);
199         di.customFlags1 = flag;
200 }
201
202 void DiffItemList::Swap(int idx1, int idx2)
203 {
204         for (ListEntry *p = m_root.IsSibling(m_root.Flink); p; p = m_root.IsSibling(p->Flink))
205                 static_cast<DIFFITEM *>(p)->Swap(idx1, idx2);
206 }