ALib C++ Framework
by
Library Version: 2511 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 system::PathCharType, which in turn aliases std::filesystem::path::value_type.

Definition at line 156 of file path.inl.

Inheritance diagram for alib::system::Path:
alib::strings::TLocalString< PathCharType, 256 > alib::strings::TAString< PathCharType, lang::HeapAllocator > alib::strings::TString< PathCharType > alib::lang::AllocatorMember< lang::HeapAllocator >

Public Static Field Index:

static PathString tempDirEvaluatedOnce
static PathString varTempDirEvaluatedOnce

Public Static Method Index:

static int IsAbsolute (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)
int IsAbsolute () const
bool IsDirectory ()
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 PathCharType * Terminate () 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())
PathCharType * VBuffer () 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 PathCharType * Buffer () 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< PathCharType > Substring (integer regionStart, integer regionLength=MAX_LEN) const
integer WStringLength () const
Public Method Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
 AllocatorMember ()
AllocatorInterface< lang::HeapAllocatorAI () 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 PathCharType * buffer
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 SystemFolders::Temp. To change the default behavior of evaluation, this variable may be filled with a proper path before using enum SystemFolders::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.inl.

◆ 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 SystemFolders::VarTemp. To change the default behavior of evaluation, this variable may be filled with a proper path before using enum SystemFolders::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.inl.

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.inl.

◆ 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.inl.

◆ 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.inl.

◆ 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.inl.

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 DIRECTORY_SEPARATOR, one will be inserted first.

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

Definition at line 263 of file path.inl.

◆ 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 403 of file path.cpp.

◆ Change() [1/3]

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

Changes the directory. If the given path is relative (e.g., a name of a subdirectory or ".."), such path is added to the current Path. Otherwise, this objects' path string is replaced. 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, false otherwise.

Definition at line 417 of file path.cpp.

◆ 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 124 of file path.cpp.

◆ 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 242 of file path.inl.

◆ 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 440 of file path.cpp.

◆ 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.inl.

◆ 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 526 of file path.cpp.

◆ IsAbsolute() [1/2]

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

Invokes static overload of this method, passing this object.

Returns
The result of a call to IsAbsolute PathString&).

Definition at line 284 of file path.inl.

◆ IsAbsolute() [2/2]

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

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

Attention
This method must be invoked on "real path strings" only. Assembled paths which contain redundant slashes return a false result.
Parameters
pathThe relative or absolute path to check.
Returns
0 if path is relative. If absolute, the position of the first character that does not belong to the root symbol. For example, with windows OS, if "C:\XYZ" was given, 3 is returned. With other OSes "//" is searched.

Definition at line 328 of file path.inl.

◆ 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 464 of file path.cpp.

◆ 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 492 of file path.cpp.

◆ 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 288 of file path.inl.

◆ 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 300 of file path.inl.


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