|
Practical Tools for Simple Design
|
A class template for managing assets. More...
#include <AssetStore.hpp>
Public Member Functions | |
| AssetStore (std::function< T(const std::string &)> loader) | |
| Constructs an AssetStore object with the specified loader function. More... | |
| void | Load (const std::string &filepath) |
| Preload resources for future use. More... | |
| T | Get (const std::string &filepath) |
| Retrieves the asset associated with the specified filepath. More... | |
| void | Remove (const std::string &filepath) |
| Removes the asset associated with the specified filepath from the store. More... | |
A class template for managing assets.
The AssetStore class template provides functionality for loading, storing, and accessing potentially expensive resources. It uses a loader function to load assets from filepaths and stores them in an unordered map for efficient retrieval.
| T | The type of assets managed by the store. |
|
inline |
Constructs an AssetStore object with the specified loader function.
| loader | The function used to load assets of type T from filepaths. Missing files should be handled inside loader. |
| T Util::AssetStore< T >::Get | ( | const std::string & | filepath | ) |
Retrieves the asset associated with the specified filepath.
If the requested resource in not already in the store, this function will load the resource using loader and cache it. This should be the default way of loading resources.
| filepath | The filepath of the asset to retrieve. |
| void Util::AssetStore< T >::Load | ( | const std::string & | filepath | ) |
Preload resources for future use.
Calling this function before using the resource is optional and is reserved as an optimization technique.
| filepath | The filepath of the asset to load. |
| void Util::AssetStore< T >::Remove | ( | const std::string & | filepath | ) |
Removes the asset associated with the specified filepath from the store.
It is generally not required to manually manage resources in the store unless the program hits a memory limit. This operation does nothing if the filepath is not in the store.
| filepath | The filepath of the asset to remove. |