|
Dev Essential
|
#include <path.h>
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) | |
| Path & | operator= (const Path &path) |
| Path (const std::string &path) | |
| Path (const char *path) | |
| ~Path () | |
| DTOR. | |
| operator std::string () const | |
| std::string | toString (PathSeparator separator=PS_Native) const |
| bool | setPath (const std::string &path) |
| Path & | append (const Path &path) |
| Path | getRoot () const |
| Path | getRootName () const |
| Path | getRootPath () const |
| Path | getParent () const |
| Path | getLastElement () const |
| std::string | getExtension () const |
| Path & | appendToBasename (const std::string &str) |
| Path & | replaceExtension (const std::string &extension) |
| Path & | removeLastElement () |
| Path & | makeCanonical () |
| Path & | makeAbsolute () |
| Path & | makeAbsolute (Path base_path) |
| Path & | makeRelative () |
| Path & | makeRelative (Path input_path) |
| bool | isRelative () const |
| bool | isAbsolute () const |
| bool | isBaseOf (const Path &path) const |
| bool | isEmpty () const |
| Path & | Clear () |
Friends | |
| bool | operator== (const Path &lhs, const Path &rhs) |
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.
Path separator types.
| Enumerator | |
|---|---|
| PS_ForwardSlash | Unix slash. |
| PS_BackwardSlash | Windows slash. |
| PS_Native | Native slash, depending on the current platform. |
| a_util::filesystem::Path::Path | ( | const Path & | path | ) |
Copy CTOR
| [in] | path | The instance to copy from |
| a_util::filesystem::Path::Path | ( | const std::string & | path | ) |
Initializing CTOR
| [in] | path | The file or directory path to initialize the instance |
| a_util::filesystem::Path::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 & a_util::filesystem::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 & a_util::filesystem::Path::Clear | ( | ) |
Clears the path and resets it to the empty state
| std::string a_util::filesystem::Path::getExtension | ( | ) | const |
Get the extension of the file (without the '.')
e.g.: "/dir/subdir/file.txt" returns "txt", "/dir/subdir" returns ""
| Path a_util::filesystem::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 a_util::filesystem::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 a_util::filesystem::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:"
| Path a_util::filesystem::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 a_util::filesystem::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 a_util::filesystem::Path::isAbsolute | ( | ) | const |
Returns whether the current path is absolute
| true | if the path is absolute, false otherwise |
| bool a_util::filesystem::Path::isBaseOf | ( | const Path & | path | ) | const |
Returns whether the current path is a child path of the target path
| true | if the path is a child, false otherwise |
| bool a_util::filesystem::Path::isEmpty | ( | ) | const |
Returns whether the current path is empty
| true | if the path is empty, false otherwise |
| bool a_util::filesystem::Path::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 & a_util::filesystem::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 & a_util::filesystem::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 & a_util::filesystem::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 |
| a_util::filesystem::Path::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 & a_util::filesystem::Path::removeLastElement | ( | ) |
Remove the last part of the path, making it a directory path.
*this | Path & a_util::filesystem::Path::replaceExtension | ( | const std::string & | extension | ) |
Replace the extension of the path
| [in] | extension | The new extension (without '.') |
*this | bool a_util::filesystem::Path::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 a_util::filesystem::Path::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) |
Check two paths for equality
| [in] | lhs | Right hand side object |
| [in] | rhs | Left hand side object |
| true | if the paths are equal, false otherwise |