4 * @brief Implementation of DIFFITEM
12 DIFFITEM DIFFITEM::emptyitem;
14 /** @brief DIFFITEM's destructor */
18 assert(children == nullptr);
21 /** @brief Return path to left/right file, including all but file name */
22 String DIFFITEM::getFilepath(int nIndex, const String &sRoot) const
24 if (diffcode.exists(nIndex))
26 return paths::ConcatPath(sRoot, diffFileInfo[nIndex].path);
31 /** @brief Return the relative path to file/folder including the item name*/
32 String DIFFITEM::getItemRelativePath() const
37 //determine what is the trees contain the item to be hidden
38 for (compareIndex = 0; (compareIndex < 3) && (diffFileInfo[compareIndex].size == -1); compareIndex++);
42 resp = paths::ConcatPath(diffFileInfo[compareIndex].path, diffFileInfo[compareIndex].filename);
47 /** @brief Return depth of path */
48 int DIFFITEM::GetDepth() const
52 for (depth = 0, cur = parent; cur->parent != nullptr; depth++, cur = cur->parent)
58 * @brief Return whether the specified item is an ancestor of the current item
60 bool DIFFITEM::IsAncestor(const DIFFITEM *pdi) const
63 for (cur = this; cur->parent != nullptr; cur = cur->parent)
65 if (cur->parent == pdi)
72 * @brief Return all ancestors of the current item.
74 std::vector<const DIFFITEM*> DIFFITEM::GetAncestors() const
76 int depth = GetDepth();
77 std::vector<const DIFFITEM*> ancestors(depth);
81 for (i = 0, cur = parent; cur->parent != nullptr; i++, cur = cur->parent)
83 assert(depth - i - 1 >= 0 && depth - i - 1 < depth);
84 ancestors[depth - i - 1] = cur;
89 /** @brief Remove and delete all children DIFFITEM entries */
90 void DIFFITEM::RemoveChildren()
92 DIFFITEM *pRem = children;
93 while (pRem != nullptr)
95 assert(pRem->parent == this);
96 DIFFITEM *pNext = pRem->Flink;
103 /** @brief Swap two items in `diffFileInfo[]`. Used when swapping GUI panes. */
104 void DIFFITEM::Swap(int idx1, int idx2)
106 std::swap(diffFileInfo[idx1], diffFileInfo[idx2]);
107 diffcode.swap(idx1, idx2);
110 for (DIFFITEM *p = children; p != nullptr; p = p->Flink)
115 void DIFFITEM::ClearAllAdditionalProperties()
117 const int n = ((diffcode.diffcode & DIFFCODE::THREEWAY) != 0) ? 3 : 2;
118 for (int i = 0; i < n; ++i)
119 diffFileInfo[i].m_pAdditionalProperties.reset();
122 for (DIFFITEM *p = children; p != nullptr; p = p->Flink)
123 p->ClearAllAdditionalProperties();
129 DIFFITEM *DIFFITEM::GetEmptyItem()
131 // TODO: It would be better if there were individual items
132 // (for whatever these special items are?) because here we
133 // have to *hope* client does not modify this static (shared) item
135 assert(emptyitem.parent == nullptr);
136 assert(emptyitem.Flink == nullptr);
137 assert(emptyitem.Blink == nullptr);
138 assert(emptyitem.children == nullptr);
139 assert(emptyitem.nidiffs == -1);
140 assert(emptyitem.nsdiffs == -1);
141 assert(emptyitem.customFlags == ViewCustomFlags::INVALID_CODE);
142 assert(emptyitem.diffcode.diffcode == 0);
149 * @brief Add Sibling item
150 * @param [in] p The item to be added
152 void DIFFITEM::AppendSibling(DIFFITEM *p)
154 assert(parent->children == this);
158 if (Blink == nullptr)
160 // Insert first sibling (besides ourself)
161 assert(Flink == nullptr);
168 // Insert additional siblings
169 assert(Flink != nullptr);
177 void DIFFITEM::AddChildToParent(DIFFITEM *p)
180 if (children == nullptr)
185 children->AppendSibling(p);
188 void DIFFITEM::DelinkFromSiblings()
190 if (parent != nullptr && parent->children != nullptr)
192 // If `this` is at end of Sibling linkage, fix First Child's end link
193 if (parent->children->Blink == this)
195 assert(Flink == nullptr);
196 parent->children->Blink = Blink;
200 // If `this` is the First Child, link parent to next Sibling
201 if (parent->children == this)
203 parent->children = Flink;
206 if (Blink != nullptr && Blink->Flink != nullptr)
207 Blink->Flink = Flink;
208 if (Flink != nullptr)
209 Flink->Blink = Blink;
210 Flink = Blink = nullptr;
213 void DIFFCODE::swap(int idx1, int idx2)
215 bool e[3] = { false, false, false };
216 for (int i = 0; i < 3; ++i)
218 std::swap(e[idx1], e[idx2]);
220 for (int i = 0; i < 3; ++i)
221 if (e[i]) setSideFlag(i);
222 bool binflag1 = (diffcode & (BINSIDE1 << idx1));
223 bool binflag2 = (diffcode & (BINSIDE1 << idx2));
224 Set(BINSIDE1 << idx1, binflag2 ? (BINSIDE1 << idx1) : 0);
225 Set(BINSIDE1 << idx2, binflag1 ? (BINSIDE1 << idx2) : 0);
226 if ((diffcode & THREEWAY) != 0)
229 switch (diffcode & COMPAREFLAGS3WAY)
232 if (idx1 == 0 || idx2 == 0)
233 idx = (idx1 == 0) ? idx2 : idx1;
236 if (idx1 == 1 || idx2 == 1)
237 idx = (idx1 == 1) ? idx2 : idx1;
240 if (idx1 == 2 || idx2 == 2)
241 idx = (idx1 == 2) ? idx2 : idx1;
245 Set(COMPAREFLAGS3WAY, DIFF1STONLY);
247 Set(COMPAREFLAGS3WAY, DIFF2NDONLY);
249 Set(COMPAREFLAGS3WAY, DIFF3RDONLY);