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::DefaultSystemIO Class Reference

The DefaultSystemIO class is a concrete implementation of the SystemIO interface that loads assets from the file system. More...

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

Inheritance diagram for utility::DefaultSystemIO:
Collaboration diagram for utility::DefaultSystemIO:

Public Member Functions

 DefaultSystemIO ()
 Constructs a DefaultSystemIO.
 
 ~DefaultSystemIO () override
 Default destructor for DefaultSystemIO.
 
bool loadDirectory (const std::string &directory) override
 Loads assets from a directory.
 
std::shared_ptr< utility::Fileadd (const std::string &path) override
 Adds an asset to the manager by loading it from the file system.
 
void remove (const std::string &path, bool save=true) override
 Removes an asset from the manager.
 
bool save (const std::string &path, const std::string &newPath="") override
 Saves an asset to the file system.
 
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 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 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.
 
- Public Member Functions inherited from utility::SystemIO
virtual ~SystemIO ()=default
 Default destructor for SystemIO.
 
bool loadDirectory (const std::filesystem::path &directory)
 Loads assets from a directory.
 
std::shared_ptr< utility::Fileadd (const std::filesystem::path &path)
 Adds an asset to the manager.
 
void remove (const std::filesystem::path &path, bool save=true)
 Removes an asset from the manager.
 
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 Member Functions

utility::logging::LoggergetLogger (void)
 Get the internal logger.
 
utility::logging::LoggergetLogger (void) const
 Get the internal logger.
 

Additional Inherited Members

- Protected Attributes inherited from utility::SystemIO
std::map< std::string, std::shared_ptr< utility::File > > _assets
 Map of loaded assets.
 

Detailed Description

The DefaultSystemIO class is a concrete implementation of the SystemIO interface that loads assets from the file system.

Logging is kept private behind an opaque logger to avoid leaking logging headers into the public API.

Definition at line 49 of file default_system_io.hpp.

Constructor & Destructor Documentation

◆ DefaultSystemIO()

utility::DefaultSystemIO::DefaultSystemIO ( )

Constructs a DefaultSystemIO.

Definition at line 38 of file default_system_io.cpp.

Member Function Documentation

◆ add() [1/3]

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.

◆ add() [2/3]

std::shared_ptr< utility::File > utility::DefaultSystemIO::add ( const std::string &  path)
overridevirtual

Adds an asset to the manager by loading it from the file system.

Parameters
pathThe path to the asset file.
Returns
A shared pointer to the loaded File, or nullptr if loading failed.

Implements utility::SystemIO.

Definition at line 89 of file default_system_io.cpp.

◆ add() [3/3]

virtual std::shared_ptr< utility::File > utility::SystemIO::add ( const std::string &  path)
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.

Implements utility::SystemIO.

◆ getLogger() [1/2]

utility::logging::Logger & utility::DefaultSystemIO::getLogger ( void  )
protected

Get the internal logger.

Returns
Reference to the internal Logger instance.

Definition at line 46 of file default_system_io.cpp.

◆ getLogger() [2/2]

utility::logging::Logger & utility::DefaultSystemIO::getLogger ( void  ) const
protected

Get the internal logger.

Returns
Reference to the internal Logger instance.

Definition at line 51 of file default_system_io.cpp.

◆ loadDirectory() [1/3]

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.

◆ loadDirectory() [2/3]

bool utility::DefaultSystemIO::loadDirectory ( const std::string &  directory)
overridevirtual

Loads assets from a directory.

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

Implements utility::SystemIO.

Definition at line 56 of file default_system_io.cpp.

◆ loadDirectory() [3/3]

virtual bool utility::SystemIO::loadDirectory ( const std::string &  directory)
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.

Implements utility::SystemIO.

◆ remove() [1/3]

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.

◆ remove() [2/3]

void utility::DefaultSystemIO::remove ( const std::string &  path,
bool  save = true 
)
overridevirtual

Removes an asset from the manager.

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

Implements utility::SystemIO.

Definition at line 131 of file default_system_io.cpp.

◆ remove() [3/3]

virtual void utility::SystemIO::remove ( const std::string &  path,
bool  save = true 
)
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.

Implements utility::SystemIO.

◆ save() [1/4]

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.

◆ save() [2/4]

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.

◆ save() [3/4]

bool utility::DefaultSystemIO::save ( const std::string &  path,
const std::string &  newPath = "" 
)
overridevirtual

Saves an asset to the file system.

Parameters
pathThe path to the asset to save.
newPathAn optional new path to save the asset to. If not provided, the asset will be saved to its original path.
Returns
True if the asset was saved successfully, false otherwise.

Implements utility::SystemIO.

Definition at line 145 of file default_system_io.cpp.

◆ save() [4/4]

virtual bool utility::SystemIO::save ( const std::string &  path,
const std::string &  newPath = "" 
)
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.

Implements utility::SystemIO.


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