Skip to main content

Common Fluids Format 2025 R2

ansys::Project::Path Class Reference

Last update: 16.07.2025

Paths used for internal Project filesystem. More...

#include "Path.hpp"

Public Member Functions

 Path ()
 
 Path (const std::string &pPath)
 
 Path (const char *pPath)
 
bool isNull () const
 Indicates if the path is empty. More...
 
std::vector< std::string > getPathComponents () const
 Return the path components as a vector of string. More...
 
bool isFolderPath () const
 Indicates if the path is a folder path (ends with /) More...
 
Path getParentPath () const
 Return the Path for the enclosing folder. More...
 
std::string getFilename () const
 Return the filename part of the path. More...
 
std::string getFolderName () const
 Return the folder name - only if Path is a folder path. More...
 
Path getRelativePathTo (const Path &pTarget) const
 Convert a global path and a global target to a relative path to the target. More...
 
const std::string & str () const
 Return as string. More...
 
const char * c_str () const
 
bool operator== (const Path &pPath) const
 
bool operator== (const std::string &pPathStr) const
 
bool operator== (const char *pPathStr) const
 
bool operator!= (const Path &pPath) const
 
bool operator!= (const std::string &pPathStr) const
 
void operator+= (const std::string &pPathStr)
 Appends the string to the Path. More...
 

Static Public Member Functions

static bool isValidFilename (const std::string &pStr)
 Check if the specified name is valid for a file. More...
 
static bool isValidPath (const std::string &pStr)
 Check if the specified path is correct. More...
 
static std::string formatPath (const std::string &pPath, bool pFilenameOnly=false)
 Converts a string to a valid path string. More...
 
static std::string getPathFromEnvironment (const std::string &envVar)
 Retrieves the value of an environment variable as a path string. More...
 

Detailed Description

Paths used for internal Project filesystem.

The paths used for project filenames might differ from the actual disk storage, as the project might have different file/folder names or even virtual folders.

  • A global path starts with /
  • A relative path starts with ./
  • Folder paths end with /
  • Acceptable characters: Alphanumeric, _ - . + @

Constructor & Destructor Documentation

◆ Path() [1/3]

ansys::Project::Path::Path ( )

◆ Path() [2/3]

ansys::Project::Path::Path ( const std::string &  pPath)

◆ Path() [3/3]

ansys::Project::Path::Path ( const char *  pPath)

Member Function Documentation

◆ c_str()

const char * ansys::Project::Path::c_str ( ) const
inline

◆ formatPath()

std::string ansys::Project::Path::formatPath ( const std::string &  pPath,
bool  pFilenameOnly = false 
)
static

Converts a string to a valid path string.

Whitespace is strippped and invalid characters are replaced by _ Can also be used to check if a path is valid as-is.

Parameters
pFilenameOnly: to check if the path is for a filename (not a folder)

◆ getFilename()

std::string ansys::Project::Path::getFilename ( ) const

Return the filename part of the path.

If the path is a folder path, filename is empty

◆ getFolderName()

std::string ansys::Project::Path::getFolderName ( ) const

Return the folder name - only if Path is a folder path.

◆ getParentPath()

Path ansys::Project::Path::getParentPath ( ) const

Return the Path for the enclosing folder.

◆ getPathComponents()

std::vector< std::string > ansys::Project::Path::getPathComponents ( ) const

Return the path components as a vector of string.

Each folder component is returned with trailing /

 /path/folder/filename
 will lead to:
 [ /, path/, folder/, filename ]

◆ getPathFromEnvironment()

std::string ansys::Project::Path::getPathFromEnvironment ( const std::string &  envVar)
static

Retrieves the value of an environment variable as a path string.

Parameters
envVarThe name of the environment variable to retrieve
Returns
A std::string containing the value of the environment variable if it exists. Returns an empty string if the environment variable is not set or if the input is empty.

◆ getRelativePathTo()

Path ansys::Project::Path::getRelativePathTo ( const Path pTarget) const

Convert a global path and a global target to a relative path to the target.

◆ isFolderPath()

bool ansys::Project::Path::isFolderPath ( ) const

Indicates if the path is a folder path (ends with /)

◆ isNull()

bool ansys::Project::Path::isNull ( ) const

Indicates if the path is empty.

◆ isValidFilename()

bool ansys::Project::Path::isValidFilename ( const std::string &  pStr)
static

Check if the specified name is valid for a file.

Returns
false if the filename contains any invalid characters

◆ isValidPath()

bool ansys::Project::Path::isValidPath ( const std::string &  pStr)
static

Check if the specified path is correct.

◆ operator!=() [1/2]

bool ansys::Project::Path::operator!= ( const Path pPath) const
inline

◆ operator!=() [2/2]

bool ansys::Project::Path::operator!= ( const std::string &  pPathStr) const
inline

◆ operator+=()

void ansys::Project::Path::operator+= ( const std::string &  pPathStr)

Appends the string to the Path.

◆ operator==() [1/3]

bool ansys::Project::Path::operator== ( const char *  pPathStr) const
inline

◆ operator==() [2/3]

bool ansys::Project::Path::operator== ( const Path pPath) const

◆ operator==() [3/3]

bool ansys::Project::Path::operator== ( const std::string &  pPathStr) const

◆ str()

const std::string & ansys::Project::Path::str ( ) const

Return as string.

Connect with Ansys