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