add operator-= variants for PBD::Searchpath
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 8 Jul 2014 04:50:09 +0000 (00:50 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 8 Jul 2014 04:53:13 +0000 (00:53 -0400)
libs/pbd/pbd/search_path.h
libs/pbd/search_path.cc

index e4c6c078478bc478f190fb2a484108c31bf01d71..86ab5cdc6409d47b749ecbc4a3c61f4db4464039 100644 (file)
@@ -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<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);
index 895bc5990946ddb001dee4eadb492a25782c690e..44438cc85c9faf78594d57497ecfaf31bc97b65b 100644 (file)
@@ -49,6 +49,30 @@ Searchpath::Searchpath (const vector<std::string>& paths)
        add_directories (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)
 {
@@ -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)
 {