4 * @brief Declaration of class CompareStats
15 * @brief Class holding directory compare stats.
17 * This class is used for sharing compare stats between dir compare
18 * classes. CDiffContext updates statuses. GUI (compare statepane) tracks
19 * state changes and updates UI. If compare is fast (compared few small files)
20 * GUI might not be able to detect state change from IDLE back to IDLE. That's
21 * why there is IsCompareDone() which tells if new compare is ready.
28 * @brief Different states for compare procedure.
29 * These states form state-machine for directory compare. States go like:
30 * STATE_IDLE --> STATE_START --> STATE_COMPARE --> STATE_IDLE.
31 * @note GUI doesn't change state, but only backend code. GUI must track
32 * state changes to update itself.
36 STATE_IDLE, /**< No compare running */
37 STATE_START, /**< Start folder compare */
38 STATE_COMPARE, /**< Comparing collected items */
42 * @brief Resultcodes we store.
67 RESULT_COUNT //THIS MUST BE THE LAST ITEM
70 explicit CompareStats(int nDirs);
72 void SetCompareThreadCount(int nCompareThreads)
74 m_rgThreadState.resize(nCompareThreads);
76 void BeginCompare(const DIFFITEM *di, int iCompareThread)
78 ThreadState &rThreadState = m_rgThreadState[iCompareThread];
79 rThreadState.m_nHitCount = 0;
80 rThreadState.m_pDiffItem = di;
82 void AddItem(int code);
83 void IncreaseTotalItems(int count = 1);
84 int GetCount(CompareStats::RESULT result) const;
85 int GetTotalItems() const;
86 int GetComparedItems() const { return m_nComparedItems; }
87 const DIFFITEM *GetCurDiffItem();
89 void SetCompareState(CompareStats::CMP_STATE state);
90 CompareStats::CMP_STATE GetCompareState() const;
91 bool IsCompareDone() const { return m_bCompareDone; }
92 CompareStats::RESULT GetResultFromCode(unsigned diffcode) const;
93 void Swap(int idx1, int idx2);
94 int GetCompareDirs() const { return m_nDirs; }
97 std::array<std::atomic_int, RESULT_COUNT> m_counts; /**< Table storing result counts */
98 std::atomic_int m_nTotalItems; /**< Total items found to compare */
99 std::atomic_int m_nComparedItems; /**< Compared items so far */
100 CMP_STATE m_state; /**< State for compare (idle, collect, compare,..) */
101 bool m_bCompareDone; /**< Have we finished last compare? */
102 int m_nDirs; /**< number of directories to compare */
105 ThreadState() : m_nHitCount(0), m_pDiffItem(nullptr) {}
106 ThreadState(const ThreadState& other) : m_nHitCount(other.m_nHitCount.load()), m_pDiffItem(other.m_pDiffItem) {}
107 std::atomic_int m_nHitCount;
108 const DIFFITEM *m_pDiffItem;
110 std::vector<ThreadState> m_rgThreadState;
115 * @brief Increase found items (dirs and files) count.
116 * @param [in] count Amount of items to add.
118 inline void CompareStats::IncreaseTotalItems(int count)
120 m_nTotalItems += count;
124 * @brief Return count by resultcode.
125 * @param [in] result Resultcode to return.
126 * @return Count of items for given resultcode.
128 inline int CompareStats::GetCount(CompareStats::RESULT result) const
130 return m_counts[result];
134 * @brief Return total count of items (so far) found.
136 inline int CompareStats::GetTotalItems() const
138 return m_nTotalItems;
142 * @brief Return current comparestate.
144 inline CompareStats::CMP_STATE CompareStats::GetCompareState() const