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. | |
ResourceHolder & | operator= (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... | |
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.
R | The 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. |
I | The 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. |
O | Ownership model. Determines who owns the resources and is responsible of their lifetime. Possible types: Resources::CentralOwner (default), Resources::RefCounted. |
typedef Om::ConstReturned thor::ResourceHolder< R, I, O >::ConstResource |
Resource handle for constant access.
The type depends on the ownership policy:
typedef Om::Returned thor::ResourceHolder< R, I, O >::Resource |
Resource handle for mutable access.
The type depends on the ownership policy:
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.
id | Value identifying the resource. |
how | Resource loader containing loading information. Determines how the resource is loaded. |
known | Determines what happens if id is already known. By default, an exception is thrown. |
ResourceLoadingException | if the loading of the resource fails. |
ResourceAccessException | if a resource associated with id is already known and known is AssumeNew. |
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.
id | Value identifying the resource. |
ResourceAccessException | If id doesn't refer to a currently stored resource. |
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.
id | Value identifying the resource. |
ResourceAccessException | If id doesn't refer to a currently stored resource. |
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.
id | Value identifying the resource. |
ResourceAccessException | If id doesn't refer to a currently stored resource. |