Bomberman
Public Member Functions | Private Attributes | List of all members
RAY::Cache< T > Class Template Reference

A templated class used to cache ressources, indexed with a string. More...

#include <Cache.hpp>

Collaboration diagram for RAY::Cache< T >:

Public Member Functions

 Cache (std::function< T(const char *)> dataLoader, std::function< void(T)> dataUnloader)
 
 ~Cache ()=default
 Default destructor, will destroy ray's data. More...
 
 Cache (const Cache &)=default
 default copy constructor More...
 
Cacheoperator= (const Cache &)=default
 a cache is assignable More...
 
std::shared_ptr< T > fetch (const std::string &path, bool lonely=false)
 

Private Attributes

std::function< T(const char *)> _dataLoader
 function to call to load data More...
 
std::function< void(T)> _dataUnloader
 function to call when the ray data will be unloaded More...
 
std::unordered_map< std::string, std::vector< std::shared_ptr< T > > > _cache
 map storing shared ptr of caches More...
 

Detailed Description

template<typename T>
class RAY::Cache< T >

A templated class used to cache ressources, indexed with a string.

Constructor & Destructor Documentation

◆ Cache() [1/2]

template<typename T >
RAY::Cache< T >::Cache ( std::function< T(const char *)>  dataLoader,
std::function< void(T)>  dataUnloader 
)
inline

◆ ~Cache()

template<typename T >
RAY::Cache< T >::~Cache ( )
default

Default destructor, will destroy ray's data.

◆ Cache() [2/2]

template<typename T >
RAY::Cache< T >::Cache ( const Cache< T > &  )
default

default copy constructor

Member Function Documentation

◆ fetch()

template<typename T >
std::shared_ptr<T> RAY::Cache< T >::fetch ( const std::string &  path,
bool  lonely = false 
)
inline
Parameters
pathpath of the file
lonelyshould be set to true if the loaded data must be held by no other active entites
Returns
a newly loaded ressource if it hasn't be previously loaded, or one from cache

◆ operator=()

template<typename T >
Cache& RAY::Cache< T >::operator= ( const Cache< T > &  )
default

a cache is assignable

Member Data Documentation

◆ _cache

template<typename T >
std::unordered_map<std::string, std::vector<std::shared_ptr<T> > > RAY::Cache< T >::_cache
private

map storing shared ptr of caches

◆ _dataLoader

template<typename T >
std::function<T(const char *)> RAY::Cache< T >::_dataLoader
private

function to call to load data

◆ _dataUnloader

template<typename T >
std::function<void(T)> RAY::Cache< T >::_dataUnloader
private

function to call when the ray data will be unloaded


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