Documentation for OpenFLUID 2.2.0
openfluid::tools::FilesystemPath Class Reference

#include <tools/FilesystemPath.hpp>

Public Member Functions

 FilesystemPath (const std::string &PathStr)
 
 FilesystemPath (const char *PathStr)
 
 FilesystemPath (const std::vector< std::string > &PathParts)
 
const std::filesystem::path & stdPath () const
 
FilesystemPath fromThis (const std::string &PathStr="") const
 
FilesystemPath fromThis (const std::vector< std::string > &PathParts) const
 
bool empty () const
 
std::string toNative () const
 
std::string toGeneric () const
 
std::string toGenericClean () const
 
std::vector< std::string > split () const
 
std::string filename () const
 
std::string dirname () const
 
std::string basename () const
 
std::string minimalBasename () const
 
std::string extension () const
 
std::string completeExtension () const
 
bool contains (const std::string &Path) const
 
std::string relativeTo (const std::string &Path) const
 
bool isDirectory (const std::string &Path="") const
 
bool isFile (const std::string &Path="") const
 
bool exists (const std::string &Path="") const
 
bool makeDirectory (const std::string &Path="", std::error_code &ErrorCode=DefaultErrorCode) const
 
bool removeDirectory (const std::string &Path="", std::error_code &ErrorCode=DefaultErrorCode) const
 
bool makeFile (const std::string &Path="") const
 
bool removeFile (const std::string &Path="", std::error_code &ErrorCode=DefaultErrorCode) const
 
bool remove (const std::string &Path="", std::error_code &ErrorCode=DefaultErrorCode) const
 

Static Public Member Functions

constexpr static char listSeparator () noexcept
 
constexpr static char separator () noexcept
 
static FilesystemPath fromStdPath (const std::filesystem::path &StdPath)
 
static std::string removeTrailingSeparators (const std::string &Path, char Sep='/') noexcept
 

Constructor & Destructor Documentation

◆ FilesystemPath() [1/3]

openfluid::tools::FilesystemPath::FilesystemPath ( const std::string &  PathStr)

Constructs a FilesystemPath object using a string

Parameters
[in]PathStrthe path as a string

◆ FilesystemPath() [2/3]

openfluid::tools::FilesystemPath::FilesystemPath ( const char *  PathStr)

Constructs a FilesystemPath object using a C-style string

Parameters
[in]PathStrthe path as a char*

◆ FilesystemPath() [3/3]

openfluid::tools::FilesystemPath::FilesystemPath ( const std::vector< std::string > &  PathParts)

Constructs a FilesystemPath object using a vector of strings that will be joined using the path separator

Parameters
[in]PathPartsthe path as a string vector

Member Function Documentation

◆ basename()

std::string openfluid::tools::FilesystemPath::basename ( ) const

Returns the complete base name of the path (without latest extension part, without trailing dot if any)

openfluid::tools::FilesystemPath ExamplePath("/var/tmp/archive.tar.gz");
std::string Name = ExamplePath.basename();
// Name = "archive.tar"
Definition: FilesystemPath.hpp:62
Returns
the base name of the file

◆ completeExtension()

std::string openfluid::tools::FilesystemPath::completeExtension ( ) const

Returns the complete extension (without first dot character) of the path

openfluid::tools::FilesystemPath ExamplePath("/var/tmp/archive.tar.gz");
std::string Ext = ExamplePath.completeExtension();
// Ext = "tar.gz"
Returns
the complete extension

◆ contains()

bool openfluid::tools::FilesystemPath::contains ( const std::string &  Path) const

Returns true if a the path contains a child path (e.g. /path/to contains /path/to/child/path)

Parameters
[in]Paththe child path
Returns
true or false

◆ dirname()

std::string openfluid::tools::FilesystemPath::dirname ( ) const

Returns the directory name (parent path)

openfluid::tools::FilesystemPath ExamplePath("/var/tmp/archive.tar.gz");
std::string Name = ExamplePath.dirname();
// Name = "/var/tmp"
Returns
the directory name

◆ empty()

bool openfluid::tools::FilesystemPath::empty ( ) const

Returns true if the current strored path is empty

Returns
true if the current strored path is empty, false otherwise

◆ exists()

bool openfluid::tools::FilesystemPath::exists ( const std::string &  Path = "") const

Returns true if the path exists (a file, a directory or a valid symbolic link)

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
Returns
true or false

◆ extension()

std::string openfluid::tools::FilesystemPath::extension ( ) const

Returns the extension (without dot character) of the path

openfluid::tools::FilesystemPath ExamplePath("/var/tmp/archive.tar.gz");
std::string Ext = ExamplePath.extension();
// Ext = "gz"
Returns
the extension

◆ filename()

std::string openfluid::tools::FilesystemPath::filename ( ) const

Returns the filename of the path

openfluid::tools::FilesystemPath ExamplePath("/var/tmp/archive.tar.gz");
std::string Name = ExamplePath.filename();
// Name = "archive.tar.gz"
Returns
the filename

◆ fromStdPath()

static FilesystemPath openfluid::tools::FilesystemPath::fromStdPath ( const std::filesystem::path &  StdPath)
static

Creates a FilesystemPath object from a std::filesystem::path object

Parameters
[in]StdPaththe std::filesystem::path object
Returns
The newly created FilesystemPath object

◆ fromThis() [1/2]

FilesystemPath openfluid::tools::FilesystemPath::fromThis ( const std::string &  PathStr = "") const

Creates a new FilesystemPath object from the current FilesystemPath object.

Parameters
[in]PathStra relative path added to the to the current stored path (optional, none by default)
Returns
The newly created FilesystemPath object

◆ fromThis() [2/2]

FilesystemPath openfluid::tools::FilesystemPath::fromThis ( const std::vector< std::string > &  PathParts) const

Creates a new FilesystemPath object from the current FilesystemPath object.

Parameters
[in]PathPartsa relative joined path added to the to the current stored path (optional, none by default)
Returns
The newly created FilesystemPath object

◆ isDirectory()

bool openfluid::tools::FilesystemPath::isDirectory ( const std::string &  Path = "") const

Returns true if the path is a directory

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
Returns
true or false

◆ isFile()

bool openfluid::tools::FilesystemPath::isFile ( const std::string &  Path = "") const

Returns true if the path is a file or a valid symbolic link

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
Returns
true or false

◆ listSeparator()

constexpr static char openfluid::tools::FilesystemPath::listSeparator ( )
inlinestaticconstexprnoexcept

Returns the separator used in paths lists according to current operating system

Returns
the list separator character

◆ makeDirectory()

bool openfluid::tools::FilesystemPath::makeDirectory ( const std::string &  Path = "",
std::error_code &  ErrorCode = DefaultErrorCode 
) const

Creates the directory of the path. It creates all parent directories necessary to create the directory. If the directory already exists, it does nothing.

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
[in]ErrorCodethe storage variable for eventual Error code returned by operation
Returns
true if the directory has been successfully created or if it already exists, false otherwise

◆ makeFile()

bool openfluid::tools::FilesystemPath::makeFile ( const std::string &  Path = "") const

Creates an empty file at the path. It creates all parent directories necessary to create the file. If the file already exists, it does nothing.

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
Returns
true if the file has been successfully created or if it already exists, false otherwise

◆ minimalBasename()

std::string openfluid::tools::FilesystemPath::minimalBasename ( ) const

Returns the minimal base name of the path (e.g. without any extension part, without trailing dot if any)

openfluid::tools::FilesystemPath ExamplePath("/var/tmp/archive.tar.gz");
std::string Name = ExamplePath.minimalBasename();
// Name = "archive"
Returns
the minimal base name of the file

◆ relativeTo()

std::string openfluid::tools::FilesystemPath::relativeTo ( const std::string &  Path) const

Returns the resulting path relative to a given path (e.g with path /path/to/this/place relatively to given path /path/to, resulting path is this/place)

Parameters
[in]Paththe given path
Returns
the resulting relative path

◆ remove()

bool openfluid::tools::FilesystemPath::remove ( const std::string &  Path = "",
std::error_code &  ErrorCode = DefaultErrorCode 
) const

Removes the file or directory of the path.

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
[in]ErrorCodethe storage variable for eventual Error code returned by operation
Returns
true if the file was successfully deleted, false otherwise

◆ removeDirectory()

bool openfluid::tools::FilesystemPath::removeDirectory ( const std::string &  Path = "",
std::error_code &  ErrorCode = DefaultErrorCode 
) const

Removes the directory of the path. It recursively deletes all contents of the directory.

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
[in]ErrorCodethe storage variable for eventual Error code returned by operation
Returns
true if the directory has been successfully deleted, false otherwise

◆ removeFile()

bool openfluid::tools::FilesystemPath::removeFile ( const std::string &  Path = "",
std::error_code &  ErrorCode = DefaultErrorCode 
) const

Removes the file of the path.

Parameters
[in]Patha relative path added to the to the base path (optional, none by default)
[in]ErrorCodethe storage variable for eventual Error code returned by operation
Returns
true if the file was successfully deleted, false otherwise

◆ removeTrailingSeparators()

static std::string openfluid::tools::FilesystemPath::removeTrailingSeparators ( const std::string &  Path,
char  Sep = '/' 
)
staticnoexcept

Removes trailing separators in the given path, if any.

Parameters
[in]Paththe path
[in]Septhe separator character (default is '/')
Returns
the path without any trailing separator

◆ separator()

constexpr static char openfluid::tools::FilesystemPath::separator ( )
inlinestaticconstexprnoexcept

Returns the path separator according to current operating system

Returns
the path separator character

◆ split()

std::vector<std::string> openfluid::tools::FilesystemPath::split ( ) const

Returns parts of the path, splitted using the path separator

Returns
the path parts

◆ stdPath()

const std::filesystem::path& openfluid::tools::FilesystemPath::stdPath ( ) const

Returns a const reference to the internally stored path (std::filesystem::path)

◆ toGeneric()

std::string openfluid::tools::FilesystemPath::toGeneric ( ) const

Returns the path as a path with generic paths separators (always '/')

Returns
the cleaned path with generic separators

◆ toGenericClean()

std::string openfluid::tools::FilesystemPath::toGenericClean ( ) const

Returns the path as a cleaned path with generic paths separators (always '/')

Returns
the cleaned path with generic separators

◆ toNative()

std::string openfluid::tools::FilesystemPath::toNative ( ) const

Returns the path as a path with native paths separators (e.g. '/' on Unix systems, '\' on Windows systems)

Returns
the cleaned path with native separators

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