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