rcpputils  master
C++ API providing common utilities and data structures.
Public Member Functions | List of all members
rcpputils::fs::path Class Reference

Drop-in replacement for std::filesystem::path. More...

#include <filesystem_helper.hpp>

Public Member Functions

 path ()=default
 Constructs an empty path. More...
 
 path (const std::string &p)
 Conversion constructor from a std::string path. More...
 
 path (const path &p)=default
 Copy constructor. More...
 
std::string string () const
 Get the path delimited using this system's path separator. More...
 
bool exists () const
 Check if this path exists. More...
 
bool is_directory () const noexcept
 Check if the path exists and it is a directory. More...
 
bool is_regular_file () const noexcept
 Check if the path is a regular file. More...
 
uint64_t file_size () const
 Return the size of the file in bytes. More...
 
bool empty () const
 Check if the path is empty. More...
 
bool is_absolute () const
 Check if the path is an absolute path. More...
 
std::vector< std::string >::const_iterator cbegin () const
 Const iterator to first element of this path. More...
 
std::vector< std::string >::const_iterator cend () const
 
path parent_path () const
 Get the parent directory of this path. More...
 
path filename () const
 Get the last element in this path. More...
 
path extension () const
 Get a relative path to the component including and following the last '.'. More...
 
path operator/ (const std::string &other) const
 Concatenate a path and a string into a single path. More...
 
pathoperator/= (const std::string &other)
 Append a string component to this path. More...
 
path operator/ (const path &other) const
 Concatenate two paths together. More...
 
pathoperator/= (const path &other)
 Append a string component to this path. More...
 

Detailed Description

Drop-in replacement for std::filesystem::path.

It must conform to the same standard described and cannot include methods that are not incorporated there.

Constructor & Destructor Documentation

◆ path() [1/3]

rcpputils::fs::path::path ( )
default

Constructs an empty path.

◆ path() [2/3]

rcpputils::fs::path::path ( const std::string p)

Conversion constructor from a std::string path.

Parameters
pA string path split by the platform's string path separator.

◆ path() [3/3]

rcpputils::fs::path::path ( const path p)
default

Copy constructor.

Member Function Documentation

◆ string()

std::string rcpputils::fs::path::string ( ) const

Get the path delimited using this system's path separator.

Returns
The path as a string

◆ exists()

bool rcpputils::fs::path::exists ( ) const

Check if this path exists.

Returns
True if the path exists, false otherwise.

◆ is_directory()

bool rcpputils::fs::path::is_directory ( ) const
noexcept

Check if the path exists and it is a directory.

Returns
True if the path is an existing directory, false otherwise.

◆ is_regular_file()

bool rcpputils::fs::path::is_regular_file ( ) const
noexcept

Check if the path is a regular file.

Returns
True if the file is an existing regular file, false otherwise.

◆ file_size()

uint64_t rcpputils::fs::path::file_size ( ) const

Return the size of the file in bytes.

Returns
size of file in bytes
Exceptions
std::system_error

◆ empty()

bool rcpputils::fs::path::empty ( ) const

Check if the path is empty.

Returns
True if the path is empty, false otherwise.

◆ is_absolute()

bool rcpputils::fs::path::is_absolute ( ) const

Check if the path is an absolute path.

Returns
True if the path is absolute, false otherwise.

◆ cbegin()

std::vector<std::string>::const_iterator rcpputils::fs::path::cbegin ( ) const

Const iterator to first element of this path.

Returns
A const iterator to the first element.

◆ cend()

std::vector<std::string>::const_iterator rcpputils::fs::path::cend ( ) const

Const iterator to one past the last element of this path.

return A const iterator to one past the last element of the path.

◆ parent_path()

path rcpputils::fs::path::parent_path ( ) const

Get the parent directory of this path.

Returns
A path to the parent directory.

◆ filename()

path rcpputils::fs::path::filename ( ) const

Get the last element in this path.

If this path points to a directory, it will return the directory name.

Returns
The last element in this path

◆ extension()

path rcpputils::fs::path::extension ( ) const

Get a relative path to the component including and following the last '.'.

Returns
The string extension

◆ operator/() [1/2]

path rcpputils::fs::path::operator/ ( const std::string other) const

Concatenate a path and a string into a single path.

Parameters
otherthe string compnoent to concatenate
Returns
The combined path of this and other.

◆ operator/=() [1/2]

path& rcpputils::fs::path::operator/= ( const std::string other)

Append a string component to this path.

Parameters
otherthe string component to append
Returns
*this

◆ operator/() [2/2]

path rcpputils::fs::path::operator/ ( const path other) const

Concatenate two paths together.

Parameters
otherthe path to append
Returns
The combined path.

◆ operator/=() [2/2]

path& rcpputils::fs::path::operator/= ( const path other)

Append a string component to this path.

Parameters
otherthe string component to append
Returns
*this

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