Antkeeper  0.0.1
Public Member Functions | List of all members
resource_manager Class Reference

Manages the loading, caching, and saving of resources. More...

#include <resource-manager.hpp>

Public Member Functions

 resource_manager ()
 Constructs a resource manager. More...
 
 ~resource_manager ()
 Destructs a resource manager. More...
 
bool mount (const std::filesystem::path &path)
 Adds a directory or archive to the search path. More...
 
bool unmount (const std::filesystem::path &path)
 Removes a directory or archive from the search path. More...
 
template<class T >
std::shared_ptr< T > load (const std::filesystem::path &path)
 Loads and caches a resource. More...
 
template<class T >
bool save (const T &resource, const std::filesystem::path &path) const
 Saves a resource to a file. More...
 
bool set_write_path (const std::filesystem::path &path)
 Sets the path to a directory or archive where files can be written. More...
 
const std::filesystem::path & get_write_path () const noexcept
 Returns the path to the directory or archive to which files are written. More...
 

Detailed Description

Manages the loading, caching, and saving of resources.

Definition at line 37 of file resource-manager.hpp.

Constructor & Destructor Documentation

◆ resource_manager()

resource_manager::resource_manager ( )

Constructs a resource manager.

Exceptions
std::runtime_errorFailed to initialize PhysicsFS.

Definition at line 27 of file resource-manager.cpp.

◆ ~resource_manager()

resource_manager::~resource_manager ( )

Destructs a resource manager.

Definition at line 58 of file resource-manager.cpp.

Member Function Documentation

◆ get_write_path()

const std::filesystem::path& resource_manager::get_write_path ( ) const
inlinenoexcept

Returns the path to the directory or archive to which files are written.

Definition at line 107 of file resource-manager.hpp.

◆ load()

template<class T >
std::shared_ptr< T > resource_manager::load ( const std::filesystem::path &  path)

Loads and caches a resource.

If the resource has already been loaded the cached resource will be returned.

Template Parameters
TResource type.
Parameters
pathPath to the resource to load.
Returns
Pointer to the loaded resource, or nullptr if the resource could not be loaded.

Definition at line 145 of file resource-manager.hpp.

◆ mount()

bool resource_manager::mount ( const std::filesystem::path &  path)

Adds a directory or archive to the search path.

Parameters
pathPath to the directory or archive to mount.
Returns
true if the directory or archive was successfully mounted, false otherwise.

Definition at line 72 of file resource-manager.cpp.

◆ save()

template<class T >
bool resource_manager::save ( const T &  resource,
const std::filesystem::path &  path 
) const

Saves a resource to a file.

Template Parameters
TResource type.
Parameters
resourceResource to save.
pathPath to where the resource file should be written.
Returns
true if the resource was successfully saved, false otherwise.

Definition at line 179 of file resource-manager.hpp.

◆ set_write_path()

bool resource_manager::set_write_path ( const std::filesystem::path &  path)

Sets the path to a directory or archive where files can be written.

Parameters
pathPath to the directory or archive to which files should be written.
Returns
true if the write path was set successfully, false otherwise.

Definition at line 106 of file resource-manager.cpp.

◆ unmount()

bool resource_manager::unmount ( const std::filesystem::path &  path)

Removes a directory or archive from the search path.

Parameters
pathPath to the directory or archive to unmount.
Returns
true if the directory or archive was successfully unmounted, false otherwise.

Definition at line 89 of file resource-manager.cpp.


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