![]() |
MAGE
v0.171.0
Matthias Advanced Game Engine
|
#include <resource_pool.hpp>
Classes | |
class | Resource |
Public Types | |
using | key_type = KeyT |
using | value_type = ResourceT |
Public Member Functions | |
ResourcePool ()=default | |
ResourcePool (const ResourcePool &pool)=delete | |
ResourcePool (ResourcePool &&pool) noexcept | |
~ResourcePool () noexcept | |
ResourcePool & | operator= (const ResourcePool &pool)=delete |
ResourcePool & | operator= (ResourcePool &&pool)=delete |
bool | empty () const noexcept |
std::size_t | size () const noexcept |
bool | Contains (const KeyT &key) noexcept |
SharedPtr< ResourceT > | Get (const KeyT &key) noexcept |
template<typename... ConstructorArgsT> | |
SharedPtr< ResourceT > | GetOrCreate (const KeyT &key, ConstructorArgsT &&... args) |
template<typename DerivedResourceT , typename... ConstructorArgsT> | |
SharedPtr< ResourceT > | GetOrCreateDerived (const KeyT &key, ConstructorArgsT &&... args) |
void | Remove (const KeyT &key) |
void | RemoveAll () noexcept |
Private Types | |
using | ResourceMap = std::map< KeyT, WeakPtr< ResourceT > > |
Private Attributes | |
ResourceMap | m_resource_map |
std::mutex | m_mutex |
A class of resource pools.
KeyT | The key type. |
ResourceT | The resource type. |
using mage::ResourcePool< KeyT, ResourceT >::key_type = KeyT |
The key type of resource pools.
|
private |
A resource map used by a resource pool.
using mage::ResourcePool< KeyT, ResourceT >::value_type = ResourceT |
The value type of resource pools.
|
default |
Constructs a resource pool.
|
delete |
Constructs a resource pool from the given resource pool.
[in] | pool | A reference to the resource pool to copy. |
|
noexcept |
Constructs a resource pool by moving the given resource pool.
[in] | pool | A reference to the resource pool to move. |
|
noexcept |
Destructs this resource pool.
|
noexcept |
Checks whether this resource pool contains a resource corresponding to the given key from this resource pool.
[in] | key | A reference to the key of the resource. |
true
, if a resource is contained in this resource pool corresponding to the given key. false
, otherwise.
|
noexcept |
Checks whether this resource pool is empty.
true
if this resource pool is empty. false
otherwise.
|
noexcept |
Returns the resource corresponding to the given key from this resource pool.
[in] | key | A reference to the key of the resource. |
nullptr
, if no resource is contained in this resource pool corresponding to the given key. SharedPtr< ResourceT > mage::ResourcePool< KeyT, ResourceT >::GetOrCreate | ( | const KeyT & | key, |
ConstructorArgsT &&... | args | ||
) |
Returns the resource corresponding to the given key from this resource pool.
If no resource is contained in this resource pool corresponding to the given key, a new resource is created from the given arguments, added to this resource pool and returned.
ConstructorArgsT | The argument types for creating a new resource of type ResourceT . |
[in] | key | A reference to the key of the resource. |
[in] | args | The arguments for creating a new resource of type ResourceT . |
SharedPtr< ResourceT > mage::ResourcePool< KeyT, ResourceT >::GetOrCreateDerived | ( | const KeyT & | key, |
ConstructorArgsT &&... | args | ||
) |
Returns the resource corresponding to the given key from this resource pool.
If no resource is contained in this resource pool corresponding to the given key, a new resource is created from the given arguments, added to this resource pool and returned.
DerivedResourceT
is a derived class of ResourceT
. DerivedResourceT | The derived resource type. |
ConstructorArgsT | The argument types for creating a new resource of type DerivedResourceT . |
[in] | key | A reference to the key of the resource. |
[in] | args | The arguments for creating a new resource of type DerivedResourceT . |
|
delete |
Copies the given resource pool to this resource pool.
[in] | pool | A reference to the resource pool to copy. |
|
delete |
Moves the given resource pool to this resource pool.
[in] | pool | A reference to the resource pool to move. |
void mage::ResourcePool< KeyT, ResourceT >::Remove | ( | const KeyT & | key | ) |
Removes the resource corresponding to the given key from this resource pool.
[in] | key | A reference to the key of the resource to remove. |
|
noexcept |
Removes all resources from this resource pool.
|
noexcept |
Returns the number of resources contained in this resource pool.
|
mutableprivate |
The mutex for accessing the resource map of this resource pool.
|
private |
The resource map of this resource pool.