sftools  2.0 dev
Bunch of tools for SFML application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | List of all members
sftools::GenericManager< Resource, Id, OnLoad > Class Template Reference

A generic resource manager ready to be customized. More...

#include <GenericManager.hpp>

+ Collaboration diagram for sftools::GenericManager< Resource, Id, OnLoad >:

Public Member Functions

 GenericManager ()
 Constructor.
 
bool load (Id const &id, bool forceReload=false)
 Load a new resource.
 
void unload (Id const &id)
 Unload a resource.
 
void unloadAll ()
 Unload all resources.
 
Resource const & operator[] (Id const &id) const
 Fetch a resource.
 
Resource & operator[] (Id const &id)
 Fetch a resource.
 

Detailed Description

template<typename Resource, typename Id, typename OnLoad>
class sftools::GenericManager< Resource, Id, OnLoad >

A generic resource manager ready to be customized.

Resource objects are stored in a std::map<Id, Resource*>.

OnLoad type must have an operator () taking an Id as unique parameter and returning a pointer to Resource (or 0 if loading failed).

Template Parameters
ResourceType of the resource to manage
IdType of resources' identifiers
OnLoadProcedure type to load resources

Definition at line 59 of file GenericManager.hpp.

Constructor & Destructor Documentation

template<typename Resource , typename Id , typename OnLoad >
sftools::GenericManager< Resource, Id, OnLoad >::GenericManager ( )

Constructor.

Definition at line 39 of file GenericManager.tpp.

Member Function Documentation

template<typename Resource , typename Id , typename OnLoad >
bool sftools::GenericManager< Resource, Id, OnLoad >::load ( Id const &  id,
bool  forceReload = false 
)

Load a new resource.

Parameters
idid of the resource to load
forceReloadensure the resource is (re)loaded
Returns
true if the resource was loaded properly
See Also
onLoad

Definition at line 45 of file GenericManager.tpp.

template<typename Resource , typename Id , typename OnLoad >
Resource const & sftools::GenericManager< Resource, Id, OnLoad >::operator[] ( Id const &  id) const

Fetch a resource.

A std::invalid_argument exception is thrown if id doesn't exist.

Parameters
idthe id of the resource to be fetched
Returns
the resource corresponding to id
Exceptions
std::invalid_argument

Definition at line 95 of file GenericManager.tpp.

template<typename Resource , typename Id , typename OnLoad >
Resource & sftools::GenericManager< Resource, Id, OnLoad >::operator[] ( Id const &  id)

Fetch a resource.

A std::invalid_argument exception is thrown if id doesn't exist.

Parameters
idthe id of the resource to be fetched
Returns
the resource corresponding to id
Exceptions
std::invalid_argument

Definition at line 110 of file GenericManager.tpp.

template<typename Resource , typename Id , typename OnLoad >
void sftools::GenericManager< Resource, Id, OnLoad >::unload ( Id const &  id)

Unload a resource.

Parameters
idid of the resource to unload

Definition at line 78 of file GenericManager.tpp.

template<typename Resource , typename Id , typename OnLoad >
void sftools::GenericManager< Resource, Id, OnLoad >::unloadAll ( )

Unload all resources.

Definition at line 85 of file GenericManager.tpp.


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