Remaining changes needed for building libpdb on Windows (except for adding the extra...
[ardour.git] / libs / pbd / pbd / search_path.h
1 /*
2     Copyright (C) 2007 Tim Mayberry 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef PBD_SEARCH_PATH_INCLUDED
21 #define PBD_SEARCH_PATH_INCLUDED
22
23 #ifdef SearchPath
24 #undef SearchPath
25 #endif
26
27 #include <string>
28 #include <vector>
29
30 namespace PBD {
31
32 /**
33  * @class SearchPath
34  *
35  * The SearchPath class is a helper class for getting a
36  * vector of paths contained in a search path string where a 
37  * "search path string" contains absolute directory paths 
38  * separated by a colon(:) or a semi-colon(;) on windows.
39  *
40  * The SearchPath class does not test whether the paths exist
41  * or are directories. It is basically just a container.
42  */
43 class SearchPath : public std::vector<std::string>
44 {
45 public:
46         /**
47          * Create an empty SearchPath.
48          */
49         SearchPath ();
50
51         /**
52          * Initialize SearchPath from a string where the string contains
53          * one or more absolute paths to directories which are delimited 
54          * by a path separation character. The path delimeter is a 
55          * colon(:) on unix and a semi-colon(;) on windows.
56          *
57          * Each path contained in the search path may or may not resolve to
58          * an existing directory in the filesystem.
59          * 
60          * @param search_path A path string.
61          */
62         SearchPath (const std::string& search_path);
63
64         /**
65          * Initialize SearchPath from a vector of paths that may or may
66          * not exist.
67          *
68          * @param paths A vector of paths.
69          */
70         SearchPath (const std::vector<std::string>& paths);
71
72         /**
73          * @return a search path string.
74          *
75          * The string that is returned contains the platform specific
76          * path separator.
77          */
78         const std::string to_string () const;
79
80         /**
81          * Add all the directories in path to this.
82          */
83         SearchPath& operator+= (const SearchPath& spath);
84
85         /**
86          * Add another directory path to the search path.
87          */
88         SearchPath& operator+= (const std::string& directory_path);
89         
90         /**
91          * Concatenate another SearchPath onto this.
92          */
93         SearchPath& operator+ (const SearchPath& other);
94         
95         /**
96          * Add another path to the search path.
97          */
98         SearchPath& operator+ (const std::string& directory_path);
99
100         /**
101          * Add a sub-directory to each path in the search path.
102          * @param subdir The directory name, it should not contain 
103          * any path separating tokens.
104          */
105         SearchPath& add_subdirectory_to_paths (const std::string& subdir);
106
107 protected:
108
109         void add_directory (const std::string& directory_path);
110         void add_directories (const std::vector<std::string>& paths);
111 };
112
113 } // namespace PBD
114
115 #endif