Make PBD::SearchPath less silly/boilerplatey.
authorDavid Robillard <d@drobilla.net>
Tue, 23 Sep 2008 15:55:34 +0000 (15:55 +0000)
committerDavid Robillard <d@drobilla.net>
Tue, 23 Sep 2008 15:55:34 +0000 (15:55 +0000)
Remove unnecessary copy in find_matching_files_in_search_path.

git-svn-id: svn://localhost/ardour2/branches/3.0@3797 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.h
libs/pbd/file_utils.cc
libs/pbd/pbd/search_path.h
libs/pbd/search_path.cc

index 7d902fbfb841ee21abdc6cb98ed06e0c2a17ce4a..32730d15f2ff0c52ba1a05267456a12a9d56a77d 100644 (file)
@@ -1532,7 +1532,6 @@ public:
        TempoLines* tempo_lines;
 
        ArdourCanvas::Group* time_line_group;
-       ArdourCanvas::SimpleLine* get_time_line ();
 
        void hide_measures ();
        void draw_measures ();
index f8dfe269c503b55e55bf9269ce495be22b47e11f..6af039a83ece699e193f8a400e54a8c870f3adc2 100644 (file)
@@ -53,6 +53,7 @@ find_matching_files_in_directory (const sys::path& directory,
        vector<string> tmp_files;
 
        get_files_in_directory (directory, tmp_files);
+       result.reserve(tmp_files.size());
 
        for (vector<string>::iterator file_iter = tmp_files.begin();
                        file_iter != tmp_files.end();
@@ -85,9 +86,7 @@ find_matching_files_in_search_path (const SearchPath& search_path,
                                     const Glib::PatternSpec& pattern,
                                     vector<sys::path>& result)
 {
-       vector<sys::path> dirs;
-       std::copy(search_path.begin(), search_path.end(), std::back_inserter(dirs));
-       find_matching_files_in_directories (dirs, pattern, result);    
+       find_matching_files_in_directories (search_path, pattern, result);    
 }
 
 bool
index 3b10d4a3198c3582b9a71729650ae99b597abeeb..505583b3e0f62874c8e8fd0df1f79d9379256e43 100644 (file)
@@ -39,14 +39,9 @@ using std::vector;
  * The SearchPath class does not test whether the paths exist
  * or are directories. It is basically just a container.
  */
-class SearchPath {
+class SearchPath : public vector<sys::path>
+{
 public:
-
-       typedef std::vector<sys::path>::iterator         iterator;
-       typedef std::vector<sys::path>::const_iterator   const_iterator;
-
-public:
-
        /**
         * Create an empty SearchPath.
         */
@@ -80,48 +75,6 @@ public:
         */
        SearchPath (const vector<sys::path>& paths);
 
-       /**
-        * The copy constructor does what you would expect and copies the
-        * vector of paths contained by the SearchPath.
-        */
-       SearchPath (const SearchPath& search_path);
-
-       /**
-        * Indicate whether there are any directory paths in m_dirs.
-        *
-        * If SearchPath is initialized with an empty string as the 
-        * result of for instance the contents of an unset environment
-        * variable.
-        *
-        * @return true if there are any paths in m_paths.
-        */
-       operator void* () const { return (void*)!m_dirs.empty(); }
-
-       /**
-        *  @return a read/write iterator that points to the first
-        *  path in the SearchPath. Iteration is done in ordinary
-        *  element order.
-        */
-       iterator begin () { return m_dirs.begin(); }
-       
-       /**
-        *  @return A read-only (constant) iterator that points to the
-        *  first path in the SearchPath.
-        */
-       const_iterator begin () const { return m_dirs.begin(); }
-
-       /**
-        *  @return A read/write iterator that points one past the last
-        *  path in the SearchPath.
-        */
-       iterator end () { return m_dirs.end(); }
-       
-       /**
-        *  @return A read-only (constant) iterator that points one past 
-        *  the last path in the SearchPath.
-        */
-       const_iterator end () const { return m_dirs.end(); }
-
        /**
         * @return a search path string.
         *
@@ -130,11 +83,6 @@ public:
         */
        const string to_string () const;
 
-       /**
-        * Assignment of another SearchPath to this.
-        */
-       SearchPath& operator= (const SearchPath& spath);
-
        /**
         * Add all the directories in path to this.
         */
@@ -162,20 +110,9 @@ public:
         */
        SearchPath& add_subdirectory_to_paths (const string& subdir);
 
-       /**
-        * Add a sub-directory to each path in the search path.
-        * @see add_subdirectory_to_paths
-        */
-       SearchPath& operator/= (const string& subdir);
-
 protected:
-
        void add_directory (const sys::path& directory_path);
-
        void add_directories (const vector<sys::path>& paths);
-       
-       vector<sys::path> m_dirs;
-
 };
 
 } // namespace PBD
index 9956c6c76339d589a691e8b5ac81ca9eb40f0099..350eea05d35b4fa55d7a25437a601bde0093ce00 100644 (file)
@@ -42,8 +42,7 @@ SearchPath::SearchPath (const string& path)
 {
        vector<sys::path> tmp;
 
-       if(tokenize (path, string(path_delimiter), std::back_inserter (tmp)))
-       {
+       if (tokenize (path, string(path_delimiter), std::back_inserter (tmp))) {
                add_directories (tmp);
        }
 }
@@ -58,17 +57,11 @@ SearchPath::SearchPath (const vector<sys::path>& paths)
        add_directories (paths);
 }
 
-SearchPath::SearchPath (const SearchPath& other)
-       : m_dirs(other.m_dirs)
-{
-
-}
-
 void
 SearchPath::add_directory (const sys::path& directory_path)
 {
        // test for existance and warn etc?
-       m_dirs.push_back(directory_path);
+       push_back(directory_path);
 }
 
 void
@@ -84,7 +77,7 @@ SearchPath::to_string () const
 {
        string path;
 
-       for (vector<sys::path>::const_iterator i = m_dirs.begin(); i != m_dirs.end(); ++i) {
+       for (vector<sys::path>::const_iterator i = begin(); i != end(); ++i) {
                path += (*i).to_string();
                path += path_delimiter;
        }
@@ -94,17 +87,10 @@ SearchPath::to_string () const
        return path;
 }
 
-SearchPath&
-SearchPath::operator= (const SearchPath& path)
-{
-       m_dirs = path.m_dirs;
-       return *this;
-}
-
 SearchPath& 
 SearchPath::operator+= (const SearchPath& spath)
 {
-       m_dirs.insert(m_dirs.end(), spath.m_dirs.begin(), spath.m_dirs.end());
+       insert(end(), spath.begin(), spath.end());
        return *this;
 }
 
@@ -126,15 +112,14 @@ SearchPath&
 SearchPath::operator+ (const SearchPath& spath)
 {
        // concatenate paths into new SearchPath
-       m_dirs.insert(m_dirs.end(), spath.m_dirs.begin(), spath.m_dirs.end());
+       insert(end(), spath.begin(), spath.end());
        return *this;
 }
 
 SearchPath&
 SearchPath::add_subdirectory_to_paths (const string& subdir)
 {
-       for (vector<sys::path>::iterator i = m_dirs.begin(); i != m_dirs.end(); ++i)
-       {
+       for (vector<sys::path>::iterator i = begin(); i != end(); ++i) {
                // should these new paths just be added to the end of 
                // the search path rather than replace?
                *i /= subdir;
@@ -142,11 +127,5 @@ SearchPath::add_subdirectory_to_paths (const string& subdir)
        
        return *this;
 }
-       
-SearchPath&
-SearchPath::operator/= (const string& subdir)
-{
-       return add_subdirectory_to_paths (subdir);
-}
 
 } // namespace PBD