utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::SystemIO Class Referenceabstract

The SystemIO class is an abstract base class for managing file assets. More...

#include <headers/utility/system_io/system_io.hpp>

Inheritance diagram for utility::SystemIO:

Public Member Functions

virtual ~SystemIO ()=default
 Default destructor for SystemIO.
 
virtual bool loadDirectory (const std::string &directory)=0
 Loads assets from a directory.
 
bool loadDirectory (const std::filesystem::path &directory)
 Loads assets from a directory.
 
virtual std::shared_ptr< utility::Fileadd (const std::string &path)=0
 Adds an asset to the manager.
 
std::shared_ptr< utility::Fileadd (const std::filesystem::path &path)
 Adds an asset to the manager.
 
virtual void remove (const std::string &path, bool save=true)=0
 Removes an asset from the manager.
 
void remove (const std::filesystem::path &path, bool save=true)
 Removes an asset from the manager.
 
virtual bool save (const std::string &path, const std::string &newPath="")=0
 Saves an asset to the disk.
 
bool save (const std::filesystem::path &path, const std::filesystem::path &newPath)
 Saves an asset to the disk.
 
bool save (const std::filesystem::path &path)
 Saves an asset to its original path.
 
bool exists (const std::string &path) const
 Checks if an asset exists in the manager.
 
bool exists (const std::filesystem::path &path) const
 Checks if an asset exists in the manager.
 
std::shared_ptr< utility::Fileopen (const std::string &path) const
 Opens an asset from the manager.
 
std::shared_ptr< utility::Fileopen (const std::filesystem::path &path) const
 Opens an asset from the manager.
 

Protected Attributes

std::map< std::string, std::shared_ptr< utility::File > > _assets
 Map of loaded assets.
 

Detailed Description

The SystemIO class is an abstract base class for managing file assets.

Definition at line 48 of file system_io.hpp.

Member Function Documentation

◆ add() [1/2]

std::shared_ptr< utility::File > utility::SystemIO::add ( const std::filesystem::path &  path)
inline

Adds an asset to the manager.

Parameters
pathThe filesystem path to the asset.
Returns
A shared pointer to the File object.

Definition at line 96 of file system_io.hpp.

Here is the call graph for this function:

◆ add() [2/2]

virtual std::shared_ptr< utility::File > utility::SystemIO::add ( const std::string &  path)
pure virtual

Adds an asset to the manager.

Parameters
pathThe path to the asset.
Returns
A shared pointer to the File object.

This method is pure virtual and must be implemented by derived classes. This method is responsible for loading the asset from the specified path by reading the file content and storing it in the _assets map.

Implemented in utility::DefaultSystemIO, and utility::DefaultSystemIO.

Here is the caller graph for this function:

◆ exists() [1/2]

bool utility::SystemIO::exists ( const std::filesystem::path &  path) const
inline

Checks if an asset exists in the manager.

Parameters
pathThe filesystem path to the asset.
Returns
True if the asset exists, false otherwise.

Definition at line 177 of file system_io.hpp.

Here is the call graph for this function:

◆ exists() [2/2]

bool utility::SystemIO::exists ( const std::string &  path) const

Checks if an asset exists in the manager.

Parameters
pathThe path to the asset.
Returns
True if the asset exists, false otherwise.

This method checks if the asset is present in the _assets map.

Definition at line 33 of file system_io.cpp.

Here is the caller graph for this function:

◆ loadDirectory() [1/2]

bool utility::SystemIO::loadDirectory ( const std::filesystem::path &  directory)
inline

Loads assets from a directory.

Parameters
directoryThe filesystem path to the directory containing assets.
Returns
True if the assets were loaded successfully, false otherwise.

Definition at line 74 of file system_io.hpp.

Here is the call graph for this function:

◆ loadDirectory() [2/2]

virtual bool utility::SystemIO::loadDirectory ( const std::string &  directory)
pure virtual

Loads assets from a directory.

Parameters
directoryThe path to the directory containing the assets.
Returns
True if the assets were loaded successfully, false otherwise.

This method is pure virtual and must be implemented by derived classes. It is responsible for loading all assets from the specified directory by reading the file content and storing it in the _assets map.

Implemented in utility::DefaultSystemIO, and utility::DefaultSystemIO.

Here is the caller graph for this function:

◆ open() [1/2]

std::shared_ptr< utility::File > utility::SystemIO::open ( const std::filesystem::path &  path) const
inline

Opens an asset from the manager.

Parameters
pathThe filesystem path to the asset.
Returns
A shared pointer to the File object.

Definition at line 198 of file system_io.hpp.

Here is the call graph for this function:

◆ open() [2/2]

std::shared_ptr< utility::File > utility::SystemIO::open ( const std::string &  path) const

Opens an asset from the manager.

Parameters
pathThe path to the asset.
Returns
A shared pointer to the File object.

This method retrieves the asset from the _assets map. If the asset does not exist, it returns a nullptr.

Definition at line 39 of file system_io.cpp.

Here is the caller graph for this function:

◆ remove() [1/2]

void utility::SystemIO::remove ( const std::filesystem::path &  path,
bool  save = true 
)
inline

Removes an asset from the manager.

Parameters
pathThe filesystem path to the asset.
saveWhether to save the asset before removing it.

Definition at line 121 of file system_io.hpp.

Here is the call graph for this function:

◆ remove() [2/2]

virtual void utility::SystemIO::remove ( const std::string &  path,
bool  save = true 
)
pure virtual

Removes an asset from the manager.

Parameters
pathThe path to the asset.
saveWhether to save the asset before removing it (default is true).

This method removes the asset from the _assets map. When removing an asset, the asset file will not be deleted from the disk. When removing an asset, its content is updated on the disk if save is true. If save is false, the asset will be removed from the _assets map without saving its content on the disk. Using a deleted asset will result in undefined behavior.

Implemented in utility::DefaultSystemIO, and utility::DefaultSystemIO.

Here is the caller graph for this function:

◆ save() [1/3]

bool utility::SystemIO::save ( const std::filesystem::path &  path)
inline

Saves an asset to its original path.

Parameters
pathThe filesystem path to the managed asset.
Returns
True if the asset was saved successfully, false otherwise.

Definition at line 158 of file system_io.hpp.

Here is the call graph for this function:

◆ save() [2/3]

bool utility::SystemIO::save ( const std::filesystem::path &  path,
const std::filesystem::path &  newPath 
)
inline

Saves an asset to the disk.

Parameters
pathThe filesystem path to the managed asset.
newPathThe target filesystem path where the asset is written.
Returns
True if the asset was saved successfully, false otherwise.

Definition at line 147 of file system_io.hpp.

Here is the call graph for this function:

◆ save() [3/3]

virtual bool utility::SystemIO::save ( const std::string &  path,
const std::string &  newPath = "" 
)
pure virtual

Saves an asset to the disk.

Parameters
pathThe path to the asset.
newPathThe new path to save the asset to (optional).
Returns
True if the asset was saved successfully, false otherwise.

This method is pure virtual and must be implemented by derived classes. It is responsible for saving the content of the asset to the specified path. If newPath is provided, it will save the asset to that path and will not update the original path. If newPath is not provided, it will save the asset to the original path.

Implemented in utility::DefaultSystemIO, and utility::DefaultSystemIO.

Here is the caller graph for this function:

Member Data Documentation

◆ _assets

std::map<std::string, std::shared_ptr<utility::File> > utility::SystemIO::_assets
protected

Map of loaded assets.

Key: asset path. Value: shared pointer to the corresponding File.

Definition at line 210 of file system_io.hpp.


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