MySQL 9.1.0
Source Code Documentation
|
Class representing a path in a file system. More...
#include <filesystem.h>
Public Types | |
enum class | FileType { STATUS_ERROR , EMPTY_PATH , FILE_NOT_FOUND , REGULAR_FILE , DIRECTORY_FILE , SYMLINK_FILE , BLOCK_FILE , CHARACTER_FILE , FIFO_FILE , SOCKET_FILE , TYPE_UNKNOWN } |
Enum used to identify file types. More... | |
Public Member Functions | |
Path () noexcept | |
Path (std::string path) | |
Construct a path. More... | |
Path (std::string_view path) | |
Path (const char *path) | |
bool | operator== (const Path &rhs) const |
bool | operator!= (const Path &rhs) const |
bool | operator< (const Path &rhs) const |
Path ordering operator. More... | |
FileType | type (bool refresh=false) const |
Get the file type. More... | |
bool | is_directory () const |
Check if the file is a directory. More... | |
bool | is_regular () const |
Check if the file is a regular file. More... | |
bool | is_absolute () const |
Check if the path is absolute or not. More... | |
bool | exists () const |
Check if path exists. More... | |
bool | is_readable () const |
Path | dirname () const |
Get the directory name of the path. More... | |
Path | basename () const |
Get the basename of the path. More... | |
void | append (const Path &other) |
Append a path component to the current path. More... | |
Path | join (const Path &other) const |
Join two path components to form a new path. More... | |
Path | real_path () const |
Returns the canonical form of the path, resolving relative paths. More... | |
const char * | c_str () const |
Get a C-string representation to the path. More... | |
const std::string & | str () const noexcept |
Get a string representation of the path. More... | |
bool | is_set () const noexcept |
Test if path is set. More... | |
operator bool () const noexcept | |
Static Public Member Functions | |
static Path | make_path (const Path &directory, const std::string &basename, const std::string &extension) |
Create a path from directory, basename, and extension. More... | |
Static Public Attributes | |
static const char *const | directory_separator = "/" |
Directory separator string. More... | |
static const char *const | root_directory = "/" |
Root directory string. More... | |
Private Member Functions | |
void | validate_non_empty_path () const |
Private Attributes | |
std::string | path_ |
FileType | type_ |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Path &path) |
HARNESS_EXPORT std::ostream & | operator<< (std::ostream &out, FileType type) |
Class representing a path in a file system.
Paths are used to access files in the file system and can be either relative or absolute. Absolute paths have a slash (/
) first in the path, otherwise, the path is relative.
|
strong |
Enum used to identify file types.
|
noexcept |
Path::Path | ( | std::string | path | ) |
Construct a path.
path | Non-empty string denoting the path. |
std::invalid_argument |
|
inline |
|
inline |
void Path::append | ( | const Path & | other | ) |
Append a path component to the current path.
This function will append a path component to the path using the appropriate directory separator.
other | Path component to append to the path. |
Path Path::basename | ( | ) | const |
Get the basename of the path.
Return the basename of the path: the path without the directory portion.
|
inline |
Get a C-string representation to the path.
Path
object is destroyed.Path Path::dirname | ( | ) | const |
Get the directory name of the path.
This will strip the last component of a path, assuming that the what remains is a directory name. If the path is a relative path that do not contain any directory separators, a dot will be returned (denoting the current directory).
bool Path::exists | ( | ) | const |
Check if path exists.
bool Path::is_absolute | ( | ) | const |
Check if the path is absolute or not.
The path is considered absolute if it starts with one of: Unix: '/' Windows: '/' or '\' or '.:' (where . is any character) else: it's considered relative (empty path is also relative in such respect)
bool Path::is_directory | ( | ) | const |
Check if the file is a directory.
bool Path::is_readable | ( | ) | const |
bool Path::is_regular | ( | ) | const |
Check if the file is a regular file.
|
inlinenoexcept |
Test if path is set.
Join two path components to form a new path.
This function will join the two path components using a directory separator.
Path
object. If you want to modify the existing path object, you should use append
instead.other | Path component to be appended to the path |
|
static |
Create a path from directory, basename, and extension.
|
inlinenoexcept |
|
inline |
bool Path::operator< | ( | const Path & | rhs | ) | const |
Path ordering operator.
This is mainly used for ordered containers. The paths are ordered lexicographically.
bool Path::operator== | ( | const Path & | rhs | ) | const |
Path Path::real_path | ( | ) | const |
Returns the canonical form of the path, resolving relative paths.
|
inlinenoexcept |
Get a string representation of the path.
Path::FileType Path::type | ( | bool | refresh = false | ) | const |
Get the file type.
The file type is normally cached so if the file type under a path changes it is necessary to force a refresh.
refresh | Set to true if the file type should be refreshed, default to false . |
|
private |
|
friend |
|
friend |
|
static |
Directory separator string.
|
private |
|
static |
Root directory string.
|
mutableprivate |