ezEngine  Release 25.03
ezDataDirPath Class Reference

A reference to a file or folder inside a data directory. More...

#include <DataDirPath.h>

Public Member Functions

Constructor
 ezDataDirPath ()
 Default ctor, creates an invalid data directory path.
 
 ezDataDirPath (ezStringView sAbsPath, ezArrayPtr< ezString > dataDirRoots, ezUInt32 uiLastKnownDataDirIndex=0)
 Tries to create a new data directory path from an absolute path. Check IsValid afterwards to confirm this path is inside a data directory. More...
 
 ezDataDirPath (const ezStringBuilder &sAbsPath, ezArrayPtr< ezString > dataDirRoots, ezUInt32 uiLastKnownDataDirIndex=0)
 Overload for ezStringBuilder to fix ambiguity between implicit conversions.
 
 ezDataDirPath (ezString &&sAbsPath, ezArrayPtr< ezString > dataDirRoots, ezUInt32 uiLastKnownDataDirIndex=0)
 Move constructor overload for the absolute path.
 
Misc
const ezStringGetAbsolutePath () const
 Returns the same path this instance was created with. Calling this function is always valid.
 
bool IsValid () const
 Returns whether this path is inside a data directory. If not, none of the Get* functions except for GetAbsolutePath are allowed to be called.
 
void Clear ()
 Same as the default constructor. Creates an empty, invalid path.
 
Operators
 operator ezStringView () const
 
bool operator== (ezStringView rhs) const
 
bool operator!= (ezStringView rhs) const
 
Data directory access. Only allowed to be called if IsValid() is true.
ezStringView GetDataDirParentRelativePath () const
 Returns a relative path including the data directory the path belongs to, e.g. "Testing Chambers/Objects/Barrel.ezPrefab".
 
ezStringView GetDataDirRelativePath () const
 Returns a path relative to the data directory the path belongs to, e.g. "Objects/Barrel.ezPrefab".
 
ezStringView GetDataDir () const
 Returns absolute path to the data directory this path belongs to, e.g. "C:/ezEngine/Data/Samples/Testing Chambers".
 
ezUInt8 GetDataDirIndex () const
 Returns the index of the data directory the path belongs to.
 
Data directory update
bool UpdateDataDirInfos (ezArrayPtr< ezString > dataDirRoots, ezUInt32 uiLastKnownDataDirIndex=0) const
 If a ezDataDirPath is de-serialized, it might not be correct anymore and its data directory reference must be updated. It could potentially no longer be part of any data directory at all and become invalid so after calling this function, IsValid will match the return value of this function. On failure, the invalid data directory paths should then be destroyed. More...
 
Serialization
ezStreamWriterWrite (ezStreamWriter &inout_stream) const
 
ezStreamReaderRead (ezStreamReader &inout_stream)
 

Detailed Description

A reference to a file or folder inside a data directory.

Allows quick access to various sub-parts of the path as well as the data dir index. To construct a ezDataDirPath, the list of absolute data directory root directories must be supplied in order to determine whether the path is inside a data directory and in which. After calling the constructor, IsValid() should be called to determine if the file is inside a data directory. The various sub-parts look like this with "Testing Chambers" being the data directory in this example:

GetAbsolutePath() == "C:/ezEngine/Data/Samples/Testing Chambers/Objects/Barrel.ezPrefab" GetDataDir() == "C:/ezEngine/Data/Samples/Testing Chambers" GetDataDirParentRelativePath() == "Testing Chambers/Objects/Barrel.ezPrefab" GetDataDirRelativePath() == "Objects/Barrel.ezPrefab"

Constructor & Destructor Documentation

◆ ezDataDirPath()

ezDataDirPath::ezDataDirPath ( ezStringView  sAbsPath,
ezArrayPtr< ezString dataDirRoots,
ezUInt32  uiLastKnownDataDirIndex = 0 
)
inline

Tries to create a new data directory path from an absolute path. Check IsValid afterwards to confirm this path is inside a data directory.

Parameters
sAbsPathAbsolute path to the file or folder. Must be normalized. Must not end with "/".
dataDirRootsA list of normalized absolute paths to the roots of the data directories. These must not end in a "/" character.
uiLastKnownDataDirIndexA hint to accelerate the search if the data directory index is known.

Member Function Documentation

◆ UpdateDataDirInfos()

bool ezDataDirPath::UpdateDataDirInfos ( ezArrayPtr< ezString dataDirRoots,
ezUInt32  uiLastKnownDataDirIndex = 0 
) const

If a ezDataDirPath is de-serialized, it might not be correct anymore and its data directory reference must be updated. It could potentially no longer be part of any data directory at all and become invalid so after calling this function, IsValid will match the return value of this function. On failure, the invalid data directory paths should then be destroyed.

Parameters
dataDirRootsA list of normalized absolute paths to the roots of the data directories. These must not end in a "/" character.
uiLastKnownDataDirIndexA hint to accelerate the search if nothing has changed.
Returns
Returns whether the data directory path is valid, i.e. it is still under one of the dataDirRoots.

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