xlnt
Public Member Functions | Static Public Member Functions | List of all members
xlnt::path Class Reference

Encapsulates a path that points to location in a filesystem. More...

#include <path.hpp>

Public Member Functions

 path ()
 Construct an empty path. More...
 
 path (const std::string &path_string)
 Counstruct a path from a string representing the path. More...
 
 path (const std::string &path_string, char sep)
 Construct a path from a string with an explicit directory seprator. More...
 
bool is_relative () const
 Return true iff this path doesn't begin with / (or a drive letter on Windows). More...
 
bool is_absolute () const
 Return true iff path::is_relative() is false. More...
 
bool is_root () const
 Return true iff this path is the root directory. More...
 
path parent () const
 Return a new path that points to the directory containing the current path Return the path unchanged if this path is the absolute or relative root. More...
 
std::string filename () const
 Return the last component of this path. More...
 
std::string extension () const
 Return the part of the path following the last dot in the filename. More...
 
std::pair< std::string, std::string > split_extension () const
 Return a pair of strings resulting from splitting the filename on the last dot. More...
 
std::vector< std::string > split () const
 Create a string representing this path separated by the provided separator or the system-default separator if not provided. More...
 
const std::string & string () const
 Create a string representing this path separated by the provided separator or the system-default separator if not provided. More...
 
path resolve (const path &base_path) const
 If this path is relative, append each component of this path to base_path and return the resulting absolute path. Otherwise, the the current path will be returned and base_path will be ignored. More...
 
path relative_to (const path &base_path) const
 The inverse of path::resolve. Creates a relative path from an absolute path by removing the common root between base_path and this path. If the current path is already relative, return it unchanged. More...
 
bool exists () const
 Return true iff the file or directory pointed to by this path exists on the filesystem. More...
 
bool is_directory () const
 Return true if the file or directory pointed to by this path is a directory. More...
 
bool is_file () const
 Return true if the file or directory pointed to by this path is a regular file. More...
 
std::string read_contents () const
 Open the file pointed to by this path and return a string containing the files contents. More...
 
path append (const std::string &to_append) const
 Append the provided part to this path and return the result. More...
 
path append (const path &to_append) const
 Append the provided part to this path and return the result. More...
 
bool operator== (const path &other) const
 Returns true if left path is equal to right path. More...
 
bool operator!= (const path &other) const
 Returns true if left path is equal to right path. More...
 

Static Public Member Functions

static char system_separator ()
 The system-specific path separator character (e.g. '/' or '\'). More...
 

Detailed Description

Encapsulates a path that points to location in a filesystem.

Constructor & Destructor Documentation

◆ path() [1/3]

xlnt::path::path ( )

Construct an empty path.

◆ path() [2/3]

xlnt::path::path ( const std::string &  path_string)
explicit

Counstruct a path from a string representing the path.

◆ path() [3/3]

xlnt::path::path ( const std::string &  path_string,
char  sep 
)

Construct a path from a string with an explicit directory seprator.

Member Function Documentation

◆ append() [1/2]

path xlnt::path::append ( const std::string &  to_append) const

Append the provided part to this path and return the result.

◆ append() [2/2]

path xlnt::path::append ( const path to_append) const

Append the provided part to this path and return the result.

◆ exists()

bool xlnt::path::exists ( ) const

Return true iff the file or directory pointed to by this path exists on the filesystem.

◆ extension()

std::string xlnt::path::extension ( ) const

Return the part of the path following the last dot in the filename.

◆ filename()

std::string xlnt::path::filename ( ) const

Return the last component of this path.

◆ is_absolute()

bool xlnt::path::is_absolute ( ) const

Return true iff path::is_relative() is false.

◆ is_directory()

bool xlnt::path::is_directory ( ) const

Return true if the file or directory pointed to by this path is a directory.

◆ is_file()

bool xlnt::path::is_file ( ) const

Return true if the file or directory pointed to by this path is a regular file.

◆ is_relative()

bool xlnt::path::is_relative ( ) const

Return true iff this path doesn't begin with / (or a drive letter on Windows).

◆ is_root()

bool xlnt::path::is_root ( ) const

Return true iff this path is the root directory.

◆ operator!=()

bool xlnt::path::operator!= ( const path other) const

Returns true if left path is equal to right path.

◆ operator==()

bool xlnt::path::operator== ( const path other) const

Returns true if left path is equal to right path.

◆ parent()

path xlnt::path::parent ( ) const

Return a new path that points to the directory containing the current path Return the path unchanged if this path is the absolute or relative root.

◆ read_contents()

std::string xlnt::path::read_contents ( ) const

Open the file pointed to by this path and return a string containing the files contents.

◆ relative_to()

path xlnt::path::relative_to ( const path base_path) const

The inverse of path::resolve. Creates a relative path from an absolute path by removing the common root between base_path and this path. If the current path is already relative, return it unchanged.

◆ resolve()

path xlnt::path::resolve ( const path base_path) const

If this path is relative, append each component of this path to base_path and return the resulting absolute path. Otherwise, the the current path will be returned and base_path will be ignored.

◆ split()

std::vector<std::string> xlnt::path::split ( ) const

Create a string representing this path separated by the provided separator or the system-default separator if not provided.

◆ split_extension()

std::pair<std::string, std::string> xlnt::path::split_extension ( ) const

Return a pair of strings resulting from splitting the filename on the last dot.

◆ string()

const std::string& xlnt::path::string ( ) const

Create a string representing this path separated by the provided separator or the system-default separator if not provided.

◆ system_separator()

static char xlnt::path::system_separator ( )
static

The system-specific path separator character (e.g. '/' or '\').


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