Falaise  4.0.1
SuperNEMO Software Toolkit
Public Member Functions | List of all members
falaise::config::path Class Reference

Class representing a filesystem path as held by a property_set. More...

#include <falaise/config/path.h>

Public Member Functions

 path ()=default
 Default constructor. More...
 
 path (std::string const &p)
 Construct path from a std::string. More...
 
 operator std::string () const
 Conversion to std::string. More...
 
bool operator== (path const &other) const
 Equality operator. More...
 
bool operator!= (path const &other) const
 Inequality operator. More...
 
bool operator== (std::string const &other) const
 Equality operator for path against a string. More...
 
bool operator!= (std::string const &other) const
 Inequality operator for path against a string. More...
 

Detailed Description

Class representing a filesystem path as held by a property_set.

Filesystem paths can be defined in datatools::properties syntax as:

mypath : string as path = "/some/path"

Parsing of the properties file will expand any mount points or environment variables so that fetching the path will return a std::string containing the resolved absolute path.

path provides a simple type to distinguish raw std::string from explicit paths allowing users to validate that a property_set value is a true path. It is nothing more than a simple holder of the std::string for the absolute path and may be used as:

void configure_me(property_set const& ps) {
auto p = ps.get<falaise::config::path>("mypath"); // throws if "mypath" is not a path value
std::cout << p << std::endl; // prints absolute path
}

A path can be constructed from any string whose value is a valid path as understood by datatools::fetch_path_with_env. Examples are:

The string may also include environment variables, e.g. $HOME or ${HOME}, which will be expanded if they exist, otherwise a invalid_path_error is thrown. When running in a program that provides the datatools::kernel service, paths can also be supplied as:

Note that in all cases, path does not check that a file exists at the location specified by the path. If you require more specific filesystem functionality, you should use the value of path in a full library such as boost::filesystem or C++17's std::filesystem if available.

See also
property_set
datatools::fetch_path_with_env

Constructor & Destructor Documentation

◆ path() [1/2]

falaise::config::path::path ( )
default

Default constructor.

◆ path() [2/2]

falaise::config::path::path ( std::string const p)

Construct path from a std::string.

Not declared explicit as we allow conversions for compatibility with existing use of filesystem paths as std::string.

Parameters
[in]p
Exceptions
invalid_path_errorif p is not a valid path string

Member Function Documentation

◆ operator std::string()

falaise::config::path::operator std::string ( ) const
inline

Conversion to std::string.

◆ operator!=() [1/2]

bool falaise::config::path::operator!= ( path const other) const
inline

Inequality operator.

Returns
true if the two operands are not the same

◆ operator!=() [2/2]

bool falaise::config::path::operator!= ( std::string const other) const
inline

Inequality operator for path against a string.

Returns
true if the value of the path is not equal to the string

◆ operator==() [1/2]

bool falaise::config::path::operator== ( path const other) const
inline

Equality operator.

Returns
true if the two operands are the same

◆ operator==() [2/2]

bool falaise::config::path::operator== ( std::string const other) const
inline

Equality operator for path against a string.

Returns
true if the value of the path is equal to the string

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