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