ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::system::Path Class Reference

Description:

Represents a directory or file in a file system.

Inherits a local string buffer fixed to size 256. The flexible nature of ALib local strings allows dynamic allocation if this should be exceeded (which usually is not expected with paths).

The character type of templated parent class AString is defined by the type definition alib::PathCharType, which in turn aliases std::filesystem::path::value_type.

Definition at line 157 of file path.hpp.

#include <path.hpp>

Inheritance diagram for alib::system::Path:
[legend]
Collaboration diagram for alib::system::Path:
[legend]

Public Static Field Index:

static PathString tempDirEvaluatedOnce
static PathString varTempDirEvaluatedOnce

Public Static Method Index:

static bool IsAbsolute (const PathString &path)
static bool IsUNCPath (const PathString &path)

Public Method Index:

 Path ()
 Path (const PathString &path)
 Path (SystemFolders special)
 Path (SystemFolders special, const PathString &fileName)
PathAdd (const PathString &dirOrFilename)
void AddModuleName (const PathString &extension)
bool Change (const PathString &path)
bool Change (SystemFolders special)
void Change (SystemFolders special, const PathString &fileName)
bool ChangeToParent ()
std::errc Create ()
std::errc Create (const PathString &path)
bool Exists ()
bool IsAbsolute () const
bool IsDirectory ()
bool IsUNCPath () const
void MakeAbsolute ()
std::errc MakeCanonical ()
PathString Name () const
PathString Parent () const
Public Method Index: inherited from alib::strings::TLocalString< PathCharType, 256 >
constexpr TLocalString (lang::HeapAllocator &pAllocator)
TLocalStringoperator= (const TLocalString &copy)
Public Method Index: inherited from alib::strings::TAString< PathCharType, lang::HeapAllocator >
 ~TAString () noexcept
 Destructs an AString object. An internally allocated buffer will be deleted.
TAString_ (const TAppendable &src)
TAStringAppend (const TCharSrc *src, integer srcLength)
const_iterator begin () const
integer Capacity () const
void dbgCheck () const
void DbgDisableBufferReplacementWarning ()
TAStringDelete (integer regionStart, integer regionLength=MAX_LEN)
TAStringDeleteEnd (integer regionLength)
TAStringDeleteStart (integer regionLength)
integer DetectLength (integer offset=0)
const_iterator end () const
void EnsureRemainingCapacity (integer spaceNeeded)
void GrowBufferAtLeastBy (integer minimumGrowth)
bool HasInternalBuffer () const
TAStringInsertAt (const TString< PathCharType > &src, integer pos)
TAStringInsertChars (PathCharType c, integer qty)
TAStringInsertUninitialized (integer pos, integer size)
TAStringNewLine ()
constexpr operator T () const
TAStringoperator+= (const TAppendable &src)
TAStringoperator<< (const TAppendable &src)
TAStringoperator= (const TAString &copy)
PathCharType operator[] (integer idx) const
constexpr PathCharType pop_back ()
constexpr void push_back (PathCharType ch)
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
TAStringReplaceRegion (PathCharType c, integer regionStart, integer regionLength)
TAStringReplaceSubstring (const TString< PathCharType > &src, integer regionStart, integer regionLength)
TAStringReset ()
TAStringReverse (integer regionStart=0, integer regionLength=MAX_LEN)
integer SearchAndReplace (PathCharType needle, PathCharType replacement, integer startIdx=0, integer endIdx=strings::MAX_LEN)
void SetBuffer (integer newCapacity)
void SetCharAt (integer idx, PathCharType c)
void SetLength (integer newLength)
void SetNull ()
 Invokes SetBuffer(0).
TAStringShortenBy (integer charsToRemove)
TAStringShortenTo (integer newLength)
constexpr const PathCharTypeTerminate () const
TAStringToLower (integer regionStart=0, integer regionLength=MAX_LEN)
TAStringToUpper (integer regionStart=0, integer regionLength=MAX_LEN)
TAStringTrim (const TCString< PathCharType > &trimChars=CStringConstantsTraits< PathCharType >::DefaultWhitespaces())
integer TrimAt (integer idx, const TCString< PathCharType > &trimChars=CStringConstantsTraits< PathCharType >::DefaultWhitespaces())
TAStringTrimEnd (const TCString< PathCharType > &trimChars=CStringConstantsTraits< PathCharType >::DefaultWhitespaces())
TAStringTrimStart (const TCString< PathCharType > &trimChars=CStringConstantsTraits< PathCharType >::DefaultWhitespaces())
PathCharTypeVBuffer () const
Public Method Index: inherited from alib::strings::TString< PathCharType >
constexpr TString () noexcept=default
constexpr TString (const PathCharType *pBuffer, integer pLength) noexcept
constexpr TString (const T &src) noexcept
constexpr TString (const TString &) noexcept=default
 Defaulted copy constructor.
 TString (const_iterator &start, const_iterator &end)
constexpr TString (lang::IsNullptr auto const &) noexcept
 Constructor accepting nullptr. Constructs a nulled string.
constexpr TString (T &src) noexcept
 TString (TAllocator &allocator, const TString< PathCharType > &copy)
constexpr TString (TString &&) noexcept=default
 Defaulted move constructor.
bool AdjustRegion (integer &regionStart, integer &regionLength) const
void Allocate (TAllocator &allocator, const TString< PathCharType > &copy)
const_iterator begin () const
constexpr const PathCharTypeBuffer () const
const_iterator cbegin () const
const_iterator cend () const
PathCharType CharAt (integer idx) const
PathCharType CharAtEnd () const
PathCharType CharAtStart () const
int CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength, integer regionStart, integer regionLength=MAX_LEN) const
int CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength=MAX_LEN) const
int CompareTo (const TString< PathCharType > &rhs) const
bool ContainsAt (const TString &needle, integer pos) const
integer CopyTo (PathCharType *dest) const
integer Count (const TString &needle, const TString &omit, integer startPos=0) const
integer Count (const TString &needle, integer startPos=0) const
integer CountChar (PathCharType needle, integer startPos=0) const
integer CountChar (PathCharType needle, PathCharType omit, integer startPos) const
const_reverse_iterator crbegin () const
const_reverse_iterator crend () const
const_iterator end () const
bool EndsWith (const TString &needle) const
bool Equals (const TString< PathCharType > &rhs) const
void Free (TAllocator &allocator)
std::size_t Hashcode () const
std::size_t HashcodeIgnoreCase () const
integer IndexOf (const TString &needle, integer startIdx=0, integer endIdx=strings::MAX_LEN) const
integer IndexOf (PathCharType needle, integer regionStart, integer regionLength) const
integer IndexOf (PathCharType needle, integer startIdx=0) const
integer IndexOfAny (const TString &needles, integer startIdx=0) const
integer IndexOfFirstDifference (const TString &needle, lang::Case sensitivity=lang::Case::Sensitive, integer startIdx=0) const
integer IndexOfOrLength (PathCharType needle) const
integer IndexOfOrLength (PathCharType needle, integer startIdx) const
integer IndexOfSegmentEnd (PathCharType opener, PathCharType closer, integer idx) const
constexpr bool IsEmpty () const
constexpr bool IsNotEmpty () const
constexpr bool IsNotNull () const
constexpr bool IsNull () const
integer LastIndexOf (PathCharType needle, integer startIndex=MAX_LEN) const
integer LastIndexOfAny (const TString &needles, integer startIdx=MAX_LEN) const
constexpr integer Length () const
constexpr operator T () const
constexpr TStringoperator= (const TString &) noexcept=default
constexpr TStringoperator= (TString &&) noexcept=default
PathCharType operator[] (integer idx) const
uint64_t ParseBin (integer *newIdx) const
uint64_t ParseBin (integer startIdx, integer *newIdx) const
uint64_t ParseBin (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
uint64_t ParseBin (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
uint64_t ParseDec (integer *newIdx) const
uint64_t ParseDec (integer startIdx, integer *newIdx) const
uint64_t ParseDec (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
uint64_t ParseDec (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
uint64_t ParseDecDigits (integer startIdx=0, integer *newIdx=nullptr) const
double ParseFloat (integer *newIdx) const
double ParseFloat (integer startIdx, integer *newIdx) const
double ParseFloat (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
double ParseFloat (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
uint64_t ParseHex (integer *newIdx) const
uint64_t ParseHex (integer startIdx, integer *newIdx) const
uint64_t ParseHex (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
uint64_t ParseHex (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
int64_t ParseInt (integer *newIdx) const
int64_t ParseInt (integer startIdx, integer *newIdx) const
int64_t ParseInt (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
int64_t ParseInt (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
uint64_t ParseOct (integer *newIdx) const
uint64_t ParseOct (integer startIdx, integer *newIdx) const
uint64_t ParseOct (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
uint64_t ParseOct (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
size_type size () const
bool StartsWith (const TString &needle) const
TString< PathCharTypeSubstring (integer regionStart, integer regionLength=MAX_LEN) const
integer WStringLength () const
Public Method Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
 AllocatorMember ()
AllocatorInterface< lang::HeapAllocatorAIF () const noexcept
lang::HeapAllocatorGetAllocator () const noexcept

Additional Inherited Members

Public Type Index: inherited from alib::strings::TAString< PathCharType, lang::HeapAllocator >
using AllocatorType
 Exposes the allocator type specified by template parameter TAllocator.
using iterator
using reverse_iterator
 Same as iterator, but working from the end to the start of the string.
Public Type Index: inherited from alib::strings::TString< PathCharType >
using const_iterator
using const_reverse_iterator
using size_type
 The type defining sizes of strings.
using value_type
 Exposes template parameter TChar to the outer world in a std compatible way.
Public Type Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
using AllocatorType
 Exposes the allocator type.
Protected Type Index: inherited from alib::strings::TLocalString< PathCharType, 256 >
using base
 The base AString-type.
using sBase
 The base String-type.
Protected Type Index: inherited from alib::strings::TAString< PathCharType, lang::HeapAllocator >
using allocBase
 The type of the base class that stores the allocator.
using base
 The base string-type.
Protected Field Index: inherited from alib::strings::TLocalString< PathCharType, 256 >
PathCharType localBuffer [TCapacity]
Protected Field Index: inherited from alib::strings::TAString< PathCharType, lang::HeapAllocator >
integer capacity
bool dbgWarnWhenExternalBufferIsReplaced
integer debugLastAllocRequest
Protected Field Index: inherited from alib::strings::TString< PathCharType >
const PathCharTypebuffer
integer length
Protected Field Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
lang::HeapAllocatorallocator
 The allocator stored.
Protected Method Index: inherited from alib::strings::TAString< PathCharType, lang::HeapAllocator >
constexpr TAString (lang::HeapAllocator &pAllocator, PathCharType *extBuffer, integer extBufferSize)
Protected Method Index: inherited from alib::strings::TString< PathCharType >
integer indexOfString (const TString &needle, integer startIdx, integer endIdx) const

Field Details:

◆ tempDirEvaluatedOnce

PathString alib::system::Path::tempDirEvaluatedOnce
static

Singleton containing the path for the use of enum value Temp. This is evaluated once with the first use of Temp. To change the default behavior of evaluation, this variable may be filled with a proper path before using enum Temp with this class.

The one-time evaluated value is stored in the GLOBAL_ALLOCATOR and access to this variable is consequently protected with GLOBAL_ALLOCATOR_LOCK.

Definition at line 170 of file path.hpp.

◆ varTempDirEvaluatedOnce

PathString alib::system::Path::varTempDirEvaluatedOnce
static

Singleton containing the path for the use of enum value VarTemp. This is evaluated once with the first use of VarTemp. To change the default behavior of evaluation, this variable may be filled with a proper path before using enum VarTemp with this class.

The one-time evaluated value is stored in the GLOBAL_ALLOCATOR and access to this variable is consequently protected with GLOBAL_ALLOCATOR_LOCK.

Definition at line 180 of file path.hpp.

Constructor(s) / Destructor Details:

◆ Path() [1/4]

alib::system::Path::Path ( )
inline

Constructs an object representing no directory. Field Path remains empty.

Definition at line 190 of file path.hpp.

◆ Path() [2/4]

alib::system::Path::Path ( SystemFolders special)
inline

Constructs an object representing one of the known special directories.

Parameters
specialThe special directory to initialize this instance to.

Definition at line 194 of file path.hpp.

Here is the call graph for this function:

◆ Path() [3/4]

alib::system::Path::Path ( SystemFolders special,
const PathString & fileName )
inline

Constructs an object representing one of the known special directories.

Parameters
specialThe special directory to initialize this instance to.
fileNameThe filename in folder special.

Definition at line 199 of file path.hpp.

Here is the call graph for this function:

◆ Path() [4/4]

alib::system::Path::Path ( const PathString & path)
inline

Constructs an object representing the given path.

Parameters
pathThe initial path.

Definition at line 203 of file path.hpp.

Here is the call graph for this function:

Method Details:

◆ Add()

Path & alib::system::Path::Add ( const PathString & dirOrFilename)
inline

Adds a directory or filename to the internal string. If the current string does not end with a alib::DIRECTORY_SEPARATOR, one will be inserted first.

Parameters
dirOrFilenameThe path component to add.
Returns
*this to allow concatenated operations.

Definition at line 264 of file path.hpp.

Here is the call graph for this function:

◆ AddModuleName()

void alib::system::Path::AddModuleName ( const PathString & extension)

Adds this processes' module name to the currently stored folder path.

Parameters
extensionAn additional extension string that is added to the evaluated file name, for example, ".jpg".

Definition at line 356 of file path.cpp.

Here is the call graph for this function:

◆ Change() [1/3]

bool alib::system::Path::Change ( const PathString & path)

Changes the directory. If the given path is absolute and valid, this objects' content is replaced. Otherwise, it is tested if the current combined path string is a directory, and if so, the given path is appended. If the resulting destination directory is not valid, false is returned and this object is not changed.

Parameters
pathThe relative or absolute path to change to.
Returns
true if the change was successful and this instance was changed, false otherwise.

Definition at line 370 of file path.cpp.

Here is the call graph for this function:

◆ Change() [2/3]

bool alib::system::Path::Change ( SystemFolders special)

Changes the directory to one of the known special directories.

Parameters
specialThe special directory to change this instance to.
Returns
true if the change was successful, false otherwise.

Definition at line 77 of file path.cpp.

Here is the call graph for this function:

◆ Change() [3/3]

void alib::system::Path::Change ( SystemFolders special,
const PathString & fileName )
inline

Changes the directory to one of the known special directories and adds the given fileName to this path.

Parameters
specialThe special directory to change this instance to.
fileNameThe filename within special.

Definition at line 243 of file path.hpp.

Here is the call graph for this function:

◆ ChangeToParent()

bool alib::system::Path::ChangeToParent ( )

In the case of directories, this path is set to the parent directory. In the case of files, the file name is removed from the path.

If the resulting destination directory is not valid, false is returned and this object is not changed.

Returns
true if the change was successful, false otherwise. I.e., in case this object represented the root folder false is returned.

Definition at line 392 of file path.cpp.

Here is the call graph for this function:

◆ Create() [1/2]

std::errc alib::system::Path::Create ( )
inline

Creates the directory represented by this object by invoking Create(const PathString&) passing an empty String.

Returns
A value of enum type std::errc.

Definition at line 222 of file path.hpp.

Here is the call graph for this function:

◆ Create() [2/2]

std::errc alib::system::Path::Create ( const PathString & path)

Creates the directory of the given path. If a relative path is given, then it is appended to the currently stored path, otherwise the current path is replaced.

Parameters
pathZero-terminated string defining the path to test.
Returns
A value of enum type std::errc.

Definition at line 478 of file path.cpp.

Here is the call graph for this function:

◆ Exists()

bool alib::system::Path::Exists ( )

Tests if this path represents an existing file or directory in the file system.

Returns
true if this path represents an existing file or directory, false otherwise.

Definition at line 29 of file filestatus.cpp.

Here is the call graph for this function:

◆ IsAbsolute() [1/2]

bool alib::system::Path::IsAbsolute ( ) const
inline

Invokes static overloaded method IsAbsolute(const PathString&), passing this object.

Returns
true if the given path is absolute, false otherwise.

Definition at line 360 of file path.hpp.

Here is the call graph for this function:

◆ IsAbsolute() [2/2]

bool alib::system::Path::IsAbsolute ( const PathString & path)
inlinestatic

Determines if the given string contains a path/filename with absolute addressing or not.

Parameters
pathThe path to check for absolute addressing.
Returns
true if the given path is absolute, false otherwise.

Definition at line 366 of file path.hpp.

Here is the call graph for this function:

◆ IsDirectory()

bool alib::system::Path::IsDirectory ( )

Tests if this path represents an existing directory in the file system.

Returns
true if a directory was found, false if not found or the path represents a file.

Definition at line 416 of file path.cpp.

Here is the call graph for this function:

◆ IsUNCPath() [1/2]

bool alib::system::Path::IsUNCPath ( ) const
inline

Invokes static overloaded method IsUNCPath(const PathString&), passing this object.

Returns
true if the given path is a UNC path, false otherwise. On non-WindowsOS systems, this method always returns false,

Definition at line 324 of file path.hpp.

Here is the call graph for this function:

◆ IsUNCPath() [2/2]

bool alib::system::Path::IsUNCPath ( const PathString & path)
inlinestatic

Determines if the given string contains a path that uses UNC addressing .

Parameters
pathThe path to check for UNC-addressing.
Returns
true if the given path is absolute, false otherwise.

Definition at line 336 of file path.hpp.

Here is the call graph for this function:

◆ MakeAbsolute()

void alib::system::Path::MakeAbsolute ( )

Changes the path to an absolute path, in case it is not yet one. This function does not create a canonical path like MakeCanonical does. On non-WindowsOS systems, if not absolute, the current working directory is set and the current content is appended (separated by alib::DIRECTORY_SEPARATOR). Under Windows OS function GetFullPathNameW is used, which allows to reflect the current directory per drive letter, if, for example, "D:mysubdir" is given.

Definition at line 508 of file path.cpp.

Here is the call graph for this function:

◆ MakeCanonical()

std::errc alib::system::Path::MakeCanonical ( )

Resolves the path by removing all symbolic links and relative addressing.

Returns
std::errc(0) on success, otherwise an error code.

Definition at line 445 of file path.cpp.

Here is the call graph for this function:

◆ Name()

PathString alib::system::Path::Name ( ) const
inline

Gets the name portion of the path.

Returns
A string containing the characters after the last directory separator.

Definition at line 290 of file path.hpp.

Here is the call graph for this function:

◆ Parent()

PathString alib::system::Path::Parent ( ) const
inline

In the case of directories, the path string to the parent directory is returned. In the case of files, the directory that the file resides in is returned.

Returns
A string containing the characters from the start to the last directory separator. If the currently stored string ends with a separator, this is returned first.

Definition at line 302 of file path.hpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: