4 * @brief Declarations of PathInfo and PathContext
8 #include "UnicodeString.h"
12 class PathContextIterator;
15 * @brief Information for one path.
17 * Path is stored in normalized format (no trailing slash).
21 friend class PathContext;
25 String GetPath(bool bNormalized = true) const;
26 String& GetRef() { return m_sPath; }
27 void SetPath(const tchar_t *path);
28 void SetPath(const String & path);
32 String m_sPath; /**< Directory / file path */
37 * @param [in] sPath New path for item.
39 inline void PathInfo::SetPath(const tchar_t *sPath)
44 inline void PathInfo::SetPath(const String & sPath)
50 * @brief Holds path information of compared files/directories.
55 typedef PathContextIterator const_iterator;
58 explicit PathContext(const String& sLeft);
59 PathContext(const String& sLeft, const String& sRight);
60 PathContext(const String& sLeft, const String& sMiddle, const String& sRight);
61 explicit PathContext(const std::vector<String>& paths);
63 String GetAt(int nIndex) const;
64 String& GetElement(int nIndex);
65 void SetAt(int nIndex, const String& newElement);
66 String operator[](int nIndex) const { return GetAt(nIndex); }
67 String& operator[](int nIndex) { return GetElement(nIndex); }
69 String GetLeft(bool bNormalized = true) const;
70 String GetRight(bool bNormalized = true) const;
71 String GetMiddle(bool bNormalized = true) const;
72 String GetPath(int index, bool bNormalized = true) const;
73 void SetLeft(const String& path, bool bNormalized = true);
74 void SetRight(const String& path, bool bNormalized = true);
75 void SetMiddle(const String& path, bool bNormalized = true);
76 void SetPath(int index, const String& path, bool bNormalized = true);
77 void SetSize(int nFiles);
80 void Swap(int nFromIndex, int nToIndex);
82 const_iterator begin() const;
83 const_iterator end() const;
86 PathInfo m_path[3]; /**< First, second, third path (left path at start) */
90 * @brief set number of files.
92 inline void PathContext::SetSize(int nFiles)
98 * @brief Return number of files.
100 inline int PathContext::GetSize() const
105 class PathContextIterator : public std::iterator<std::forward_iterator_tag, String>
108 explicit PathContextIterator(const PathContext *pPathContext) : m_pPathContext(pPathContext)
110 m_sel = (pPathContext->GetSize() == 0) ? -1 : 0;
113 PathContextIterator() : m_pPathContext(nullptr), m_sel(-1)
117 ~PathContextIterator() = default;
119 PathContextIterator& operator=(const PathContextIterator& it)
122 m_pPathContext = it.m_pPathContext;
126 PathContextIterator& operator++()
129 if (m_sel >= m_pPathContext->GetSize())
136 return m_pPathContext->GetAt(m_sel);
139 bool operator==(const PathContextIterator& it) const
141 return m_sel == it.m_sel;
144 bool operator!=(const PathContextIterator& it) const
146 return m_sel != it.m_sel;
150 const PathContext *m_pPathContext;
154 inline PathContextIterator PathContext::begin() const
156 return PathContextIterator(this);
159 inline PathContextIterator PathContext::end() const
161 return PathContextIterator();