505583b3e0f62874c8e8fd0df1f79d9379256e43
[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 #include <string>
24 #include <vector>
25
26 #include <pbd/filesystem.h>
27
28 namespace PBD {
29
30 using std::string;
31 using std::vector;
32
33 /**
34  * @class The SearchPath class is a helper class for getting a 
35  * vector of paths contained in a search path string where a 
36  * "search path string" contains absolute directory paths 
37  * separated by a colon(:) or a semi-colon(;) on windows.
38  *
39  * The SearchPath class does not test whether the paths exist
40  * or are directories. It is basically just a container.
41  */
42 class SearchPath : public vector<sys::path>
43 {
44 public:
45         /**
46          * Create an empty SearchPath.
47          */
48         SearchPath ();
49
50         /**
51          * Initialize SearchPath from a string where the string contains
52          * one or more absolute paths to directories which are delimited 
53          * by a path separation character. The path delimeter is a 
54          * colon(:) on unix and a semi-colon(;) on windows.
55          *
56          * Each path contained in the search path may or may not resolve to
57          * an existing directory in the filesystem.
58          * 
59          * @param search_path A path string.
60          */
61         SearchPath (const string& search_path);
62
63         /**
64          * Initialize SearchPath from a sys::path.
65          *
66          * @param directory_path A directory path.
67          */
68         SearchPath (const sys::path& directory_path);
69
70         /**
71          * Initialize SearchPath from a vector of paths that may or may
72          * not exist.
73          *
74          * @param path A path.
75          */
76         SearchPath (const vector<sys::path>& paths);
77
78         /**
79          * @return a search path string.
80          *
81          * The string that is returned contains the platform specific
82          * path separator.
83          */
84         const string to_string () const;
85
86         /**
87          * Add all the directories in path to this.
88          */
89         SearchPath& operator+= (const SearchPath& spath);
90
91         /**
92          * Add another directory path to the search path.
93          */
94         SearchPath& operator+= (const sys::path& directory_path);
95         
96         /**
97          * Concatenate another SearchPath onto this.
98          */
99         SearchPath& operator+ (const SearchPath& other);
100         
101         /**
102          * Add another path to the search path.
103          */
104         SearchPath& operator+ (const sys::path& directory_path);
105
106         /**
107          * Add a sub-directory to each path in the search path.
108          * @param subdir The directory name, it should not contain 
109          * any path separating tokens.
110          */
111         SearchPath& add_subdirectory_to_paths (const string& subdir);
112
113 protected:
114         void add_directory (const sys::path& directory_path);
115         void add_directories (const vector<sys::path>& paths);
116 };
117
118 } // namespace PBD
119
120 #endif