/*
- Copyright (C) 2007 Tim Mayberry
+ Copyright (C) 2007 Tim Mayberry
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
-#ifndef PBD_SEARCH_PATH_INCLUDED
-#define PBD_SEARCH_PATH_INCLUDED
+#ifndef __libpbd_search_path_h__
+#define __libpbd_search_path_h__
#include <string>
#include <vector>
-#include <pbd/filesystem.h>
+#include "pbd/libpbd_visibility.h"
namespace PBD {
-using std::string;
-using std::vector;
-
/**
- * @class The SearchPath class is a helper class for getting a
- * vector of paths contained in a search path string where a
- * "search path string" contains absolute directory paths
+ * @class Searchpath
+ *
+ * The Searchpath class is a helper class for getting a
+ * vector of paths contained in a search path string where a
+ * "search path string" contains absolute directory paths
* separated by a colon(:) or a semi-colon(;) on windows.
*
- * 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.
*/
-class SearchPath {
-public:
-
- typedef std::vector<sys::path>::iterator iterator;
- typedef std::vector<sys::path>::const_iterator const_iterator;
-
+class LIBPBD_TEMPLATE_API Searchpath : public std::vector<std::string>
+{
public:
-
/**
- * Create an empty SearchPath.
+ * Create an empty Searchpath.
*/
- SearchPath ();
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath ();
/**
- * Initialize SearchPath from a string where the string contains
- * one or more absolute paths to directories which are delimited
- * by a path separation character. The path delimeter is a
+ * Initialize Searchpath from a string where the string contains
+ * one or more absolute paths to directories which are delimited
+ * by a path separation character. The path delimeter is a
* colon(:) on unix and a semi-colon(;) on windows.
*
* Each path contained in the search path may or may not resolve to
* an existing directory in the filesystem.
- *
- * @param search_path A path string.
- */
- SearchPath (const string& search_path);
-
- /**
- * Initialize SearchPath from a sys::path.
*
- * @param directory_path A directory path.
+ * @param search_path A path string.
*/
- SearchPath (const sys::path& directory_path);
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath (const std::string& search_path);
/**
- * Initialize SearchPath from a vector of paths that may or may
+ * Initialize Searchpath from a vector of paths that may or may
* not exist.
*
- * @param path A path.
+ * @param paths A vector of paths.
*/
- SearchPath (const vector<sys::path>& paths);
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath (const std::vector<std::string>& paths);
- /**
- * The copy constructor does what you would expect and copies the
- * vector of paths contained by the SearchPath.
- */
- SearchPath (const SearchPath& search_path);
+ LIBPBD_TEMPLATE_MEMBER_API ~Searchpath () {};
/**
- * 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 a search path string.
*
- * @return true if there are any paths in m_paths.
+ * The string that is returned contains the platform specific
+ * path separator.
*/
- operator void* () const { return (void*)!m_dirs.empty(); }
+ LIBPBD_TEMPLATE_MEMBER_API const std::string to_string () const;
/**
- * @return a read/write iterator that points to the first
- * path in the SearchPath. Iteration is done in ordinary
- * element order.
+ * Add all the directories in path to this.
*/
- iterator begin () { return m_dirs.begin(); }
-
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator+= (const Searchpath& spath);
+
/**
- * @return A read-only (constant) iterator that points to the
- * first path in the SearchPath.
+ * Add another directory path to the search path.
*/
- const_iterator begin () const { return m_dirs.begin(); }
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator+= (const std::string& directory_path);
/**
- * @return A read/write iterator that points one past the last
- * path in the SearchPath.
+ * Concatenate another Searchpath onto this.
*/
- iterator end () { return m_dirs.end(); }
-
+ LIBPBD_TEMPLATE_MEMBER_API const Searchpath operator+ (const Searchpath& other);
+
/**
- * @return A read-only (constant) iterator that points one past
- * the last path in the SearchPath.
+ * Add another path to the search path.
*/
- const_iterator end () const { return m_dirs.end(); }
+ LIBPBD_TEMPLATE_MEMBER_API const Searchpath operator+ (const std::string& directory_path);
/**
- * @return a search path string.
- *
- * The string that is returned contains the platform specific
- * path separator.
+ * Remove all the directories in path from this.
*/
- const string get_string () const;
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator-= (const Searchpath& spath);
/**
- * Assignment of another SearchPath to this.
+ * Remove a directory path from the search path.
*/
- SearchPath& operator= (const SearchPath& spath);
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath& operator-= (const std::string& directory_path);
/**
- * Add all the directories in path to this.
+ * Add a sub-directory to each path in the search path.
+ * @param subdir The directory name, it should not contain
+ * any path separating tokens.
*/
- SearchPath& operator+= (const SearchPath& spath);
+ LIBPBD_TEMPLATE_MEMBER_API Searchpath& add_subdirectory_to_paths (const std::string& subdir);
/**
- * Add another directory path to the search path.
+ * Add directory_path to this Searchpath.
*/
- SearchPath& operator+= (const sys::path& directory_path);
-
+ LIBPBD_TEMPLATE_MEMBER_API void add_directory (const std::string& directory_path);
+
/**
- * Concatenate another SearchPath onto this.
+ * Add directories in paths to this Searchpath.
*/
- SearchPath& operator+ (const SearchPath& other);
-
+ LIBPBD_TEMPLATE_MEMBER_API void add_directories (const std::vector<std::string>& paths);
+
/**
- * Add another path to the search path.
+ * Remove directory_path from this Searchpath.
*/
- SearchPath& operator+ (const sys::path& directory_path);
+ LIBPBD_TEMPLATE_MEMBER_API void remove_directory (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
- * any path separating tokens.
+ * Remove all the directories in paths from this Searchpath.
*/
- SearchPath& add_subdirectory_to_paths (const string& subdir);
+ LIBPBD_TEMPLATE_MEMBER_API void remove_directories (const std::vector<std::string>& paths);
/**
- * Add a sub-directory to each path in the search path.
- * @see add_subdirectory_to_paths
+ * @return true if Searchpath already contains path
*/
- SearchPath& operator/= (const string& subdir);
-
-protected:
-
- void add_directory (const sys::path& directory_path);
+ LIBPBD_TEMPLATE_MEMBER_API bool contains (const std::string& path) const;
+};
- void add_directories (const vector<sys::path>& paths);
-
- vector<sys::path> m_dirs;
+LIBPBD_API void export_search_path (const std::string& base_dir, const char* varname, const char* dir);
-};
} // namespace PBD
-#endif
+#endif /* __libpbd_search_path_h__ */