Practical Tools for Simple Design
Loading...
Searching...
No Matches
Util::AssetStore< T > Class Template Reference

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...
 
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...
 

Detailed Description

template<typename T>
class Util::AssetStore< T >

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.

Template Parameters
TThe type of assets managed by the store.

Constructor & Destructor Documentation

◆ AssetStore()

template<typename T >
Util::AssetStore< T >::AssetStore ( std::function< T(const std::string &)>  loader)
inline

Constructs an AssetStore object with the specified loader function.

Parameters
loaderThe function used to load assets of type T from filepaths. Missing files should be handled inside loader.

Member Function Documentation

◆ Get()

template<typename T >
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.

Parameters
filepathThe filepath of the asset to retrieve.
Returns
A shared pointer to the asset, or nullptr if not found.

◆ Load()

template<typename T >
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.

Parameters
filepathThe filepath of the asset to load.

◆ Remove()

template<typename T >
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.

Parameters
filepathThe filepath of the asset to remove.

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