From d3e3f5f0058f45825b46abf731ece39fc416efa0 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 8 Jul 2014 00:50:09 -0400 Subject: [PATCH] add operator-= variants for PBD::Searchpath --- libs/pbd/pbd/search_path.h | 12 ++++++++++++ libs/pbd/search_path.cc | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) 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 @@ -97,6 +97,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 @@ -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& paths); + LIBPBD_TEMPLATE_MEMBER_API void remove_directory (const std::string& directory_path); + LIBPBD_TEMPLATE_MEMBER_API void remove_directories (const std::vector& 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 @@ -49,6 +49,30 @@ Searchpath::Searchpath (const vector& paths) add_directories (paths); } +void +Searchpath::remove_directory (const std::string& directory_path) +{ + if (directory_path.empty()) { + return; + } + + for (vector::iterator i = begin(); i != end();) { + if (*i == directory_path) { + i = erase (i); + } else { + ++i; + } + } +} + +void +Searchpath::remove_directories (const vector& paths) +{ + for(vector::const_iterator i = paths.begin(); i != paths.end(); ++i) { + remove_directory (*i); + } +} + void Searchpath::add_directory (const std::string& directory_path) { @@ -115,6 +139,21 @@ Searchpath::operator+ (const Searchpath& spath) return *this; } +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) {