libcommonc++  0.7
SearchPath.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_SearchPath_hxx
24 #define __ccxx_SearchPath_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/FileName.h++>
28 #include <commonc++/String.h++>
29 
30 #include <memory>
31 
32 #ifdef SearchPath
33 #undef SearchPath
34 #endif
35 
36 namespace ccxx {
37 
46 {
47  public:
48 
54  SearchPath(const String& path = "");
55 
57  SearchPath(const SearchPath& other);
58 
60  ~SearchPath();
61 
63  SearchPath& operator=(const SearchPath& other);
64 
71  void append(const String& dir);
72 
79  void prepend(const String& dir);
80 
85  void remove(const String& dir);
86 
88  void clear();
89 
97  bool contains(const String& dir) const;
98 
108  bool find(FileName& file) const;
109 
111  inline bool isEmpty() const
112  { return(_path.empty()); }
113 
118  inline size_t getDirectoryCount() const
119  { return(length()); }
120 
122  inline size_t length() const
123  { return(_path.size()); }
124 
130  String getDirectory(int index) const;
131 
137  inline String operator[](int index) const
138  { return(getDirectory(index)); }
139 
145  String getPath() const;
146 
148  void fromString(const String& path);
149 
152  inline String toString() const
153  { return(getPath()); }
154 
156  static const SearchPath empty;
157 
159  static const char* separator;
160 
161  private:
162 
163  StringVec _path;
164  mutable String _pathstr;
165 };
166 
167 } // namespace ccxx
168 
169 #endif // __ccxx_SearchPath_hxx
size_t length() const
Get the number of directories in the search path.
Definition: SearchPath.h++:122
A String vector.
Definition: String.h++:1159
A file search path.
Definition: SearchPath.h++:45
size_t getDirectoryCount() const
Get the number of directories in the search path.
Definition: SearchPath.h++:118
static const SearchPath empty
An empty SearchPath.
Definition: SearchPath.h++:156
static const char * separator
The host platform&#39;s path separator.
Definition: SearchPath.h++:159
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
A class representing a filename.
Definition: FileName.h++:55
String operator[](int index) const
Get the directory at the specified index in the search path.
Definition: SearchPath.h++:137
String toString() const
Get a String representation of the SearchPath.
Definition: SearchPath.h++:152
Definition: AllocationMap.c++:25
bool isEmpty() const
Test if the path is empty.
Definition: SearchPath.h++:111