Apache Mesos
Classes | Public Member Functions | List of all members
Path Class Reference

Represents a POSIX or Windows file system path and offers common path manipulations. More...

#include <path.hpp>

Classes

class  const_iterator
 

Public Member Functions

 Path ()
 
 Path (const std::string &path, const char path_separator=os::PATH_SEPARATOR)
 
std::string basename () const
 Extracts the component following the final '/'. More...
 
std::string dirname () const
 Extracts the component up to, but not including, the final '/'. More...
 
Option< std::string > extension () const
 Returns the file extension of the path, including the dot. More...
 
bool is_absolute () const
 
 operator std::string () const
 
const std::string & string () const
 
const_iterator begin () const
 
const_iterator end () const
 

Detailed Description

Represents a POSIX or Windows file system path and offers common path manipulations.

When reading the comments below, keep in mind that '/' refers to the path separator character, so read it as "'/' or '\', depending on platform".

Constructor & Destructor Documentation

Path::Path ( )
inline
Path::Path ( const std::string &  path,
const char  path_separator = os::PATH_SEPARATOR 
)
inlineexplicit

Member Function Documentation

std::string Path::basename ( ) const
inline

Extracts the component following the final '/'.

Trailing '/' characters are not counted as part of the pathname.

Like the standard '::basename()' except it is thread safe.

The following list of examples (taken from SUSv2) shows the strings returned by basename() for different paths:

path basename
"/usr/lib" "lib"
"/usr/" "usr"
"usr" "usr"
"/" "/"
"." "."
".." ".."
Returns
The component following the final '/'. If Path does not contain a '/', this returns a copy of Path. If Path is the string "/", then this returns the string "/". If Path is an empty string, then it returns the string ".".
const_iterator Path::begin ( ) const
inline
std::string Path::dirname ( ) const
inline

Extracts the component up to, but not including, the final '/'.

Trailing '/' characters are not counted as part of the pathname.

Like the standard '::dirname()' except it is thread safe.

The following list of examples (taken from SUSv2) shows the strings returned by dirname() for different paths:

path dirname
"/usr/lib" "/usr"
"/usr/" "/"
"usr" "."
"/" "/"
"." "."
".." "."
Returns
The component up to, but not including, the final '/'. If Path does not contain a '/', then this returns the string ".". If Path is the string "/", then this returns the string "/". If Path is an empty string, then this returns the string ".".
const_iterator Path::end ( ) const
inline
Option<std::string> Path::extension ( ) const
inline

Returns the file extension of the path, including the dot.

Returns None if the basename contains no dots, or consists entirely of dots (i.e. '.', '..').

Examples:

path extension
"a.txt" ".txt"
"a.tar.gz" ".gz"
".bashrc" ".bashrc"
"a" None
"." None
".." None
bool Path::is_absolute ( ) const
inline
Path::operator std::string ( ) const
inline
const std::string& Path::string ( ) const
inline

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