2 * @file PathContext.cpp
4 * @brief Implementation file for PathInfo and PathContext
7 // ID line follows -- this is updated by SVN
8 // $Id: PathContext.cpp 4929 2008-01-18 20:03:57Z kimmov $
10 #include "PathContext.h"
13 #include "Environment.h"
16 * @brief Copy constructor.
18 PathInfo::PathInfo(const PathInfo &pi)
25 * @param [in] sbNormalized true if path is wanted in normalized format.
27 String PathInfo::GetPath(bool bNormalized /*= true*/) const
30 return paths_AddTrailingSlash(m_sPath);
35 String& PathInfo::GetRef()
42 * @param [in] sPath New path for item.
44 void PathInfo::SetPath(const TCHAR *sPath)
49 void PathInfo::SetPath(const String & sPath)
55 * @brief Normalize path.
57 void PathInfo::NormalizePath()
59 paths_normalize(m_sPath);
62 PathContext::PathContext()
67 PathContext::PathContext(const String& sLeft)
70 m_path[0].SetPath(sLeft);
73 PathContext::PathContext(const String& sLeft, const String& sRight)
76 m_path[0].SetPath(sLeft);
77 m_path[1].SetPath(sRight);
80 PathContext::PathContext(const String& sLeft, const String& sMiddle, const String& sRight)
83 m_path[0].SetPath(sLeft);
84 m_path[1].SetPath(sMiddle);
85 m_path[2].SetPath(sRight);
88 PathContext::PathContext(const PathContext &paths)
90 m_nFiles = paths.m_nFiles;
91 for (int i = 0; i < m_nFiles; i++)
92 m_path[i].SetPath(paths[i]);
95 PathContext::PathContext(const std::vector<String> &paths)
97 m_nFiles = paths.size();
98 for (size_t i = 0; i < paths.size(); i++)
99 m_path[i].SetPath(paths[i]);
102 String PathContext::GetAt(int nIndex) const
104 assert(nIndex < m_nFiles);
105 return m_path[nIndex].GetPath();
108 String& PathContext::GetElement(int nIndex)
110 assert(nIndex < m_nFiles);
111 return m_path[nIndex].GetRef();
114 void PathContext::SetAt(int nIndex, const String& newElement)
116 assert(nIndex < m_nFiles);
117 m_path[nIndex].SetPath(newElement);
120 String PathContext::operator[](int nIndex) const
122 return GetAt(nIndex);
125 String& PathContext::operator[](int nIndex)
127 return GetElement(nIndex);
131 * @brief set number of files.
133 void PathContext::SetSize(int nFiles)
139 * @brief Return number of files.
141 int PathContext::GetSize() const
147 * @brief Empty m_path array
149 void PathContext::RemoveAll()
152 m_path[0].SetPath(_T(""));
153 m_path[1].SetPath(_T(""));
154 m_path[2].SetPath(_T(""));
158 * @brief Return left path.
159 * @param [in] sNormalized If true normalized path is returned.
161 String PathContext::GetLeft(bool bNormalized) const
165 return m_path[0].GetPath(bNormalized);
169 * @brief Return right path.
170 * @param [in] sNormalized If true normalized path is returned.
172 String PathContext::GetRight(bool bNormalized) const
176 return m_path[m_nFiles - 1].GetPath(bNormalized);
180 * @brief Return middle path.
181 * @param [in] sNormalized If true normalized path is returned.
183 String PathContext::GetMiddle(bool bNormalized) const
187 return m_path[1].GetPath(bNormalized);
192 * @param [in] index index of path to return
193 * @param [in] sNormalized If true normalized path is returned.
195 String PathContext::GetPath(int index, bool bNormalized) const
197 return m_path[index].GetPath(bNormalized);
201 * @brief Set left path.
202 * @param [in] path New path for item.
204 void PathContext::SetLeft(const String& path, bool bNormalized)
208 m_path[0].SetPath(path);
210 m_path[0].NormalizePath();
214 * @brief Set right path.
215 * @param [in] path New path for item.
217 void PathContext::SetRight(const String& path, bool bNormalized)
221 m_path[m_nFiles - 1].SetPath(path);
223 m_path[m_nFiles - 1].NormalizePath();
227 * @brief Set middle path.
228 * @param [in] path New path for item.
230 void PathContext::SetMiddle(const String& path, bool bNormalized)
235 m_path[2] = m_path[1];
237 m_path[1].SetPath(path);
239 m_path[1].NormalizePath();
244 * @param [in] index index of path to set
245 * @param [in] path New path for item.
247 void PathContext::SetPath(int index, const String& path, bool bNormalized)
249 if (index >= sizeof(m_path)/sizeof(m_path[0]))
251 if (index >= m_nFiles)
252 m_nFiles = index + 1;
253 m_path[index].SetPath(path);
255 m_path[index].NormalizePath();
261 void PathContext::Swap()
264 m_path[0].m_sPath.swap(m_path[1].m_sPath);
266 m_path[0].m_sPath.swap(m_path[2].m_sPath);