CppCommon
1.0.4.1
C++ Common Library
|
Filesystem path. More...
#include <path.h>
Public Member Functions | |
Path () | |
Initialize path with an empty value. More... | |
Path (const char *path) | |
Initialize path with a given C-string value. More... | |
Path (const std::string &path) | |
Initialize path with a given string value. More... | |
Path (const wchar_t *path) | |
Initialize path with a given wide C-string value. More... | |
Path (const std::wstring &path) | |
Initialize path with a given wide string value. More... | |
Path (const Path &)=default | |
Path (Path &&)=default | |
~Path ()=default | |
Path & | operator= (const Path &)=default |
Path & | operator= (Path &&)=default |
operator bool () const noexcept | |
Check if the path is not empty. More... | |
Path & | operator/= (const Path &path) |
Path & | operator+= (const Path &path) |
const std::string & | string () const noexcept |
Get the path value as UTF-8 string. More... | |
std::wstring | wstring () const |
Get the path value as a wide string. More... | |
Path | root () const |
Decompose root path from the current path. More... | |
Path | relative () const |
Decompose relative path from the current path. More... | |
Path | parent () const |
Decompose parent path from the current path. More... | |
Path | filename () const |
Decompose filename from the current path. More... | |
Path | stem () const |
Decompose stem from the current path. More... | |
Path | extension () const |
Decompose extension from the current path. More... | |
Path | absolute () const |
Transform the current path to the real path on a filesystem. More... | |
Path | canonical () const |
Transform the current path and replace all '.' and '..' properly. More... | |
Path | validate (char placeholder='_') const |
Transform the current path and replace all deprecated characters with a given placeholder (default is '_') More... | |
FileType | type () const |
Get the path file type. More... | |
Flags< FileAttributes > | attributes () const |
Get the path file attributes. More... | |
Flags< FilePermissions > | permissions () const |
Get the path file permissions. More... | |
UtcTimestamp | created () const |
Get the path created UTC timestamp. More... | |
UtcTimestamp | modified () const |
Get the path modified UTC timestamp. More... | |
size_t | hardlinks () const |
Get the path count of hardlinks. More... | |
SpaceInfo | space () const |
Get the path space information. More... | |
bool | empty () const noexcept |
Is the path empty? More... | |
bool | HasRoot () const |
Has root path? More... | |
bool | HasRelative () const |
Has relative path? More... | |
bool | HasParent () const |
Has parent path? More... | |
bool | HasFilename () const |
Has filename? More... | |
bool | HasStem () const |
Has stem? More... | |
bool | HasExtension () const |
Has extension? More... | |
bool | IsAbsolute () const |
Is absolute path? More... | |
bool | IsRelative () const |
Is relative path? More... | |
bool | IsExists () const |
Is the path exists? More... | |
bool | IsRegularFile () const |
Is the path points to regular file? More... | |
bool | IsDirectory () const |
Is the path points to directory? More... | |
bool | IsSymlink () const |
Is the path points to symbolic link? More... | |
bool | IsOther () const |
Is the path points to special file (block, character, FIFO, socket)? More... | |
bool | IsEquivalent (const Path &path) const |
Is the current path is equivalent to the given one (points to the same node on a filesystem)? More... | |
void | Clear () noexcept |
Clear the path content. More... | |
Path & | Assign (const Path &path) |
Assign the given path to the current one. More... | |
Path & | Append (const Path &path) |
Append the given path to the current one. More... | |
Path & | Concat (const Path &path) |
Concatenate the given path to the current one. More... | |
Path & | MakePreferred () |
Convert all path separators to system ones ('\' for Windows or '/' for Unix) More... | |
Path & | ReplaceFilename (const Path &filename) |
Replace the current path filename with a given one. More... | |
Path & | ReplaceExtension (const Path &extension) |
Replace the current path extension with a given one. More... | |
Path & | RemoveFilename () |
Remove the current path filename. More... | |
Path & | RemoveExtension () |
Remove the current path extension. More... | |
Path & | RemoveTrailingSeparators () |
Remove all trailing separators form the current path. More... | |
void | swap (Path &path) noexcept |
Swap two instances. More... | |
Static Public Member Functions | |
static bool | deprecated (char character) noexcept |
Is the given character is deprecated by the filesystem? More... | |
static bool | deprecated (wchar_t character) noexcept |
Is the given wide character is deprecated by the filesystem? More... | |
static std::string | deprecated () |
Get filesystem deprecated characters ('\', '/', '?', '', '*', ':', '|', '"', '<', '>') More... | |
static char | separator () noexcept |
Get the system path separator character ('\' for Windows or '/' for Unix) More... | |
static Path | initial () |
Get the initial path of the process. More... | |
static Path | current () |
Get the current path of the process. More... | |
static Path | executable () |
Get the executable path of the process. More... | |
static Path | home () |
Get the home path of the process. More... | |
static Path | temp () |
Get the temporary path of the process. More... | |
static Path | unique () |
Get the unique filename in UUID format "00000000-0000-0000-0000-000000000000". More... | |
static Path | Copy (const Path &src, const Path &dst, bool overwrite=false) |
Copy the given source path to destination path (file, empty directory, symlink, etc) More... | |
static Path | CopyIf (const Path &src, const Path &dst, const std::string &pattern="", bool overwrite=false) |
Copy all matched files from the the given source path to destination path (files, directories, symlinks, etc) More... | |
static Path | CopyAll (const Path &src, const Path &dst, bool overwrite=false) |
Recursively copy the given source path to destination path (files, directories, symlinks, etc) More... | |
static Path | Rename (const Path &src, const Path &dst) |
Rename the given source path to destination path (file, empty directory, symlink, etc) More... | |
static Path | Remove (const Path &path) |
Remove the given path (file, empty directory, symlink, etc) from the filesystem. More... | |
static Path | RemoveAll (const Path &path) |
Recursively remove the given path (file, empty directory, symlink, etc) from the filesystem. More... | |
static Path | RemoveIf (const Path &path, const std::string &pattern="") |
Recursively remove the given path matched to the given pattern (file, empty directory, symlink, etc) from the filesystem. More... | |
static void | SetAttributes (const Path &path, const Flags< FileAttributes > &attributes) |
Set file attributes for the given path. More... | |
static void | SetPermissions (const Path &path, const Flags< FilePermissions > &permissions) |
Set file permissions for the given path. More... | |
static void | SetCreated (const Path &path, const UtcTimestamp ×tamp) |
Set created UTC timestamp for the given path. More... | |
static void | SetModified (const Path &path, const UtcTimestamp ×tamp) |
Set modified UTC timestamp for the given path. More... | |
static void | SetCurrent (const Path &path) |
Set the given path of the process as a current one. More... | |
static void | Touch (const Path &path) |
Touch the given path and set its modified UTC timestamp to the current value. More... | |
Protected Attributes | |
std::string | _path |
Path string. More... | |
Friends | |
Path | operator/ (const Path &path1, const Path &path2) |
Path | operator+ (const Path &path1, const Path &path2) |
bool | operator== (const Path &path1, const Path &path2) |
bool | operator!= (const Path &path1, const Path &path2) |
bool | operator< (const Path &path1, const Path &path2) |
bool | operator> (const Path &path1, const Path &path2) |
bool | operator<= (const Path &path1, const Path &path2) |
bool | operator>= (const Path &path1, const Path &path2) |
std::istream & | operator>> (std::istream &is, Path &path) |
Input instance from the given input stream. More... | |
std::ostream & | operator<< (std::ostream &os, const Path &path) |
Output instance into the given output stream. More... | |
void | swap (Path &path1, Path &path2) noexcept |
Filesystem path.
Filesystem path wraps string directory, filename, symlink and other path types in a class and provide utility methods to check type of the path, status and permissions in a file system. Additionally path contains operators and methods for path manipulation (concatenation, canonization, absolute path).
Path is managed in UTF-8 encoding!
Not thread-safe.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
default |
|
default |
|
default |
Path CppCommon::Path::absolute | ( | ) | const |
Flags< FileAttributes > CppCommon::Path::attributes | ( | ) | const |
Path CppCommon::Path::canonical | ( | ) | const |
|
inlinenoexcept |
|
static |
Copy all matched files from the the given source path to destination path (files, directories, symlinks, etc)
src | - Source path |
dst | - Destination path |
pattern | - Regular expression pattern (default is "") |
overwrite | - Overwrite destination path (default is false) |
UtcTimestamp CppCommon::Path::created | ( | ) | const |
|
static |
Get the current path of the process.
|
static |
Get filesystem deprecated characters ('\', '/', '?', '', '*', ':', '|', '"', '<', '>')
|
staticnoexcept |
|
staticnoexcept |
|
inlinenoexcept |
|
static |
Get the executable path of the process.
Path CppCommon::Path::extension | ( | ) | const |
Path CppCommon::Path::filename | ( | ) | const |
size_t CppCommon::Path::hardlinks | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
static |
Get the home path of the process.
|
static |
Get the initial path of the process.
|
inline |
|
inline |
bool CppCommon::Path::IsEquivalent | ( | const Path & | path | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Path & CppCommon::Path::MakePreferred | ( | ) |
UtcTimestamp CppCommon::Path::modified | ( | ) | const |
|
inlineexplicitnoexcept |
Path CppCommon::Path::parent | ( | ) | const |
Flags< FilePermissions > CppCommon::Path::permissions | ( | ) | const |
Path CppCommon::Path::relative | ( | ) | const |
Remove the given path (file, empty directory, symlink, etc) from the filesystem.
path | - Path to remove |
|
inline |
|
inline |
Recursively remove the given path matched to the given pattern (file, empty directory, symlink, etc) from the filesystem.
All files/symlinks will be matched to the given pattern!
path | - Path to remove |
pattern | - Regular expression pattern (default is "") |
Path & CppCommon::Path::RemoveTrailingSeparators | ( | ) |
Path CppCommon::Path::root | ( | ) | const |
|
staticnoexcept |
Get the system path separator character ('\' for Windows or '/' for Unix)
|
static |
|
static |
|
static |
|
static |
|
static |
SpaceInfo CppCommon::Path::space | ( | ) | const |
Get the path space information.
Path CppCommon::Path::stem | ( | ) | const |
|
inlinenoexcept |
|
inlinenoexcept |
|
static |
Get the temporary path of the process.
|
static |
FileType CppCommon::Path::type | ( | ) | const |
|
static |
Get the unique filename in UUID format "00000000-0000-0000-0000-000000000000".
Path CppCommon::Path::validate | ( | char | placeholder = '_' | ) | const |
|
inline |
|
friend |
|
friend |