Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::Path Class Referencefinal

General path representation. Does not check whether the target actually exists (e.g., on a filesystem). To check target existence, use Filesystem. More...

#include <Path.h>

Public Member Functions

 Path ()
 Creates empty path.
 
 Path (std::string path)
 
 Path (std::string_view path)
 
 Path (TSpanView< char > path)
 
 Path (const char *path)
 
 Path (std::filesystem::path path)
 
bool isRelative () const
 
bool isAbsolute () const
 
bool isEmpty () const
 
void clear ()
 
Path append (const Path &other) const
 
Path append (std::string_view pathStr) const
 
Path toAbsolute () const
 
std::string toString () const
 Get a string representation of this path in generic format.
 
std::string toAbsoluteString () const
 
std::string toNativeString () const
 Get a string representation of this path in native format.
 
std::size_t toNativeString (TSpan< char > out_buffer, std::size_t *out_numTotalChars=nullptr, bool isNullTerminated=true) const
 Similar to toNativeString(), except the buffer is provided. This variant guarantees no dynamic allocation takes place.
 
std::filesystem::path toStdPath () const
 Get a standard path representation of this path.
 
Path removeLeadingSeparator () const
 
Path removeTrailingSeparator () const
 
std::string getFilename () const
 Returns the filename if present.
 
std::string getExtension () const
 Returns filename extension if present. The extension string will start with a period character ".". If the path contains no extension, then an empty string is returned.
 
Path getLeadingElement () const
 
Path getTrailingElement (bool ignoreTrailingSeparator=true) const
 
Path getParent () const
 
Path replaceExtension (std::string_view replacement) const
 Changes filename extension in the path, if any. The behavior is the same as std::filesystem::path::replace_extension(1).
 
Path removeExtension () const
 Removes filename extension in the path, if any.
 
Path operator/ (const Path &other) const
 
Path operator/ (std::string_view pathStr) const
 
bool operator== (const Path &other) const
 

Detailed Description

General path representation. Does not check whether the target actually exists (e.g., on a filesystem). To check target existence, use Filesystem.

Constructor & Destructor Documentation

◆ Path() [1/6]

ph::Path::Path ( )

Creates empty path.

◆ Path() [2/6]

ph::Path::Path ( std::string path)
explicit

Constructs a path from some string representation of the path. The string can be either a relative or absolute path, or even a path fragment. The input format of path should be in a general, "mostly" OS neutral form [1] which often referred as "generic format" in many libraries.

References: [1] https://www.boost.org/doc/libs/1_83_0/libs/filesystem/doc/reference.html

◆ Path() [3/6]

ph::Path::Path ( std::string_view path)
explicit

A std::string_view variant of Path(std::string).

◆ Path() [4/6]

ph::Path::Path ( TSpanView< char > path)
explicit

A span variant of Path(std::string).

◆ Path() [5/6]

ph::Path::Path ( const char * path)
explicit

Similar to Path(std::string), except the string is a null-terminated character sequence pointed to by path.

◆ Path() [6/6]

ph::Path::Path ( std::filesystem::path path)
explicit

Member Function Documentation

◆ append() [1/2]

Path ph::Path::append ( const Path & other) const

Appending one path to another. System specific directory separators are added in between two path objects.

◆ append() [2/2]

Path ph::Path::append ( std::string_view pathStr) const

◆ clear()

void ph::Path::clear ( )
inline

◆ getExtension()

std::string ph::Path::getExtension ( ) const

Returns filename extension if present. The extension string will start with a period character ".". If the path contains no extension, then an empty string is returned.

◆ getFilename()

std::string ph::Path::getFilename ( ) const

Returns the filename if present.

Returns
Filename including the extension part (if any). Empty if not present.

◆ getLeadingElement()

Path ph::Path::getLeadingElement ( ) const

If the path starts with a root directory specifier, it will be returned. Example: for the path "/abc/def/", "/" will be returned.

◆ getParent()

Path ph::Path::getParent ( ) const

Get the parent directory of this path, e.g., the parent of "./aaa/bbb.ext" would be "./aaa".

◆ getTrailingElement()

Path ph::Path::getTrailingElement ( bool ignoreTrailingSeparator = true) const

If the path ends with a path separator, the element returned will be the name before the separator. For example, "C:\\abc\\def\\ghi\\" will return "ghi" as the trailing element. If this is not desired and an empty path "" is expected instread, set @p ignoreTrailingSeparator to <tt>false</tt>. Filename with its extension is considered a single element, i.e., "./aaa/bbb.ext" would return "bbb.ext".

◆ isAbsolute()

bool ph::Path::isAbsolute ( ) const
inline

◆ isEmpty()

bool ph::Path::isEmpty ( ) const
inline

◆ isRelative()

bool ph::Path::isRelative ( ) const
inline

◆ operator/() [1/2]

Path ph::Path::operator/ ( const Path & other) const

◆ operator/() [2/2]

Path ph::Path::operator/ ( std::string_view pathStr) const

◆ operator==()

bool ph::Path::operator== ( const Path & other) const

◆ removeExtension()

Path ph::Path::removeExtension ( ) const

Removes filename extension in the path, if any.

◆ removeLeadingSeparator()

Path ph::Path::removeLeadingSeparator ( ) const

◆ removeTrailingSeparator()

Path ph::Path::removeTrailingSeparator ( ) const

◆ replaceExtension()

Path ph::Path::replaceExtension ( std::string_view replacement) const

Changes filename extension in the path, if any. The behavior is the same as std::filesystem::path::replace_extension(1).

◆ toAbsolute()

Path ph::Path::toAbsolute ( ) const

◆ toAbsoluteString()

std::string ph::Path::toAbsoluteString ( ) const

◆ toNativeString() [1/2]

std::string ph::Path::toNativeString ( ) const

Get a string representation of this path in native format.

Returns
A string that can be passed to the native OS for identifying a target.

◆ toNativeString() [2/2]

std::size_t ph::Path::toNativeString ( TSpan< char > out_buffer,
std::size_t * out_numTotalChars = nullptr,
bool isNullTerminated = true ) const

Similar to toNativeString(), except the buffer is provided. This variant guarantees no dynamic allocation takes place.

Parameters
[out]out_bufferThe buffer to store the string.
[out]out_numTotalCharsTotal number of characters in the string representation of this path (including the null terminator). If isNullTerminated is false, the number will not include the null terminator.
isNullTerminatedWhether the resultant string should be null-terminated. If true, null terminator will present even if the string is not fully copied.
Returns
Number of copied characters (including the null terminator).

◆ toStdPath()

std::filesystem::path ph::Path::toStdPath ( ) const
inline

Get a standard path representation of this path.

◆ toString()

std::string ph::Path::toString ( ) const

Get a string representation of this path in generic format.


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