diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/pbd/pbd/search_path.h | 12 | ||||
-rw-r--r-- | libs/pbd/search_path.cc | 39 |
2 files changed, 51 insertions, 0 deletions
diff --git a/libs/pbd/pbd/search_path.h b/libs/pbd/pbd/search_path.h index e4c6c07847..86ab5cdc64 100644 --- a/libs/pbd/pbd/search_path.h +++ b/libs/pbd/pbd/search_path.h @@ -98,6 +98,16 @@ public: LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator+ (const std::string& directory_path); /** + * Remove all the directories in path from this. + */ + LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator-= (const Searchpath& spath); + + /** + * Remove a directory path from the search path. + */ + LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator-= (const std::string& directory_path); + + /** * Add a sub-directory to each path in the search path. * @param subdir The directory name, it should not contain * any path separating tokens. @@ -108,6 +118,8 @@ protected: LIBPBD_TEMPLATE_MEMBER_API void add_directory (const std::string& directory_path); LIBPBD_TEMPLATE_MEMBER_API void add_directories (const std::vector<std::string>& paths); + LIBPBD_TEMPLATE_MEMBER_API void remove_directory (const std::string& directory_path); + LIBPBD_TEMPLATE_MEMBER_API void remove_directories (const std::vector<std::string>& paths); }; LIBPBD_API void export_search_path (const std::string& base_dir, const char* varname, const char* dir); diff --git a/libs/pbd/search_path.cc b/libs/pbd/search_path.cc index 895bc59909..44438cc85c 100644 --- a/libs/pbd/search_path.cc +++ b/libs/pbd/search_path.cc @@ -50,6 +50,30 @@ Searchpath::Searchpath (const vector<std::string>& paths) } void +Searchpath::remove_directory (const std::string& directory_path) +{ + if (directory_path.empty()) { + return; + } + + for (vector<std::string>::iterator i = begin(); i != end();) { + if (*i == directory_path) { + i = erase (i); + } else { + ++i; + } + } +} + +void +Searchpath::remove_directories (const vector<std::string>& paths) +{ + for(vector<std::string>::const_iterator i = paths.begin(); i != paths.end(); ++i) { + remove_directory (*i); + } +} + +void Searchpath::add_directory (const std::string& directory_path) { if (directory_path.empty()) { @@ -116,6 +140,21 @@ Searchpath::operator+ (const Searchpath& spath) } Searchpath& +Searchpath::operator-= (const Searchpath& spath) +{ + remove_directories (spath); + return *this; +} + +Searchpath& +Searchpath::operator-= (const std::string& directory_path) +{ + remove_directory (directory_path); + return *this; +} + + +Searchpath& Searchpath::add_subdirectory_to_paths (const string& subdir) { for (vector<std::string>::iterator i = begin(); i != end(); ++i) { |