Make PBD::SearchPath less silly/boilerplatey.

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
This commit is contained in:
David Robillard 2008-09-23 15:55:34 +00:00
parent 22dc575e4c
commit 1bee7c3f93
4 changed files with 10 additions and 96 deletions

View file

@ -1532,7 +1532,6 @@ public:
TempoLines* tempo_lines; TempoLines* tempo_lines;
ArdourCanvas::Group* time_line_group; ArdourCanvas::Group* time_line_group;
ArdourCanvas::SimpleLine* get_time_line ();
void hide_measures (); void hide_measures ();
void draw_measures (); void draw_measures ();

View file

@ -53,6 +53,7 @@ find_matching_files_in_directory (const sys::path& directory,
vector<string> tmp_files; vector<string> tmp_files;
get_files_in_directory (directory, tmp_files); get_files_in_directory (directory, tmp_files);
result.reserve(tmp_files.size());
for (vector<string>::iterator file_iter = tmp_files.begin(); for (vector<string>::iterator file_iter = tmp_files.begin();
file_iter != tmp_files.end(); file_iter != tmp_files.end();
@ -85,9 +86,7 @@ find_matching_files_in_search_path (const SearchPath& search_path,
const Glib::PatternSpec& pattern, const Glib::PatternSpec& pattern,
vector<sys::path>& result) vector<sys::path>& result)
{ {
vector<sys::path> dirs; find_matching_files_in_directories (search_path, pattern, result);
std::copy(search_path.begin(), search_path.end(), std::back_inserter(dirs));
find_matching_files_in_directories (dirs, pattern, result);
} }
bool bool

View file

@ -39,14 +39,9 @@ using std::vector;
* The SearchPath class does not test whether the paths exist * The SearchPath class does not test whether the paths exist
* or are directories. It is basically just a container. * or are directories. It is basically just a container.
*/ */
class SearchPath { class SearchPath : public vector<sys::path>
{
public: public:
typedef std::vector<sys::path>::iterator iterator;
typedef std::vector<sys::path>::const_iterator const_iterator;
public:
/** /**
* Create an empty SearchPath. * Create an empty SearchPath.
*/ */
@ -80,48 +75,6 @@ public:
*/ */
SearchPath (const vector<sys::path>& paths); 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. * @return a search path string.
* *
@ -130,11 +83,6 @@ public:
*/ */
const string to_string () const; const string to_string () const;
/**
* Assignment of another SearchPath to this.
*/
SearchPath& operator= (const SearchPath& spath);
/** /**
* Add all the directories in path to this. * Add all the directories in path to this.
*/ */
@ -162,20 +110,9 @@ public:
*/ */
SearchPath& add_subdirectory_to_paths (const string& subdir); 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: protected:
void add_directory (const sys::path& directory_path); void add_directory (const sys::path& directory_path);
void add_directories (const vector<sys::path>& paths); void add_directories (const vector<sys::path>& paths);
vector<sys::path> m_dirs;
}; };
} // namespace PBD } // namespace PBD

View file

@ -42,8 +42,7 @@ SearchPath::SearchPath (const string& path)
{ {
vector<sys::path> tmp; 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); add_directories (tmp);
} }
} }
@ -58,17 +57,11 @@ SearchPath::SearchPath (const vector<sys::path>& paths)
add_directories (paths); add_directories (paths);
} }
SearchPath::SearchPath (const SearchPath& other)
: m_dirs(other.m_dirs)
{
}
void void
SearchPath::add_directory (const sys::path& directory_path) SearchPath::add_directory (const sys::path& directory_path)
{ {
// test for existance and warn etc? // test for existance and warn etc?
m_dirs.push_back(directory_path); push_back(directory_path);
} }
void void
@ -84,7 +77,7 @@ SearchPath::to_string () const
{ {
string path; 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 += (*i).to_string();
path += path_delimiter; path += path_delimiter;
} }
@ -94,17 +87,10 @@ SearchPath::to_string () const
return path; return path;
} }
SearchPath&
SearchPath::operator= (const SearchPath& path)
{
m_dirs = path.m_dirs;
return *this;
}
SearchPath& SearchPath&
SearchPath::operator+= (const SearchPath& spath) 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; return *this;
} }
@ -126,15 +112,14 @@ SearchPath&
SearchPath::operator+ (const SearchPath& spath) SearchPath::operator+ (const SearchPath& spath)
{ {
// concatenate paths into new SearchPath // 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; return *this;
} }
SearchPath& SearchPath&
SearchPath::add_subdirectory_to_paths (const string& subdir) 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 // should these new paths just be added to the end of
// the search path rather than replace? // the search path rather than replace?
*i /= subdir; *i /= subdir;
@ -142,11 +127,5 @@ SearchPath::add_subdirectory_to_paths (const string& subdir)
return *this; return *this;
} }
SearchPath&
SearchPath::operator/= (const string& subdir)
{
return add_subdirectory_to_paths (subdir);
}
} // namespace PBD } // namespace PBD