Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Public Types | Public Member Functions | List of all members
gf::ResourceCache< T > Class Template Reference

A generic cache for resources. More...

#include <gf/ResourceManager.h>

Public Types

using Loader = std::function< std::unique_ptr< T >(const Path &)>
 A resource loader. More...
 

Public Member Functions

 ResourceCache (Loader loader)
 Constructor. More...
 
 ResourceCache (const ResourceCache &)=delete
 Deleted copy constructor. More...
 
ResourceCacheoperator= (const ResourceCache &)=delete
 Deleted copy assignment. More...
 
TgetResource (AssetManager &assetManager, const Path &filename)
 Get a resource. More...
 

Detailed Description

template<typename T>
class gf::ResourceCache< T >

A generic cache for resources.

This function is a low-level class that is used in gf::ResourceManager. It is generic enough so that you can use it for your own purpose.

See also
gf::ResourceManager

Member Typedef Documentation

template<typename T>
using gf::ResourceCache< T >::Loader = std::function<std::unique_ptr<T>(const Path&)>

A resource loader.

Constructor & Destructor Documentation

template<typename T>
gf::ResourceCache< T >::ResourceCache ( Loader  loader)
inlineexplicit

Constructor.

Parameters
loaderA resource loader
template<typename T>
gf::ResourceCache< T >::ResourceCache ( const ResourceCache< T > &  )
delete

Deleted copy constructor.

Member Function Documentation

template<typename T>
T& gf::ResourceCache< T >::getResource ( AssetManager assetManager,
const Path filename 
)
inline

Get a resource.

If the resource exists in the cache, it is returned immediately. Otherwise, it is searched thanks to an asset manager and put in the cache. If the resource is not found, an exception is thrown.

Parameters
assetManagerAn asset manager
filenameThe filename of the resource
Returns
A reference to the resource
Exceptions
std::runtime_errorIf the resource is not found
template<typename T>
ResourceCache& gf::ResourceCache< T >::operator= ( const ResourceCache< T > &  )
delete

Deleted copy assignment.