#include <path_finder.h>
Public Types | |
typedef std::list< std::string > | string_list |
A list type returned by some functions. | |
Public Member Functions | |
path_finder (const std::string &path=std::string(), const std::string &ext=std::string(), const std::string &pathsep=":") | |
Creates object with the given path/extension list. | |
std::string | path_string () const |
Returns a ":"-separated string of all paths added via add/path(). | |
void | path_separator (const std::string &sep) |
Sets the string used as a separator for the string-based variants of path(), extentions(), etc. | |
const std::string & | path_separator () const |
Returns the path separator string. | |
virtual unsigned int | path (const std::string &p) |
Sets the path to p, which should be a path_separtor()-delimited string. | |
virtual unsigned int | path (const string_list &p) |
Sets the path to the given list of directories. | |
virtual void | add_path (const std::string &p) |
Adds p to the path. | |
virtual void | add_extension (const std::string &ext=std::string()) |
Adds a "search extension." Sample: finder.extension( ".txt:README" ); Will now try all path combinations with the rightmost characters matching ext. | |
virtual unsigned int | extensions (const std::string &ext) |
like extension(), but overwrites extension list. | |
virtual unsigned int | extensions (const string_list &p) |
Sets the extensions list to the given list. | |
std::string | extensions_string () const |
Returns the path_separator()-delimited listed of file suffixes to use when searching for a path. | |
const string_list & | extensions () const |
Returns this object's extensions list. | |
std::string | join_list (const string_list &list, const std::string &separator) const |
Helper function to collapse a list into a string. | |
std::string | find (const std::string &resourcename, bool check_cache=true) const |
Returns the full path of the given resource, provided it could be found in all paths or with all extensions added and provided it is readable. | |
const string_list & | path () const |
Returns a list of all items added via add_path() and path(). | |
Static Public Member Functions | |
bool | is_accessible (const std::string &path) |
Returns true if path is readable. | |
std::string | basename (const std::string &) |
Returns the "base name" of the given string: any part following the final directory separator character. | |
std::string | dir_separator () |
Returns a platform-dependent path separator. |
Example:
path_finder p; p.path( "/lib/lib:/usr/lib/lib" ); p.extensions( ".a:.so" ); cout << p.find( "z" );
That would print an empty string if it finds nothing, or a string if it finds any of the following:
Please excuse the large number of unnecessary i/o operators in this interface: this is old code from when i started learning STL and wanted to try a lot of stuff out. :/
Definition at line 47 of file path_finder.h.
|
Adds a "search extension." Sample: finder.extension( ".txt:README" ); Will now try all path combinations with the rightmost characters matching ext. Be sure to include a period if you want that searched (that is so this class can be used to find non-files and those with non-traditional extensions). |
|
Adds p to the path. May be path_separtor()-delimited. |
|
Returns a platform-dependent path separator. This is set when the class is compiled. |
|
Returns the full path of the given resource, provided it could be found in all paths or with all extensions added and provided it is readable. Note that this might return a relative path, especially if the resourcename passed to it immediately resolves to an existing resource. It returns an empty string if the resourcename cannot be found in the filesystem tree (or is otherwise unaccessible). If check_cache is false then this function ignores it's lookup cache and searches again, otherwise it uses a cache. When caching it will always return the same result for any given resourcename. |
|
Sets the path to p, which should be a path_separtor()-delimited string. Returns the number of path elements parsed from p. |
|
Returns the path separator string. Default is ":"; |