Class to encapsulate a path to a file or directory and facilitate path operations. More...
#include <UTPath.h>
Class to encapsulate a relative or absolute path to a file or directory and facilitate path operations without the developer having to be concerned with platforms like Windows which use a nonstandard path delimiter. '/' is treated as being the canonical path delimiter, and the path object will accept it and treat it as such. On platforms which use a nonstandard path delimiter, the UT library will convert any slashes to the nonstandard delimiter when it needs to use a such a path in a system call.
Definition at line 49 of file UTPath.h.
Path_t::Path_t | ( | byte * | buffer, | |
int | buffer_size | |||
) | [inline] |
Constructor for a path which initially uses a stack-allocated buffer of the specified size. If the required size grows beyond that size, the buffer will be reallocated from the heap. Unless it is guaranteed that the needed size is going to be less than PATH_MAX, if a stack buffer is to be used, PathB_t would be a more straightforward way to accomplish the same thing since it has a built-in buffer of size PATH_MAX. A file does not need to exist at the path to be valid.
Path_t::Path_t | ( | stringliteral * | path | ) | [inline] |
Path which persistently references a string literal; the pointer is borrowed. Therefore the path object is dependent on the pointer with which it was constructed. The contents of that pointer must remain valid for the life of the path object. Any manipulation of the path will cause the contents to be copied to a dynamically allocated buffer. At that point, the path object will no longer be dependent on the contents of the string literal constant. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.
Path_t::Path_t | ( | const utf8 * | path | ) | [inline] |
Path_t::Path_t | ( | const Path_t & | path | ) | [inline] |
Path_t::Path_t | ( | const String_t & | path | ) | [inline] |
Status_t Path_t::Set | ( | stringliteral * | path | ) | [inline] |
const Path_t & Path_t::operator= | ( | stringliteral * | path | ) | [inline] |
bool Path_t::IsPathValid | ( | ) | const |
Checks the path's validity. Returns true if the path is valid, false if it is not. A file does not need to exist at the path to be valid.
Status_t Path_t::Append | ( | stringliteral * | leaf | ) | [inline] |
Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.
Reimplemented from String_t.
Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.
Reimplemented from String_t.
Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.
Reimplemented from String_t.
Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.
Status_t Path_t::AppendToLeaf | ( | stringliteral * | add_to_leaf | ) | [inline] |
const Path_t & Path_t::operator+= | ( | stringliteral * | path | ) | [inline] |
Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.
Reimplemented from String_t.
Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.
Reimplemented from String_t.
Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.
Reimplemented from String_t.
Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.
Path_t Path_t::operator+ | ( | stringliteral * | append | ) | const [inline] |
Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.
Reimplemented from String_t.
Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.
Reimplemented from String_t.
Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.
Reimplemented from String_t.
Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.
Obtains the name of the last path element. That could be the name of the specified file with all path information removed, or the name of the specified directory with all parent path components removed. If the path is not valid, an error status is returned. A file does not need to exist at the path to be valid.
Converts the path to be relative to the path sepecified by relative to. If canonical is true, any nonstandard path delimiters (like '\' under Windows) will be converted to the canonical '/' delimiter.
Status_t Path_t::ToParent | ( | ) |
Removes the last path element. If the path is a relative path, the ToParent function will resolve the parent path to an absolute path if necessary. If the path is not valid, or has no parent directory, an error status is returned. A file does not need to exist at the path to be valid.
Obtains the parent directory of the path specified by this. If this specifies a relative path, the GetParent function will resolve the parent path to an absolute path if necessary. If the path specified by this is not valid, or has no parent directory, an error status is returned. A file does not need to exist at the path to be valid.
Status_t Path_t::IsDirectory | ( | ) | const |
Checks whether this is a directory (not a regular file, pipe, etc). If this is not a valid path, or the specified path does not exist, IsDirectory returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult(). If the path is a symbolic link, it will be dereferenced.
If this is a directory, dir will be set to the same path specified by this. If this is a file, dir will be set to the parent directory of the file.
Status_t Path_t::IsAbsolute | ( | ) | const |
Checks whether this is an absolute path. If this is not a valid path, IsAbsolute returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult(). A file does not need to exist at the path to be valid.
Status_t Path_t::MakeAbsolute | ( | ) |
If this specifies a relative path, it will be converted to an absolute path. If the path specified by this is not valid, an error status is returned. A file does not need to exist at the path to be valid.
Status_t Path_t::IsRootDirectory | ( | ) | const |
Checks whether this is a root path (one with no parent). If this is not a valid path, IsRootDirectory returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult().
Status_t Path_t::IsRegularFile | ( | ) | const |
Checks whether this is a regular file (not a directory, pipe, etc). If this is not a valid path, or the specified path does not exist, IsRegularFile returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult(). If the path is a symbolic link, it will be dereferenced.
Checks whether this is a regular file. If it is, returns a success status and sets *size to indicate the size of the file. If the path is a symbolic link, it will be dereferenced.
Status_t Path_t::IsSymLink | ( | ) | const |
Checks whether this is a symbolic link. If this is not a valid path, or the specified path does not exist, IsSymLink returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult().
Status_t Path_t::MakeDir | ( | bool | recursive = true , |
|
mode_t | permissions = (S_IRUSR|S_IWUSR)|S_IXUSR | |||
) | const |
Creates a directory at the specified path. If it already exists and is a regular directory, returns the POSIX error EEXIST. If it already exists but is not a directory, returns the POSIX error ENOTDIR. The following symbolic constants are provided for permissions:
S_IRWUSR user (file owner) has read, write permission
S_IRWXU user (file owner) has read, write and execute permission
S_IRUSR (S_IREAD) user has read permission
S_IWUSR (S_IWRITE) user has write permission
S_IXUSR (S_IEXEC) user has execute permission
S_IRWGRP group has read, write permission
S_IRWXG group has read, write and execute permission
S_IRGRP group has read permission
S_IWGRP group has write permission
S_IXGRP group has execute permission
S_IRWOTH others have read, write permission
S_IRWXO others have read, write and execute permission
S_IROTH others have read permission
S_IWOTH others have write permisson
S_IXOTH others have execute permission
Status_t Path_t::Delete | ( | bool | recursive = false |
) | const |
Deletes the file or directory at the specified path. If no such file or directory existed, returns the POSIX error ENOENT. If the path to be deleted is a directory and it is not empty, it can only be deleted if the recursive parameter is true.
Obtains the path of the application executable. If an error occurs, an error status will be returned.
Obtains the path of the directory containing the application executable. If an error occurs, an error status will be returned.
Obtains the current working directory. If an error occurs, an error status will be returned.
Sets the current working directory. If an error occurs, an error status will be returned.
Obtains the path of the user's home directory.
bool Path_t::IsDelimiter | ( | utf8 | c | ) | [inline, static] |
Returns true if the character c is a path delimiter. If c is '/' (the canonical delimiter), it will always return true. On platforms which use a nonstandard delimiter (like Windows' '\'), it will also return true if c matches the nonstandard delimiter. This function will not return true for the character used to delimit separate complete paths as in "C:\a;C:\b" or "/usr/bin:/sbin").
Status_t Path_t::StripCurrAndParentDirs | ( | ) | [inline] |