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
Path(const std::string &path, bool skipPathCheck=false)Create a normalized path from a string.
Parameters
| Parameter | Description |
|---|---|
path (in) | Input path. |
skipPathCheck (in) | If true, only separators are converted; normalize() is skipped. |
Public member functions
operator+
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
| Parameter | Description |
|---|---|
additionalPath (in) | string to append |
Returns the concatenated path
Path operator+(const Path &additionalPath)Join two paths with a separator (not normalized).
Parameters
| Parameter | Description |
|---|---|
additionalPath (in) | path to append |
Returns this + separator + additionalPath
getPath
const std::string &getPath() constReturns the path string
getString
const std::string &getString() constReturns the path string (same as getPath())
getBaseFileName
std::string getBaseFileName()Returns File name without extension.
getTopDirectory
Path getTopDirectory()Returns Name of the parent directory containing this path.
getFileName
std::string getFileName()Returns File name including extension.
getFileExtension
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
Path getDirectory()Returns Directory path containing this path (everything before the last separator), or an empty path if there is no separator.
fileExists
bool fileExists()Returns True if the file exists and can be opened for reading.
directoryExists
bool directoryExists()Returns True if anything (file or directory) exists at the path.
operator std::string
operator std::string() constReturns the path string
Static member functions
normalize static
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
| Parameter | Description |
|---|---|
in (in) | path using the platform separator |
Returns the normalized path; "" stays "", and a relative path that cancels out becomes "."
separator static
static std::string separator()Returns the platform path separator ("\\" on Windows, "/" elsewhere)
antiSeparator static
static std::string antiSeparator()Returns the separator of the other platform family ("/" on Windows, "\\" elsewhere)
replaceAntiSeparatorWithSeparator static
static void replaceAntiSeparatorWithSeparator(std::string &string)Replace every antiSeparator() with separator() in place.
Parameters
| Parameter | Description |
|---|---|
string (in, out) | path string to convert |
upperDir static
static std::string upperDir()Returns the parent-directory component ".."
setFromArgv static
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
| Parameter | Description |
|---|---|
argv0 (in) | argv[0] of main() |
Returns the absolute, lexically normalized executable path