List of all members | Public Types | Public Member Functions
thor::ResourceHolder< R, I, O > Class Template Reference

Class that is responsible of the management of resources like images, fonts or music. More...

Inherits NonCopyable.

Public Types

typedef Om::Returned Resource
 Resource handle for mutable access. More...
 
typedef Om::ConstReturned ConstResource
 Resource handle for constant access. More...
 

Public Member Functions

 ResourceHolder ()
 Default constructor.
 
 ResourceHolder (ResourceHolder &&source)
 Move constructor.
 
ResourceHolderoperator= (ResourceHolder &&source)
 Move assignment operator.
 
Resource acquire (const I &id, const ResourceLoader< R > &how, Resources::KnownIdStrategy known=Resources::AssumeNew)
 Loads a new resource, identified as id. More...
 
void release (const I &id)
 Unloads the resource currently identified as id. More...
 
Resource operator[] (const I &id)
 Accesses a resource using the identifier id. More...
 
ConstResource operator[] (const I &id) const
 Accesses a resource using the identifier id (const overload). More...
 

Detailed Description

template<typename R, typename I, class O = Resources::CentralOwner>
class thor::ResourceHolder< R, I, O >

Class that is responsible of the management of resources like images, fonts or music.

A resource, sometimes called asset, is a heavyweight object that is used from multiple places in your application. This class acts as a central access point for resources. ResourceHolder provides methods to load (acquire), release and access resources. Every resource is associated with an ID, a user-defined identifier, which acts as a name or address referring to the resource.

Template Parameters
RThe resource type to manage (for example sf::Texture). R must not be const-qualified. R isn't required to be default-constructible or copy-constructible.
IThe type identifying the resource. IDs are usually enums or strings. If you don't want to choose IDs yourself, let ResourceLoader::getInfo() generate them automatically – in this case I would be std::string.
OOwnership model. Determines who owns the resources and is responsible of their lifetime. Possible types: Resources::CentralOwner (default), Resources::RefCounted.

Member Typedef Documentation

template<typename R , typename I , class O = Resources::CentralOwner>
typedef Om::ConstReturned thor::ResourceHolder< R, I, O >::ConstResource

Resource handle for constant access.

The type depends on the ownership policy:

template<typename R , typename I , class O = Resources::CentralOwner>
typedef Om::Returned thor::ResourceHolder< R, I, O >::Resource

Resource handle for mutable access.

The type depends on the ownership policy:

Member Function Documentation

template<typename R , typename I , class O = Resources::CentralOwner>
Resource thor::ResourceHolder< R, I, O >::acquire ( const I &  id,
const ResourceLoader< R > &  how,
Resources::KnownIdStrategy  known = Resources::AssumeNew 
)

Loads a new resource, identified as id.

Parameters
idValue identifying the resource.
howResource loader containing loading information. Determines how the resource is loaded.
knownDetermines what happens if id is already known. By default, an exception is thrown.
Returns
Resource associated with id; either just loaded or already stored in the holder.
Exceptions
ResourceLoadingExceptionif the loading of the resource fails.
ResourceAccessExceptionif a resource associated with id is already known and known is AssumeNew.
template<typename R , typename I , class O = Resources::CentralOwner>
Resource thor::ResourceHolder< R, I, O >::operator[] ( const I &  id)

Accesses a resource using the identifier id.

Requires that a resource with the identifier id is currently stored in this holder.

Parameters
idValue identifying the resource.
Returns
Handle to that resource.
Exceptions
ResourceAccessExceptionIf id doesn't refer to a currently stored resource.
template<typename R , typename I , class O = Resources::CentralOwner>
ConstResource thor::ResourceHolder< R, I, O >::operator[] ( const I &  id) const

Accesses a resource using the identifier id (const overload).

Requires that a resource with the identifier id is currently stored in this holder.

Parameters
idValue identifying the resource.
Returns
Handle to that resource, which does not allow modification of the resource.
Exceptions
ResourceAccessExceptionIf id doesn't refer to a currently stored resource.
template<typename R , typename I , class O = Resources::CentralOwner>
void thor::ResourceHolder< R, I, O >::release ( const I &  id)

Unloads the resource currently identified as id.

The resource is removed from this resource holder. Depending on the ownership policy, it may either be released immediately or live until it is no longer referenced. In any case, you cannot access it any longer through this instance.

Parameters
idValue identifying the resource.
Exceptions
ResourceAccessExceptionIf id doesn't refer to a currently stored resource.

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