ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
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 this AString derivate is bound to type definition system::PathCharType, which in turn aliases std::filesystem::path::value_type.

Definition at line 193 of file path.hpp.

#include <path.hpp>

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

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)
 
ALIB_API void AddModuleName (const PathString &extension)
 
ALIB_API bool Change (const PathString &path)
 
ALIB_API bool Change (SystemFolders special)
 
void Change (SystemFolders special, const PathString &fileName)
 
ALIB_API SystemErrors Create ()
 
ALIB_API SystemErrors Create (const PathString &path)
 
int IsAbsolute () const
 
ALIB_API bool IsDirectory ()
 
ALIB_API SystemErrors MakeReal ()
 
PathString Name () const
 
- Public Method Index: inherited from TLocalString< PathCharType, 256 >
constexpr TLocalString ()
 
 TLocalString (const TAppendable &src)
 
 TLocalString (const TLocalString &copy)
 
constexpr TLocalString (lang::HeapAllocator &pAllocator)
 
 TLocalString (TLocalString &&move) noexcept
 
TLocalStringoperator= (const TLocalString &copy)
 
TLocalStringoperator= (TLocalString &&move)
 
- Public Method Index: inherited from TAString< PathCharType, lang::HeapAllocator >
constexpr TAString ()
 Constructs an empty, nulled AString (does not allocate a buffer).
 
 TAString (const TAppendable &src)
 
 TAString (const TAString &copy)
 
constexpr TAString (lang::HeapAllocator &pAllocator)
 
 TAString (TAString &&move) noexcept
 
 ~TAString () noexcept
 Destructs an AString object. An internally allocated buffer will be deleted.
 
 operator TCharArray () const
 
 operator TCharArray () const
 
TAStringoperator= (const TAString &copy)
 
void dbgCheck () const
 
void DbgDisableBufferReplacementWarning ()
 
ALIB_API void SetBuffer (integer newCapacity)
 
ALIB_API void SetBuffer (PathCharType *extBuffer, integer extBufferSize, integer extLength=0, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
 
void EnsureRemainingCapacity (integer spaceNeeded)
 
ALIB_API void GrowBufferAtLeastBy (integer minimumGrowth)
 
integer Capacity () const
 
bool HasInternalBuffer () const
 
void SetNull ()
 Invokes SetBuffer(0).
 
constexpr const PathCharType * Terminate () const
 
PathCharType * VBuffer () const
 
void SetCharAt (integer idx, PathCharType c)
 
PathCharType & operator[] (integer idx)
 
void SetLength (integer newLength)
 
void DetectLength ()
 
TAStringShortenTo (integer newLength)
 
TAStringAppend (const TCharSrc *src, integer srcLength)
 
TAStringAppend (const PathCharType *src, integer srcLength)
 
TAStringAppend (const TString< PathCharType > &src, integer regionStart, integer regionLength=MAX_LEN)
 
TAStringAppend (const TAppendable &src)
 
TAString_ (const TString< PathCharType > &src, integer regionStart, integer regionLength=MAX_LEN)
 
TAString_ (const TAppendable &src)
 
TAStringNewLine ()
 
TAStringoperator<< (const TAppendable &src)
 
TAString_ ()
 
TAStringReset ()
 
TAStringReset (const TAppendable &src)
 
TAStringInsertAt (const TString< PathCharType > &src, integer pos)
 
TAStringInsertChars (PathCharType c, integer qty)
 
TAStringInsertChars (PathCharType c, integer qty, integer pos)
 
TAStringDelete (integer regionStart, integer regionLength=MAX_LEN)
 
TAStringDeleteStart (integer regionLength)
 
TAStringDeleteStart (const TString< PathCharType > &deleteIfMatch)
 
TAStringDeleteEnd (integer regionLength)
 
TAStringDeleteEnd (const TString< PathCharType > &deleteIfMatch)
 
ALIB_API TAStringTrim (const TCString< PathCharType > &trimChars=TT_CStringConstants< PathCharType >::DefaultWhitespaces())
 
ALIB_API integer TrimAt (integer idx, const TCString< PathCharType > &trimChars=TT_CStringConstants< PathCharType >::DefaultWhitespaces())
 
TAStringTrimStart (const TCString< PathCharType > &trimChars=TT_CStringConstants< PathCharType >::DefaultWhitespaces())
 
TAStringTrimEnd (const TCString< PathCharType > &trimChars=TT_CStringConstants< PathCharType >::DefaultWhitespaces())
 
Iterator begin ()
 
Iterator end ()
 
ALIB_WARNINGS_RESTORE ReverseIterator rbegin ()
 
ReverseIterator rend ()
 
TAStringReplaceSubstring (const TString< PathCharType > &src, integer regionStart, integer regionLength)
 
TAStringReplaceRegion (PathCharType c, integer regionStart, integer regionLength)
 
ALIB_API integer SearchAndReplace (PathCharType needle, PathCharType replacement, integer startIdx=0, integer endIdx=strings::MAX_LEN)
 
ALIB_API integer SearchAndReplace (const TString< PathCharType > &needle, const TString< PathCharType > &replacement, integer startIdx=0, integer maxReplacements=strings::MAX_LEN, lang::Case sensitivity=lang::Case::Sensitive, integer endIdx=strings::MAX_LEN)
 
TAStringToUpper (integer regionStart=0, integer regionLength=MAX_LEN)
 
TAStringToLower (integer regionStart=0, integer regionLength=MAX_LEN)
 
TAStringReverse (integer regionStart=0, integer regionLength=MAX_LEN)
 
ConstIterator begin () const
 
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE ConstIterator end () const
 
ALIB_WARNINGS_RESTORE ConstReverseIterator rbegin () const
 
ConstReverseIterator rend () const
 
- Public Method Index: inherited from TString< PathCharType >
constexpr TString () noexcept=default
 Defaulted default constructor.
 
constexpr TString (const PathCharType *pBuffer, integer pLength) noexcept
 
constexpr TString (const TCharArray &src)
 
constexpr TString (const TString &) noexcept=default
 Defaulted copy constructor.
 
 TString (ConstIterator &start, ConstIterator &end)
 
 TString (TAllocator &allocator, const TString< PathCharType > &copy)
 
constexpr TString (TString &&) noexcept=default
 Defaulted move constructor.
 
 operator TCharArray () const
 
 operator TCharArray () const
 
TStringoperator= (const TString &) noexcept=default
 
TStringoperator= (TString &&) noexcept=default
 
constexpr const PathCharType * Buffer () const
 
constexpr integer Length () const
 
integer WStringLength () const
 
constexpr bool IsNull () const
 
constexpr bool IsNotNull () const
 
constexpr bool IsEmpty () const
 
constexpr bool IsNotEmpty () const
 
TString< PathCharType > Substring (integer regionStart, integer regionLength=MAX_LEN) const
 
PathCharType CharAt (integer idx) const
 
PathCharType CharAtStart () const
 
PathCharType CharAtEnd () const
 
PathCharType operator[] (integer idx) const
 
std::size_t Hashcode () const
 
std::size_t HashcodeIgnoreCase () const
 
bool Equals (const TString< PathCharType > &rhs) const
 
int CompareTo (const TString< PathCharType > &rhs) const
 
int CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength=MAX_LEN) const
 
int CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength, integer regionStart, integer regionLength=MAX_LEN) const
 
bool ContainsAt (const TString &needle, integer pos) const
 
bool StartsWith (const TString &needle) const
 
bool EndsWith (const TString &needle) const
 
integer IndexOf (PathCharType needle, integer startIdx=0) const
 
integer IndexOf (PathCharType needle, integer regionStart, integer regionLength) const
 
integer IndexOf (const TString &needle, integer startIdx=0, integer endIdx=strings::MAX_LEN) const
 
integer IndexOfOrLength (PathCharType needle) const
 
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer IndexOfOrLength (PathCharType needle, integer startIdx) const
 
ALIB_WARNINGS_RESTORE integer LastIndexOf (PathCharType needle, integer startIndex=MAX_LEN) const
 
integer IndexOfAny (const TString &needles, integer startIdx=0) const
 
integer LastIndexOfAny (const TString &needles, integer startIdx=MAX_LEN) const
 
integer IndexOfFirstDifference (const TString &needle, lang::Case sensitivity=lang::Case::Sensitive, integer startIdx=0) const
 
integer IndexOfSegmentEnd (PathCharType opener, PathCharType closer, integer idx) const
 
integer CountChar (PathCharType needle, integer startPos=0) const
 
integer CountChar (PathCharType needle, PathCharType omit, integer startPos) const
 
integer Count (const TString &needle, integer startPos=0) const
 
integer Count (const TString &needle, const TString &omit, integer startPos=0) const
 
ALIB_API uint64_t ParseDecDigits (integer startIdx=0, integer *newIdx=nullptr) const
 
ALIB_API int64_t ParseInt (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
 
int64_t ParseInt (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
 
int64_t ParseInt (integer *newIdx) const
 
int64_t ParseInt (integer startIdx, integer *newIdx) const
 
ALIB_API 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 ParseDec (integer *newIdx) const
 
uint64_t ParseDec (integer startIdx, integer *newIdx) const
 
ALIB_API 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 ParseBin (integer *newIdx) const
 
uint64_t ParseBin (integer startIdx, integer *newIdx) const
 
ALIB_API uint64_t ParseHex (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
 
uint64_t ParseHex (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
 
uint64_t ParseHex (integer *newIdx) const
 
uint64_t ParseHex (integer startIdx, integer *newIdx) const
 
ALIB_API uint64_t ParseOct (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
 
uint64_t ParseOct (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
 
uint64_t ParseOct (integer *newIdx) const
 
uint64_t ParseOct (integer startIdx, integer *newIdx) const
 
ALIB_API double ParseFloat (integer startIdx=0, TNumberFormat< PathCharType > *numberFormat=nullptr, integer *newIdx=nullptr) const
 
double ParseFloat (TNumberFormat< PathCharType > *numberFormat, integer *newIdx=nullptr) const
 
double ParseFloat (integer *newIdx) const
 
double ParseFloat (integer startIdx, integer *newIdx) const
 
integer CopyTo (PathCharType *dest) const
 
void Allocate (TAllocator &allocator, const TString< PathCharType > &copy)
 
void Free (TAllocator &allocator)
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE ConstIterator end () const
 
ConstIterator cend () const
 
ALIB_WARNINGS_RESTORE ConstReverseIterator rbegin () const
 
ConstReverseIterator rend () const
 
ConstReverseIterator crbegin () const
 
ConstReverseIterator crend () const
 
bool AdjustRegion (integer &regionStart, integer &regionLength) const
 
- Public Method Index: inherited from AllocatorMember< lang::HeapAllocator >
 AllocatorMember ()=delete
 Deleted default constructor. (The allocator has to be given with construction)
 
 AllocatorMember (lang::HeapAllocator &pAllocator) noexcept
 
AllocatorInterface< lang::HeapAllocatorAI () const noexcept
 
lang::HeapAllocatorGetAllocator () const noexcept
 

Additional Inherited Members

- Public Type Index: inherited from TAString< PathCharType, lang::HeapAllocator >
using AllocatorType
 Exposes the allocator type specified by template parameter TAllocator.
 
using Iterator
 
using ReverseIterator
 Same as Iterator, but working from the end to the start of the string.
 
- Public Type Index: inherited from TString< PathCharType >
using CharType
 Expose template parameter TChar to the outer world.
 
using ConstIterator
 
using ConstReverseIterator
 
- Public Type Index: inherited from AllocatorMember< lang::HeapAllocator >
using AllocatorType
 Exposes the allocator type.
 
- Protected Type Index: inherited from TLocalString< PathCharType, 256 >
using base
 The base AString-type.
 
using sBase
 The base String-type.
 
- Protected Type Index: inherited from TAString< PathCharType, lang::HeapAllocator >
using allocBase
 The allocator type that TAllocator specifies.
 
using base
 The base string-type.
 
- Protected Field Index: inherited from TLocalString< PathCharType, 256 >
PathCharType localBuffer [TCapacity]
 
- Protected Field Index: inherited from TAString< PathCharType, lang::HeapAllocator >
integer capacity
 
bool dbgWarnWhenExternalBufferIsReplaced
 
integer debugLastAllocRequest
 
- Protected Field Index: inherited from TString< PathCharType >
const PathCharType * buffer
 
integer length
 
- Protected Field Index: inherited from AllocatorMember< lang::HeapAllocator >
lang::HeapAllocatorallocator
 A reference to the allocator.
 
- Protected Method Index: inherited from TAString< PathCharType, lang::HeapAllocator >
constexpr TAString (lang::HeapAllocator &pAllocator, PathCharType *extBuffer, integer extBufferSize)
 
constexpr TAString (PathCharType *extBuffer, integer extBufferSize)
 
- Protected Method Index: inherited from TString< PathCharType >
ALIB_API integer indexOfString (const TString &needle, integer startIdx, integer endIdx) const
 

Field Details:

◆ tempDirEvaluatedOnce

PathString tempDirEvaluatedOnce
static

Singleton containing the path for the use of enum value SystemFolders::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 207 of file path.hpp.

◆ varTempDirEvaluatedOnce

PathString varTempDirEvaluatedOnce
static

Singleton containing the path for the use of enum value SystemFolders::VarTemp". This is evaluated once with the first use of \b %SystemFolders::VarTemp. To change the default behavior of evaluation, this variable may be filled with a proper path before using enum \b %SystemFolders::VarTemp with this class. The one-time evaluated value is stored in the \ref alib::monomem::GLOBAL_ALLOCATOR "GLOBAL_ALLOCATOR" and access to this variable is consequently protected with \ref alib::monomem::GLOBAL_ALLOCATOR_LOCK "GLOBAL_ALLOCATOR_LOCK".

Definition at line 217 of file path.hpp.

Constructor(s) / Destructor Details:

◆ Path() [1/4]

Path ( )
inline

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

Definition at line 229 of file path.hpp.

◆ Path() [2/4]

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 236 of file path.hpp.

Here is the call graph for this function:

◆ Path() [3/4]

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 246 of file path.hpp.

Here is the call graph for this function:

◆ Path() [4/4]

Path ( const PathString & path)
inline

Constructs an object representing the given path.

Parameters
pathThe initial path.

Definition at line 256 of file path.hpp.

Method Details:

◆ Add()

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 319 of file path.hpp.

Here is the call graph for this function:

◆ AddModuleName()

void 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 319 of file path.cpp.

Here is the call graph for this function:

◆ Change() [1/3]

bool 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 334 of file path.cpp.

Here is the call graph for this function:

◆ Change() [2/3]

bool 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 105 of file path.cpp.

Here is the call graph for this function:

◆ Change() [3/3]

void 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 305 of file path.hpp.

Here is the call graph for this function:

◆ Create() [1/2]

ALIB_API SystemErrors Create ( )
inline

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

Returns
A value of enum type SystemErrors.

Definition at line 279 of file path.hpp.

Here is the call graph for this function:

◆ Create() [2/2]

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

Definition at line 423 of file path.cpp.

Here is the call graph for this function:

◆ IsAbsolute() [1/2]

int IsAbsolute ( ) const
inline

Calls invokes static overload of this method, passing this object.

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

Definition at line 347 of file path.hpp.

Here is the call graph for this function:

◆ IsAbsolute() [2/2]

static int 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 380 of file path.hpp.

Here is the call graph for this function:

◆ IsDirectory()

bool 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 360 of file path.cpp.

Here is the call graph for this function:

◆ MakeReal()

SystemErrors MakeReal ( )

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

Returns
SystemErrors::OK on success, otherwise an error code.

Definition at line 390 of file path.cpp.

Here is the call graph for this function:

◆ Name()

PathString Name ( ) const
inline

Gets the name portion of the path.

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

Definition at line 353 of file path.hpp.

Here is the call graph for this function:

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