ADTF
3.18.2
|
File/Directory path class. More...
Public Types | |
enum | PathSeparator { PS_ForwardSlash = 0 , PS_BackwardSlash = 1 , PS_Native = 2 } |
Path separator types. More... | |
Public Member Functions | |
Path () | |
Default CTOR for an empty path. | |
Path (const Path &path) | |
Copy CTOR. More... | |
Path & | operator= (const Path &path) |
Assignment Operator. More... | |
Path (const std::string &path) | |
Initializing CTOR. More... | |
Path (const char *path) | |
Initializing CTOR. More... | |
~Path () | |
DTOR. | |
operator std::string () const | |
Converts the path to the systems native string representation. More... | |
std::string | toString (PathSeparator separator=PS_Native) const |
Get the string representation of the current path using the specified separator. More... | |
bool | setPath (const std::string &path) |
Set the current path of the instance, handling platform aspects or any trailing slashes. More... | |
Path & | append (const Path &path) |
Appends a relative file or directory path or another file extension to the current path. More... | |
Path | getRoot () const |
Get the root path of the directory/file. More... | |
Path | getRootName () const |
Get the root name of the directory/file. More... | |
Path | getRootPath () const |
Get the root path of the directory/file. More... | |
Path | getParent () const |
Get the parent path of the directory or file. More... | |
Path | getLastElement () const |
Get the name of the directory or file. More... | |
std::string | getExtension () const |
Get the extension of the file (without the '. More... | |
Path & | appendToBasename (const std::string &str) |
Append a string to a basename. More... | |
Path & | replaceExtension (const std::string &extension) |
Replace the extension of the path. More... | |
Path & | removeLastElement () |
Remove the last part of the path, making it a directory path. More... | |
Path & | makeCanonical () |
Make the current path canonical. More... | |
Path & | makeAbsolute () |
Convert the path to an absolute path relative to the current working directory. More... | |
Path & | makeAbsolute (Path base_path) |
Convert the path to an absolute path relative to the given base_path . More... | |
Path & | makeRelative () |
Convert the path to a relative path relative to the current working directory. More... | |
Path & | makeRelative (Path input_path) |
Convert the path to a relative path relative to the input_path . More... | |
bool | isRelative () const |
Returns whether the current path is relative. More... | |
bool | isAbsolute () const |
Returns whether the current path is absolute. More... | |
bool | isEmpty () const |
Returns whether the current path is empty. More... | |
Path & | Clear () |
Clears the path and resets it to the empty state. More... | |
Private Attributes | |
std::unique_ptr< Implementation > | _impl |
File/Directory path class.
This class represents paths on the filesystem. Only syntactic aspects of paths are handled, the path may or may not exist and might not even be allowed to exist on the current platform.
enum PathSeparator |
Path | ( | const std::string & | path | ) |
Initializing CTOR.
[in] | path | The file or directory path to initialize the instance |
Path | ( | const char * | path | ) |
Initializing CTOR.
[in] | path | The file or directory path to initialize the instance |
Appends a relative file or directory path or another file extension to the current path.
[in] | path | The (relative) (file-)path or file extension to append |
*this
PathException | If path is absolute. |
Path& appendToBasename | ( | const std::string & | str | ) |
Append a string to a basename.
[in] | str | String to append to the basename |
*this | with str appended to the basename |
Path& Clear | ( | ) |
Clears the path and resets it to the empty state.
std::string getExtension | ( | ) | const |
Get the extension of the file (without the '.
')
e.g.: "/dir/subdir/file.txt" returns "txt", "/dir/subdir" returns ""
Path getLastElement | ( | ) | const |
Get the name of the directory or file.
e.g.: "/dir/subdir/file.txt" returns "file.txt", "/dir/subdir" returns "subdir"
Path getParent | ( | ) | const |
Get the parent path of the directory or file.
e.g.: "/dir/subdir/file.txt" returns "/dir/subdir", "/dir/subdir" returns "/dir"
Path getRoot | ( | ) | const |
Get the root path of the directory/file.
Usually "C:" or "D:" on Windows, on Unix-like systems usually "/". e.g.: "/dir/subdir/file.txt" returns "/", "C:/dir" returns "C:" @dev_essential_deprecated Use getRootName() instead.
Path getRootName | ( | ) | const |
Get the root name of the directory/file.
Usually "C:" or "D:" on Windows, on Unix-like systems usually "/". e.g.: "/dir/subdir/file.txt" returns "/", "C:/dir" returns "C:"
Path getRootPath | ( | ) | const |
Get the root path of the directory/file.
Usually "C:\" or "D:\" on Windows, on Unix-like systems usually "/". e.g.: "/dir/subdir/file.txt" returns "/", "C:/dir" returns "C:/"
bool isAbsolute | ( | ) | const |
Returns whether the current path is absolute.
true | if the path is absolute, false otherwise |
bool isEmpty | ( | ) | const |
Returns whether the current path is empty.
true | if the path is empty, false otherwise |
bool isRelative | ( | ) | const |
Returns whether the current path is relative.
true | if the path is relative, false otherwise |
PathException | if the current path is empty |
Path& makeAbsolute | ( | ) |
Convert the path to an absolute path relative to the current working directory.
*this
containing the absolute path Convert the path to an absolute path relative to the given base_path
.
[in] | base_path | Reference to which the absolute path is converted |
*this
containing the absolute path Path& makeCanonical | ( | ) |
Make the current path canonical.
This means that all occurences of '.' and '..' are evaluated syntactically. e.g.: "/./dir/../dir/file.txt" is replaced by "/file.txt".
*this
Path& makeRelative | ( | ) |
Convert the path to a relative path relative to the current working directory.
*this
containing the relative path Convert the path to a relative path relative to the input_path
.
[in] | input_path | Reference to which the relative path is converted |
*this
containing the relative path PathException | If the current path and the input_path have different roots |
operator std::string | ( | ) | const |
Converts the path to the systems native string representation.
The | string representation of the path (or empty string for empty path), using the platform native separator |
Assignment Operator.
[in] | path | The instance to copy from return Reference to *this |
Path& removeLastElement | ( | ) |
Remove the last part of the path, making it a directory path.
*this
Path& replaceExtension | ( | const std::string & | extension | ) |
Replace the extension of the path.
[in] | extension | The new extension (without '.') |
*this
bool setPath | ( | const std::string & | path | ) |
Set the current path of the instance, handling platform aspects or any trailing slashes.
[in] | path | The new path |
false
if the path is invalid and cannot be set, true
on success std::string toString | ( | PathSeparator | separator = PS_Native | ) | const |
Get the string representation of the current path using the specified separator.
[in] | separator | The separator to use |
The | string representation of the path (or empty string for empty path) |