Class that is responsible for the management of resources like images, fonts or music. More...
Public Member Functions | |
ResourceManager () | |
Default constructor. | |
~ResourceManager () | |
Destructor. | |
ResourcePtr< Resource > | Search (const ResourceKey &key) |
Searches for an occurrence of key and returns the mapped resource, if possible. | |
ResourcePtr< const Resource > | Search (const ResourceKey &key) const |
Searches for an occurrence of key and returns the mapped resource, if possible (const overload). | |
ResourcePtr< Resource > | Acquire (const ResourceKey &key) |
Returns the resource mapped to key, loading the resource if required. | |
bool | Release (const ResourceKey &key) |
Releases the resource as soon as possible. | |
void | SetLoadingFailureStrategy (Resources::LoadingFailureStrategy strategy) |
Determines how to react to resources that cannot be loaded. | |
void | SetReleaseStrategy (Resources::ReleaseStrategy strategy) |
Determines whether resources are automatically released or not. |
Class that is responsible for the management of resources like images, fonts or music.
You can acquire and release resources. Access is granted through the key (an ID class).
Resource | The resource type to manage (for example sf::Image). Const-correctness is properly forwarded: If Resource is const-qualified, you cannot modify the resources after initialization (via ResourcePtr). Resource isn't required to be default-constructible or copy-constructible. |
ResourceKey | The key class that is used to distinguish between resources (for example thor::Resources::ImageKey). By default, a library implementation supporting the SFML resource classes is used. If you want to specify your own key classes, they have to fulfill the following requirements:
|
thor::ResourceManager< Resource, ResourceKey >::ResourceManager | ( | ) |
Default constructor.
Initially, the object owns no allocated resources. By default, the loading failure strategy Resources::ThrowException and the release strategy Resources::ExplicitRelease are used.
thor::ResourceManager< Resource, ResourceKey >::~ResourceManager | ( | ) |
Destructor.
Destroys all allocated resources. All ResourcePtr instances pointing to any of the resources stored inside this ResourceManager become NULL.
ResourcePtr<Resource> thor::ResourceManager< Resource, ResourceKey >::Acquire | ( | const ResourceKey & | key | ) |
Returns the resource mapped to key, loading the resource if required.
If the key is already stored, the corresponding resource is returned. Otherwise, the resource is loaded. The release time of the resource is determined by the release strategy.
key | The resource identifier to search for, which also contains loading information. |
ResourceLoadingException | if the loading of the resource fails (and the ThrowException strategy is active). |
bool thor::ResourceManager< Resource, ResourceKey >::Release | ( | const ResourceKey & | key | ) |
Releases the resource as soon as possible.
If the resource is not in use (i.e. no ResourcePtr references it), it is immediately released. Otherwise, it is released as soon as the last ResourcePtr loses ownership. Calling this function has no effect when the AutoRelease strategy is active, since the resource is released ASAP anyway.
key | The resource identifier. |
ResourcePtr<Resource> thor::ResourceManager< Resource, ResourceKey >::Search | ( | const ResourceKey & | key | ) |
Searches for an occurrence of key and returns the mapped resource, if possible.
This function does never load a new resource.
key | The resource identifier to search for. |
ResourcePtr<const Resource> thor::ResourceManager< Resource, ResourceKey >::Search | ( | const ResourceKey & | key | ) | const |
Searches for an occurrence of key and returns the mapped resource, if possible (const overload).
This function does never load a new resource.
key | The resource identifier to search for. |
void thor::ResourceManager< Resource, ResourceKey >::SetLoadingFailureStrategy | ( | Resources::LoadingFailureStrategy | strategy | ) |
Determines how to react to resources that cannot be loaded.
The strategy concerns all failing Acquire() calls.
void thor::ResourceManager< Resource, ResourceKey >::SetReleaseStrategy | ( | Resources::ReleaseStrategy | strategy | ) |
Determines whether resources are automatically released or not.
This function sets the strategy for each resource that will be acquired in the future. Resources that have already been allocated are not concerned! This allows you to set the release behaviour specificially for each resource before you call Acquire().