CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::FilePath Class Reference

Path to file or directory. More...

#include <CeresEngine/Foundation/IO/FilePath.hpp>

Public Member Functions

 FilePath ()
 Creates a new empty FilePath.
 
 FilePath (StringView path)
 Creates a new FilePath from a string view that represents a path.
 
 FilePath (String &&path)
 Creates a new FilePath by moving the contents of a path string.
 
 FilePath (const char *path)
 Creates a new FilePath from a const char* string.
 
 FilePath (const FilePath &)=default
 
 FilePath (FilePath &&)=default
 
FilePathoperator= (const FilePath &)=default
 
FilePathoperator= (FilePath &&)=default
 
virtual ~FilePath ()
 Destroys the FilePath instance.
 
StringView getPath () const
 Get path as string.
 
String toNative () const
 Gets the native path as string.
 
bool isEmpty () const
 Checks if path is empty.
 
StringView getFullPath () const
 Gets full path.
 
StringView getFileName () const
 Gets file name from the path.
 
StringView getBaseName () const
 Gets the path base name.
 
StringView getExtension () const
 Gets the path file extension.
 
StringView getParent () const
 Gets the directory path.
 
FilePath getParentPath () const
 Gets the directory path.
 
StringView getDriveLetter () const
 Gets drive letter on a Windows-style path.
 
bool isAbsolute () const
 Checks if path is an absolute path.
 
bool isRelative () const
 Check if path is a relative.
 
FilePath resolve (const FilePath &path) const
 Resolves a relative path from path.
 
FilePath normalize () const
 Gets the normalized path (removed '.
 
FilePath relativize (const FilePath &base) const
 Relativizes this path to be a relative path from base.
 
FilePathmakeRelative ()
 
FilePath toRelative () const &
 
FilePath && toRelative () &&
 
FilePathmakeAbsolute ()
 
FilePath toAbsolute () const &
 
FilePath && toAbsolute () &&
 
FilePath operator/ (const FilePath &other) const
 
FilePathoperator/= (const FilePath &other)
 
const StringtoString () const
 The underlying path as a string in the unified format.
 
std::filesystem::path toStdPath () const
 

Protected Member Functions

void setPath (StringView path)
 Sets a new path. Converts the path into the internal format.
 
void setPath (String &&path)
 Sets a new path. Converts the path into the internal format.
 

Private Attributes

String mPath
 The underlying path as a string in the unified format.
 

Detailed Description

Path to file or directory.

This class stores a path to a file or directory and provides common operations like getting the file name or extension.

FilePath uses a unified format for storing paths that can be used consistently on every platform, using only '/' as a separator. When a FilePath is constructed from a string, the path is translated into the unified format and can then be used in a cross-platform way throughout an application. All operations on FilePath also return paths in the same unified format. To obtain a path in native platform format, use toNative().

All operations are completely string-based and don't use any system information. Therefore, paths are treated purely syntactically and do not imply that for example a file does really exist.

Constructor & Destructor Documentation

◆ FilePath() [1/6]

CeresEngine::FilePath::FilePath ( )

Creates a new empty FilePath.

◆ FilePath() [2/6]

CeresEngine::FilePath::FilePath ( StringView  path)

Creates a new FilePath from a string view that represents a path.

◆ FilePath() [3/6]

CeresEngine::FilePath::FilePath ( String &&  path)

Creates a new FilePath by moving the contents of a path string.

◆ FilePath() [4/6]

CeresEngine::FilePath::FilePath ( const char path)

Creates a new FilePath from a const char* string.

◆ FilePath() [5/6]

CeresEngine::FilePath::FilePath ( const FilePath )
default

◆ FilePath() [6/6]

CeresEngine::FilePath::FilePath ( FilePath &&  )
default

◆ ~FilePath()

virtual CeresEngine::FilePath::~FilePath ( )
virtual

Destroys the FilePath instance.

Member Function Documentation

◆ getBaseName()

StringView CeresEngine::FilePath::getBaseName ( ) const

Gets the path base name.

Note
This function returns "something" for both "/path/to/something.ex" and "/path/to/something.ex/".
Returns
The base name of the stored path (without extension).

◆ getDriveLetter()

StringView CeresEngine::FilePath::getDriveLetter ( ) const

Gets drive letter on a Windows-style path.

Note
If there is no drive letter (Linux, Mac), an empty string is returned.
Returns
The drive letter of the path on Windows (e.g., "C").

◆ getExtension()

StringView CeresEngine::FilePath::getExtension ( ) const

Gets the path file extension.

Note
This function returns ".ex" for both "/path/to/something.ex" and "/path/to/something.ex/". If the path has no extension, an empty string is returned.
Returns
The extension of the stored path.

◆ getFileName()

StringView CeresEngine::FilePath::getFileName ( ) const

Gets file name from the path.

Note
This function returns "something.ex" for both "/path/to/something.ex" and "/path/to/something.ex/".
Returns
The file name of the stored path (with extension).

◆ getFullPath()

StringView CeresEngine::FilePath::getFullPath ( ) const

Gets full path.

Note
If you want trailing separators to remain in the string, use getPath().
Returns
The full path in unified format, but without a trailing separator

◆ getParent()

StringView CeresEngine::FilePath::getParent ( ) const

Gets the directory path.

Note
This function returns "/path/to/" as directory path for both "/path/to/directory" and "/path/to/directory/".
Returns
The path to the directory, with trailing any slashes.

◆ getParentPath()

FilePath CeresEngine::FilePath::getParentPath ( ) const
inline

Gets the directory path.

Note
This function returns "/path/to/" as directory path for both "/path/to/directory" and "/path/to/directory/".
Returns
The path to the directory, with trailing any slashes.

◆ getPath()

StringView CeresEngine::FilePath::getPath ( ) const
inline

Get path as string.

Returns
File path (unified format)
Note
The path will be returned in unified format, but otherwise unchanged (e.g., trailing separators are preserved). To get the path without trailing separators, use getFullPath().

◆ isAbsolute()

bool CeresEngine::FilePath::isAbsolute ( ) const

Checks if path is an absolute path.

Returns
true if path is absolute, else false.

◆ isEmpty()

bool CeresEngine::FilePath::isEmpty ( ) const

Checks if path is empty.

Returns
true if path is empty, else false.

◆ isRelative()

bool CeresEngine::FilePath::isRelative ( ) const

Check if path is a relative.

Returns
true if path is relative, else false.

◆ makeAbsolute()

FilePath & CeresEngine::FilePath::makeAbsolute ( )

◆ makeRelative()

FilePath & CeresEngine::FilePath::makeRelative ( )

◆ normalize()

FilePath CeresEngine::FilePath::normalize ( ) const

Gets the normalized path (removed '.

' and '..' entries if possible).

Note
This function resolves occurrences of '.' and '..', taking into account the root path, e.g.:
  • 'a/b/../c' -> 'a/c'
  • '../../a' -> '../../a'
  • 'a/../../b' -> '../b'
  • '/a/../b/' - '/b'
  • etc.
Returns
The normalized path.

◆ operator/()

FilePath CeresEngine::FilePath::operator/ ( const FilePath other) const

◆ operator/=()

FilePath & CeresEngine::FilePath::operator/= ( const FilePath other)

◆ operator=() [1/2]

FilePath & CeresEngine::FilePath::operator= ( const FilePath )
default

◆ operator=() [2/2]

FilePath & CeresEngine::FilePath::operator= ( FilePath &&  )
default

◆ relativize()

FilePath CeresEngine::FilePath::relativize ( const FilePath base) const

Relativizes this path to be a relative path from base.

◆ resolve()

FilePath CeresEngine::FilePath::resolve ( const FilePath path) const

Resolves a relative path from path.

Note
This function applies the specified path the given path to the current path.
Parameters
pathTh path to be resolved.
Returns
The resolved path.

◆ setPath() [1/2]

void CeresEngine::FilePath::setPath ( String &&  path)
protected

Sets a new path. Converts the path into the internal format.

◆ setPath() [2/2]

void CeresEngine::FilePath::setPath ( StringView  path)
protected

Sets a new path. Converts the path into the internal format.

◆ toAbsolute() [1/2]

FilePath && CeresEngine::FilePath::toAbsolute ( ) &&
inline

◆ toAbsolute() [2/2]

FilePath CeresEngine::FilePath::toAbsolute ( ) const &
inline

◆ toNative()

String CeresEngine::FilePath::toNative ( ) const

Gets the native path as string.

Note
The path will be returned in native format, but otherwise unchanged (e.g., trailing separators are preserved).
Returns
The file path in the native format.

◆ toRelative() [1/2]

FilePath && CeresEngine::FilePath::toRelative ( ) &&
inline

◆ toRelative() [2/2]

FilePath CeresEngine::FilePath::toRelative ( ) const &
inline

◆ toStdPath()

std::filesystem::path CeresEngine::FilePath::toStdPath ( ) const

◆ toString()

const String & CeresEngine::FilePath::toString ( ) const
inline

The underlying path as a string in the unified format.

Member Data Documentation

◆ mPath

String CeresEngine::FilePath::mPath
private

The underlying path as a string in the unified format.


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