RAUL  0.8.0
Public Member Functions | Static Public Member Functions | List of all members
Raul::Path Class Reference

A URI which is a path (for example a filesystem or OSC path). More...

#include <Path.hpp>

Inheritance diagram for Raul::Path:
Inheritance graph
Collaboration diagram for Raul::Path:
Collaboration graph

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. More...
 
 Path (const char *cpath)
 Construct a Path from a C string. More...
 
 Path (const Path &copy)
 Construct a Path from another path. More...
 
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 '/'). More...
 
Path parent () const
 Return the parent's path. More...
 
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 "/". More...
 
const std::string base_no_scheme () const
 Return path with a trailing "/". More...
 
- Public Member Functions inherited from Raul::URI
 URI (const std::basic_string< char > &uri="nil:0")
 Construct a URI from an std::string. More...
 
 URI (const char *uri)
 Construct a URI from a C string. More...
 
const std::string chop_start (const std::string &str) const
 Return path with everything up to and including the first occurence of str chopped.
 
std::string chop_scheme () const
 Return the URI with the scheme removed (as a string)
 
std::string scheme () const
 Return the URI scheme (everything before the first ':')
 
const std::string str () const
 
const char * c_str () const
 
std::string substr (size_t start, size_t end=std::string::npos) const
 
bool operator< (const URI &uri) const
 
bool operator<= (const URI &uri) const
 
bool operator== (const URI &uri) const
 
bool operator!= (const URI &uri) const
 
size_t length () const
 
size_t find (const std::string &s) const
 
size_t find_last_of (char c) const
 
 operator Raul::Atom () const
 

Static Public Member Functions

static const Path root ()
 Return the root path. More...
 
static void set_root (const Raul::URI &uri)
 Set the root path. More...
 
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. More...
 
static std::string nameify (const std::basic_string< char > &str)
 Convert a string to a valid name (or "method" - tokens between slashes) More...
 
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.
 
- Static Public Member Functions inherited from Raul::URI
static bool is_valid (const std::basic_string< char > &uri)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Path() [1/3]

Raul::Path::Path ( const std::basic_string< char > &  path)

Construct a Path from an std::string.

It is a fatal error to construct a Path from an invalid string, use is_valid first to check.

◆ Path() [2/3]

Raul::Path::Path ( const char *  cpath)

Construct a Path from a C string.

It is a fatal error to construct a Path from an invalid string, use is_valid first to check.

◆ Path() [3/3]

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.

Member Function Documentation

◆ root()

const Path Raul::Path::root ( )
static

Return the root path.

The default root path is the URI "path:/"

A Path is either the root path, or a child of a root path (i.e. the root path followed by a sequence of Symbols separated by '/')

References Path().

Referenced by base(), descendant_comparator(), parent(), pathify(), and symbol().

◆ set_root()

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 '/').

◆ pathify()

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().

◆ nameify()

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().

◆ symbol()

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).

References root().

Referenced by child().

◆ parent()

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.

References root().

Referenced by descendant_comparator().

◆ base()

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.

References root().

Referenced by base_no_scheme(), child(), and relative_to_base().

◆ base_no_scheme()

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.

References base().


The documentation for this class was generated from the following files: