Gamedev Framework (gf)  0.5.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

Member Typedef Documentation

◆ Loader

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

A resource loader.

Constructor & Destructor Documentation

◆ ResourceCache() [1/2]

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


loaderA resource loader

◆ ResourceCache() [2/2]

template<typename T>
gf::ResourceCache< T >::ResourceCache ( const ResourceCache< T > &  )

Deleted copy constructor.

Member Function Documentation

◆ getResource()

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

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.

assetManagerAn asset manager
filenameThe filename of the resource
A reference to the resource
std::runtime_errorIf the resource is not found

◆ operator=()

template<typename T>
ResourceCache& gf::ResourceCache< T >::operator= ( const ResourceCache< T > &  )

Deleted copy assignment.