Skip to content

raisim::Path ​

class · #include <raisim/Path.hpp>

A file system path string using the platform separator. Unlike std::filesystem::path, it stores a plain string: the constructor converts the other separator to the platform one and normalizes "." and ".." components.

Constructors & destructor ​

Path ​

cpp
Path(const std::string &path, bool skipPathCheck=false)

Create a normalized path from a string.

Parameters

ParameterDescription
path (in)Input path.
skipPathCheck (in)If true, only separators are converted; normalize() is skipped.

Public member functions ​

operator+ ​

cpp
Path operator+(const std::string &additionalPath)

Append a string. If the caller's fragment starts with a separator and this path already ends with one, drop the duplicate rather than producing "a//b".

The previous test was additionalPath.substr(1) == separator(), which compares everything AFTER the first character against a single separator – true only for two-character inputs like "x/", and it then appended substr(1), silently dropping the "x". No separator is inserted otherwise, and the result is not normalized.

Parameters

ParameterDescription
additionalPath (in)string to append

Returns the concatenated path

cpp
Path operator+(const Path &additionalPath)

Join two paths with a separator (not normalized).

Parameters

ParameterDescription
additionalPath (in)path to append

Returns this + separator + additionalPath

getPath ​

cpp
const std::string &getPath() const

Returns the path string

getString ​

cpp
const std::string &getString() const

Returns the path string (same as getPath())

getBaseFileName ​

cpp
std::string getBaseFileName()

Returns File name without extension.

getTopDirectory ​

cpp
Path getTopDirectory()

Returns Name of the parent directory containing this path.

getFileName ​

cpp
std::string getFileName()

Returns File name including extension.

getFileExtension ​

cpp
std::string getFileExtension()

Returns Text after the last '.' in the path (the extension without the dot). The whole path is returned if it has no '.'.

getDirectory ​

cpp
Path getDirectory()

Returns Directory path containing this path (everything before the last separator), or an empty path if there is no separator.

fileExists ​

cpp
bool fileExists()

Returns True if the file exists and can be opened for reading.

directoryExists ​

cpp
bool directoryExists()

Returns True if anything (file or directory) exists at the path.

operator std::string ​

cpp
operator std::string() const

Returns the path string

Static member functions ​

normalize static ​

cpp
static std::string normalize(const std::string &in)

Resolve "." and ".." component-wise and collapse repeated separators.

".." is only treated as a parent reference when it is a whole path component. Matching it as a raw substring (the previous behaviour) mangled ordinary names such as "robot..v2", and could compute rfind() == npos and pass it to erase(), which throws std::out_of_range for an input as mundane as "meshes/../foo.obj". A leading ".." is kept, because a relative path may legitimately escape its starting directory; a ".." above an absolute root is dropped.

Parameters

ParameterDescription
in (in)path using the platform separator

Returns the normalized path; "" stays "", and a relative path that cancels out becomes "."

separator static ​

cpp
static std::string separator()

Returns the platform path separator ("\\" on Windows, "/" elsewhere)

antiSeparator static ​

cpp
static std::string antiSeparator()

Returns the separator of the other platform family ("/" on Windows, "\\" elsewhere)

replaceAntiSeparatorWithSeparator static ​

cpp
static void replaceAntiSeparatorWithSeparator(std::string &string)

Replace every antiSeparator() with separator() in place.

Parameters

ParameterDescription
string (in, out)path string to convert

upperDir static ​

cpp
static std::string upperDir()

Returns the parent-directory component ".."

setFromArgv static ​

cpp
static Path setFromArgv(char *argv0)

Absolute path of the executable named by argv[0]. A relative argv[0] (./a, ../a, dir/a) is relative to the working directory; an absolute one is kept as is. Fatal if the path cannot be resolved.

Parameters

ParameterDescription
argv0 (in)argv[0] of main()

Returns the absolute, lexically normalized executable path

RaiSim — physics for robotics and AI.