2 * @file DiffItemList.cpp
4 * @brief Implementation of DiffItemList
8 #include "DiffItemList.h"
14 DiffItemList::DiffItemList() : m_pRoot(nullptr)
21 DiffItemList::~DiffItemList()
27 * @brief Add new diffitem to structured DIFFITEM tree.
28 * @param [in] par Parent item, or `nullptr` if no parent.
29 * @return Pointer to the added item.
31 DIFFITEM *DiffItemList::AddNewDiff(DIFFITEM *par)
33 DIFFITEM *p = new DIFFITEM;
36 // if there is no `parent`, this item becomes a child of `m_pRoot`
37 assert(m_pRoot != nullptr);
38 m_pRoot->AddChildToParent(p);
41 par->AddChildToParent(p);
47 * @brief Empty structured DIFFITEM tree
49 void DiffItemList::RemoveAll()
55 void DiffItemList::InitDiffItemList()
57 assert(m_pRoot == nullptr);
58 m_pRoot = new DIFFITEM;
61 void DiffItemList::ClearAllAdditionalProperties()
63 assert(m_pRoot != nullptr);
64 for (DIFFITEM* p = GetFirstDiffPosition(); p != nullptr; p = p->GetFwdSiblingLink())
65 p->ClearAllAdditionalProperties();
69 * @brief Get position of first item in structured DIFFITEM tree
71 DIFFITEM *DiffItemList::GetFirstDiffPosition() const
73 return GetFirstChildDiffPosition(m_pRoot);
77 * @brief Get position of first child item in structured DIFFITEM tree
78 * @param [in] par Position of parent diff item (maybe `nullptr`)
79 * @return Position of first child item (or `nullptr` if no children)
81 DIFFITEM *DiffItemList::GetFirstChildDiffPosition(const DIFFITEM *par) const
85 assert(m_pRoot != nullptr);
86 return m_pRoot->GetFirstChild();
89 return par->GetFirstChild();
93 * @brief Get position of next item in structured DIFFITEM tree
94 * @param [in,out] diffpos Position of current item, updated to next item position
95 * @return Diff Item (by reference) in current position
97 const DIFFITEM &DiffItemList::GetNextDiffPosition(DIFFITEM *&diffpos) const
99 DIFFITEM *p = diffpos;
100 if (diffpos->HasChildren())
102 diffpos = GetFirstChildDiffPosition(diffpos);
106 DIFFITEM *cur = diffpos;
109 diffpos = cur->GetFwdSiblingLink();
110 cur = cur->GetParentLink();
111 assert(cur != nullptr);
112 } while (diffpos == nullptr && cur->HasParent());
118 * @brief Get position of next item in structured DIFFITEM tree
119 * @param [in,out] diffpos Position of current item, updated to next item position
120 * @return Diff Item (by reference) in current position
122 DIFFITEM &DiffItemList::GetNextDiffRefPosition(DIFFITEM *&diffpos)
124 return (DIFFITEM &)GetNextDiffPosition(diffpos);
128 * @brief Get position of next sibling item in structured DIFFITEM tree
129 * @param [in,out] diffpos Position of current item, updated to next sibling item position
130 * @return Diff Item (by reference) in current position
132 const DIFFITEM &DiffItemList::GetNextSiblingDiffPosition(DIFFITEM *&diffpos) const
134 DIFFITEM *p = diffpos;
135 diffpos = p->GetFwdSiblingLink();
136 assert(p==nullptr || diffpos==nullptr || p->GetParentLink() == diffpos->GetParentLink());
137 assert(p==nullptr || p->HasParent());
142 * @brief Get position of next sibling item in structured DIFFITEM tree
143 * @param [in,out] diffpos Position of current item, updated to next sibling item position
144 * @return Diff Item (by reference) in current position
146 DIFFITEM &DiffItemList::GetNextSiblingDiffRefPosition(DIFFITEM *&diffpos)
148 return (DIFFITEM &)GetNextSiblingDiffPosition(diffpos);
152 * @brief Alter some bit flags of the diffcode.
155 * SetDiffStatusCode(pos, DIFFCODE::SAME, DIFFCODE::COMPAREFLAGS)
156 * changes the comparison result to be the same.
158 * SetDiffStatusCode(pos, DIFFCODE::BOTH, DIFFCODE::SIDEFLAG)
159 * changes the side status to be both (sides).
161 * SetDiffStatusCode(pos, DIFFCODE::SAME+DIFFCODE::BOTH, DIFFCODE::COMPAREFLAGS+DIFFCODE::SIDEFLAG);
162 * changes the comparison result to be the same and the side status to be both
164 void DiffItemList::SetDiffStatusCode(DIFFITEM *diffpos, unsigned diffcode, unsigned mask)
166 assert(diffpos != nullptr);
167 DIFFITEM &di = GetDiffRefAt(diffpos);
168 assert( ((~mask) & diffcode) == 0 ); // make sure they only set flags in their mask
169 di.diffcode.diffcode &= (~mask); // remove current data
170 di.diffcode.diffcode |= diffcode; // add new data
174 * @brief Update difference counts.
176 void DiffItemList::SetDiffCounts(DIFFITEM *diffpos, unsigned diffs, unsigned ignored)
178 assert(diffpos != nullptr);
179 DIFFITEM &di = GetDiffRefAt(diffpos);
180 di.nidiffs = ignored; // see StoreDiffResult() in DirScan.cpp
185 * @brief Returns item's custom (user) flags.
186 * @param [in] diffpos Position of item.
187 * @return Custom flags from item.
189 unsigned DiffItemList::GetCustomFlags1(DIFFITEM *diffpos) const
191 assert(diffpos != nullptr);
192 const DIFFITEM &di = GetDiffAt(diffpos);
193 return di.customFlags;
197 * @brief Sets item's custom (user) flags.
198 * @param [in] diffpos Position of item.
199 * @param [in] flag Value of flag to set.
201 void DiffItemList::SetCustomFlags1(DIFFITEM *diffpos, unsigned flag)
203 assert(diffpos != nullptr);
204 DIFFITEM &di = GetDiffRefAt(diffpos);
205 di.customFlags = flag;
208 void DiffItemList::Swap(int idx1, int idx2)
210 assert(m_pRoot != nullptr);
211 for (DIFFITEM *p = GetFirstDiffPosition(); p != nullptr; p = p->GetFwdSiblingLink())