2 * @file PathContext.cpp
4 * @brief Implementation file for PathInfo and PathContext
9 #include "PathContext.h"
14 * @brief Copy constructor.
16 PathInfo::PathInfo(const PathInfo &pi)
23 * @param [in] sbNormalized true if path is wanted in normalized format.
25 String PathInfo::GetPath(bool bNormalized /*= true*/) const
28 return paths::AddTrailingSlash(m_sPath);
34 * @brief Normalize path.
36 void PathInfo::NormalizePath()
38 paths::normalize(m_sPath);
41 PathContext::PathContext()
46 PathContext::PathContext(const String& sLeft)
49 m_path[0].SetPath(sLeft);
52 PathContext::PathContext(const String& sLeft, const String& sRight)
55 m_path[0].SetPath(sLeft);
56 m_path[1].SetPath(sRight);
59 PathContext::PathContext(const String& sLeft, const String& sMiddle, const String& sRight)
62 m_path[0].SetPath(sLeft);
63 m_path[1].SetPath(sMiddle);
64 m_path[2].SetPath(sRight);
67 PathContext::PathContext(const PathContext &paths)
69 m_nFiles = paths.m_nFiles;
70 std::copy_n(paths.m_path, m_nFiles, m_path);
73 PathContext::PathContext(const std::vector<String> &paths)
75 m_nFiles = static_cast<int>(paths.size());
76 for (size_t i = 0; i < paths.size(); i++)
77 m_path[i].SetPath(paths[i]);
80 String PathContext::GetAt(int nIndex) const
82 assert(nIndex < m_nFiles);
83 return m_path[nIndex].GetPath();
86 String& PathContext::GetElement(int nIndex)
88 assert(nIndex < m_nFiles);
89 return m_path[nIndex].GetRef();
92 void PathContext::SetAt(int nIndex, const String& newElement)
94 assert(nIndex < m_nFiles);
95 m_path[nIndex].SetPath(newElement);
99 * @brief Empty m_path array
101 void PathContext::RemoveAll()
104 m_path[0].SetPath(_T(""));
105 m_path[1].SetPath(_T(""));
106 m_path[2].SetPath(_T(""));
110 * @brief Return left path.
111 * @param [in] sNormalized If true normalized path is returned.
113 String PathContext::GetLeft(bool bNormalized) const
117 return m_path[0].GetPath(bNormalized);
121 * @brief Return right path.
122 * @param [in] sNormalized If true normalized path is returned.
124 String PathContext::GetRight(bool bNormalized) const
128 return m_path[m_nFiles - 1].GetPath(bNormalized);
132 * @brief Return middle path.
133 * @param [in] sNormalized If true normalized path is returned.
135 String PathContext::GetMiddle(bool bNormalized) const
139 return m_path[1].GetPath(bNormalized);
144 * @param [in] index index of path to return
145 * @param [in] sNormalized If true normalized path is returned.
147 String PathContext::GetPath(int index, bool bNormalized) const
149 return m_path[index].GetPath(bNormalized);
153 * @brief Set left path.
154 * @param [in] path New path for item.
156 void PathContext::SetLeft(const String& path, bool bNormalized)
160 m_path[0].SetPath(path);
162 m_path[0].NormalizePath();
166 * @brief Set right path.
167 * @param [in] path New path for item.
169 void PathContext::SetRight(const String& path, bool bNormalized)
173 m_path[m_nFiles - 1].SetPath(path);
175 m_path[m_nFiles - 1].NormalizePath();
179 * @brief Set middle path.
180 * @param [in] path New path for item.
182 void PathContext::SetMiddle(const String& path, bool bNormalized)
187 m_path[2] = m_path[1];
189 m_path[1].SetPath(path);
191 m_path[1].NormalizePath();
196 * @param [in] index index of path to set
197 * @param [in] path New path for item.
199 void PathContext::SetPath(int index, const String& path, bool bNormalized)
201 if (index >= sizeof(m_path)/sizeof(m_path[0]))
203 if (index >= m_nFiles)
204 m_nFiles = index + 1;
205 m_path[index].SetPath(path);
207 m_path[index].NormalizePath();
213 void PathContext::Swap(int nFromIndex, int nToIndex)
215 if ((nFromIndex >= 0 && nFromIndex < m_nFiles) && (nToIndex >= 0 && nToIndex < m_nFiles))
216 m_path[nFromIndex].m_sPath.swap(m_path[nToIndex].m_sPath);