2 Copyright (C) 2007 Tim Mayberry
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.
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.
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.
20 #include <glibmm/miscutils.h>
22 #include "pbd/tokenizer.h"
23 #include "pbd/search_path.h"
24 #include "pbd/error.h"
31 const char * const path_delimiter = ";";
33 const char * const path_delimiter = ":";
40 SearchPath::SearchPath ()
45 SearchPath::SearchPath (const string& path)
47 vector<std::string> tmp;
49 if (tokenize (path, string(path_delimiter), std::back_inserter (tmp))) {
50 add_directories (tmp);
54 SearchPath::SearchPath (const vector<std::string>& paths)
56 add_directories (paths);
60 SearchPath::add_directory (const std::string& directory_path)
62 if (!directory_path.empty()) {
63 push_back(directory_path);
68 SearchPath::add_directories (const vector<std::string>& paths)
70 for(vector<std::string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
76 SearchPath::to_string () const
80 for (vector<std::string>::const_iterator i = begin(); i != end(); ++i) {
82 path += path_delimiter;
85 path = path.substr (0, path.length() - 1); // drop final separator
91 SearchPath::operator+= (const SearchPath& spath)
93 insert(end(), spath.begin(), spath.end());
98 SearchPath::operator+= (const std::string& directory_path)
100 add_directory (directory_path);
105 SearchPath::operator+ (const std::string& directory_path)
107 add_directory (directory_path);
112 SearchPath::operator+ (const SearchPath& spath)
114 // concatenate paths into new SearchPath
115 insert(end(), spath.begin(), spath.end());
120 SearchPath::add_subdirectory_to_paths (const string& subdir)
122 for (vector<std::string>::iterator i = begin(); i != end(); ++i) {
123 // should these new paths just be added to the end of
124 // the search path rather than replace?
125 *i = Glib::build_filename (*i, subdir);