2 * @file DiffItemList.cpp
4 * @brief Implementation of DiffItemList
7 #include "DiffItemList.h"
13 DiffItemList::DiffItemList()
20 DiffItemList::~DiffItemList()
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.
30 DIFFITEM* DiffItemList::AddDiff(DIFFITEM *parent)
32 DIFFITEM *p = new DIFFITEM;
34 parent->children.Append(p);
42 * @brief Remove diffitem from structured DIFFITEM tree
43 * @param diffpos position of item to remove
45 void DiffItemList::RemoveDiff(uintptr_t diffpos)
47 DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
53 * @brief Empty structured DIFFITEM tree
55 void DiffItemList::RemoveAll()
57 while (m_root.IsSibling(m_root.Flink))
58 RemoveDiff((uintptr_t)m_root.Flink);
62 * @brief Get position of first item in structured DIFFITEM tree
64 uintptr_t DiffItemList::GetFirstDiffPosition() const
66 return (uintptr_t)m_root.IsSibling(m_root.Flink);
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
74 uintptr_t DiffItemList::GetFirstChildDiffPosition(uintptr_t parentdiffpos) const
76 DIFFITEM *parent = reinterpret_cast<DIFFITEM *>(parentdiffpos);
78 return (uintptr_t)parent->children.IsSibling(parent->children.Flink);
80 return (uintptr_t)m_root.IsSibling(m_root.Flink);
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
88 const DIFFITEM &DiffItemList::GetNextDiffPosition(uintptr_t & diffpos) const
90 DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
93 diffpos = GetFirstChildDiffPosition(diffpos);
101 diffpos = (uintptr_t)cur->parent->children.IsSibling(cur->Flink);
103 diffpos = (uintptr_t)m_root.IsSibling(cur->Flink);
105 } while (!diffpos && cur);
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
115 DIFFITEM &DiffItemList::GetNextDiffRefPosition(uintptr_t & diffpos)
117 return (DIFFITEM &)GetNextDiffPosition(diffpos);
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
125 const DIFFITEM &DiffItemList::GetNextSiblingDiffPosition(uintptr_t & diffpos) const
127 DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
129 diffpos = (uintptr_t)p->parent->children.IsSibling(p->Flink);
131 diffpos = (uintptr_t)m_root.IsSibling(p->Flink);
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
140 DIFFITEM &DiffItemList::GetNextSiblingDiffRefPosition(uintptr_t & diffpos)
142 return (DIFFITEM &)GetNextSiblingDiffPosition(diffpos);
146 * @brief Alter some bit flags of the diffcode.
149 * SetDiffStatusCode(pos, DIFFCODE::SAME, DIFFCODE::COMPAREFLAGS)
150 * changes the comparison result to be the same.
152 * SetDiffStatusCode(pos, DIFFCODE::BOTH, DIFFCODE::SIDEFLAG)
153 * changes the side status to be both (sides).
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
158 void DiffItemList::SetDiffStatusCode(uintptr_t diffpos, unsigned diffcode, unsigned mask)
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
168 * @brief Update difference counts.
170 void DiffItemList::SetDiffCounts(uintptr_t diffpos, unsigned diffs, unsigned ignored)
173 DIFFITEM & di = GetDiffRefAt(diffpos);
174 di.nidiffs = ignored; // see StoreDiffResult() in DirScan.cpp
179 * @brief Returns item's custom (user) flags.
180 * @param [in] diffpos Position of item.
181 * @return Custom flags from item.
183 unsigned DiffItemList::GetCustomFlags1(uintptr_t diffpos) const
186 const DIFFITEM & di = GetDiffAt(diffpos);
187 return di.customFlags1;
191 * @brief Sets item's custom (user) flags.
192 * @param [in] diffpos Position of item.
193 * @param [in] flag Value of flag to set.
195 void DiffItemList::SetCustomFlags1(uintptr_t diffpos, unsigned flag)
198 DIFFITEM & di = GetDiffRefAt(diffpos);
199 di.customFlags1 = flag;
202 void DiffItemList::Swap(int idx1, int idx2)
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);