A URI which is a path (for example a filesystem or OSC path). More...
#include <Path.hpp>
Inherits Raul::URI.
Public Member Functions | |
Path () | |
Construct an uninitialzed path, because the STL is annoying. | |
Path (const std::basic_string< char > &path) | |
Construct a Path from an std::string. | |
Path (const char *cpath) | |
Construct a Path from a C string. | |
Path (const Path ©) | |
Construct a Path from another path. | |
bool | is_root () const |
bool | is_child_of (const Path &parent) const |
bool | is_parent_of (const Path &child) const |
Path | child (const std::string &s) const |
Path | child (const Path &p) const |
Path | operator+ (const Path &p) const |
const char * | symbol () const |
Return the symbol of this path (everything after the last '/'). | |
Path | parent () const |
Return the parent's path. | |
Path | child (const Raul::Symbol &symbol) const |
Return the path's child with the given name (symbol). | |
Path | relative_to_base (const Path &base) const |
Return path relative to some base path (chop prefix). | |
const std::string | base () const |
Return path with a trailing "/". | |
const std::string | base_no_scheme () const |
Return path with a trailing "/". | |
Static Public Member Functions | |
static const Path | root () |
Return the root path. | |
static void | set_root (const Raul::URI &uri) |
Set the root path. | |
static bool | is_path (const Raul::URI &uri) |
static bool | is_valid (const std::basic_string< char > &path) |
static bool | is_valid_name (const std::basic_string< char > &name) |
static std::string | pathify (const std::basic_string< char > &str) |
Convert a string to a valid full path. | |
static std::string | nameify (const std::basic_string< char > &str) |
Convert a string to a valid name (or "method" - tokens between slashes). | |
static void | replace_invalid_chars (std::string &str, size_t start, bool replace_slash=false) |
Replace any invalid characters in str with a suitable replacement. | |
static bool | descendant_comparator (const Path &parent, const Path &child) |
Return true if child is equal to, or a descendant of parent. |
A URI which is a path (for example a filesystem or OSC path).
This enforces that a Path is a valid path, where each fragment is a valid Symbol, separated by exactly one slash (/).
A path is divided by slashes (/). The first character MUST be a slash, and the last character MUST NOT be a slash (except in the special case of the root path "/", which is the only valid single-character path). A Path is actually a URI, the relative path is appended to the root URI automatically, so a Patch can always be used as a URI.
Raul::Path::Path | ( | ) | [inline] |
Construct an uninitialzed path, because the STL is annoying.
Referenced by root().
Raul::Path::Path | ( | const std::basic_string< char > & | path | ) |
Raul::Path::Path | ( | const char * | cpath | ) |
Raul::Path::Path | ( | const Path & | copy | ) | [inline] |
Construct a Path from another path.
This is faster than constructing a path from the other path's string representation, since validity checking is avoided.
const Path Raul::Path::root | ( | ) | [static] |
void Raul::Path::set_root | ( | const Raul::URI & | uri | ) | [static] |
Set the root path.
The default root path is the URI "path:/"
Note this should be done on application start up. Changing the root path while any Path objects exist will break things horribly; don't!
The root can be set to any URI, there are no restrictions on valid characters and such like there are for relative paths (but it must be a valid URI, i.e. begin with a scheme, and in particular not begin with '/'). Relative paths are appended to the root path's URI, i.e. every Path, as a string, begins with the root URI. The part after that is a strict path (a sequence of Symbols separated by '/').
string Raul::Path::pathify | ( | const std::basic_string< char > & | str | ) | [static] |
Convert a string to a valid full path.
The returned string is a valid relative path without the root prefix, i.e. the returned string starts with '/' followed by valid symbols, each separated by '/'.
References Raul::URI::chop_scheme(), replace_invalid_chars(), and root().
string Raul::Path::nameify | ( | const std::basic_string< char > & | str | ) | [static] |
Convert a string to a valid name (or "method" - tokens between slashes).
This will strip all slashes, etc, and always return a valid name/method.
References replace_invalid_chars().
const char* Raul::Path::symbol | ( | ) | const [inline] |
Return the symbol of this path (everything after the last '/').
This is e.g. the "method name" for OSC paths, the filename for filesystem paths, etc. The empty string may be returned (if the path is the root path).
Path Raul::Path::parent | ( | ) | const [inline] |
Return the parent's path.
Calling this on the path "/" will return "/". This is the (deepest) "container path" for OSC paths.
const std::string Raul::Path::base | ( | ) | const [inline] |
Return path with a trailing "/".
Returned value is guaranteed to be a valid parent path, i.e. a valid child path can be made using parent.base() + child_name.
const std::string Raul::Path::base_no_scheme | ( | ) | const [inline] |
Return path with a trailing "/".
Returned value is guaranteed to be a valid parent path, i.e. a valid child path can be made using parent.base() + child_name.