From 3bd928591b62443631b373a2c8a2481aa3cff764 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Mon, 19 Oct 2015 14:46:50 +1000 Subject: [PATCH] Add PBD::Searchpath::contains method to check if a Searchpath contains a path --- libs/pbd/pbd/search_path.h | 4 ++++ libs/pbd/search_path.cc | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/libs/pbd/pbd/search_path.h b/libs/pbd/pbd/search_path.h index f669d7f25a..d287782aca 100644 --- a/libs/pbd/pbd/search_path.h +++ b/libs/pbd/pbd/search_path.h @@ -134,6 +134,10 @@ public: */ LIBPBD_TEMPLATE_MEMBER_API void remove_directories (const std::vector& paths); + /** + * @return true if Searchpath already contains path + */ + LIBPBD_TEMPLATE_MEMBER_API bool contains (const std::string& path) const; }; 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 d1dc8c39f0..46292ef1f3 100644 --- a/libs/pbd/search_path.cc +++ b/libs/pbd/search_path.cc @@ -163,6 +163,17 @@ Searchpath::add_subdirectory_to_paths (const string& subdir) return *this; } +bool +Searchpath::contains (const string& path) const +{ + std::vector::const_iterator i = find(begin(), end(), path); + + if (i == end()) { + return false; + } + return true; +} + /* This is not part of the Searchpath object, but is closely related to the * whole idea, and we put it here for convenience. */