OpenLexocad
28.0
|
Simple cache for resources of a given type. More...
#include <entt.hpp>
Public Types | |
using | size_type = std::size_t |
Unsigned integer type. More... | |
using | resource_type = Resource |
Type of resources managed by a cache. More... | |
using | id_type = ENTT_ID_TYPE |
Unique identifier type for resources. More... | |
Public Member Functions | |
cache ()=default | |
Default constructor. More... | |
cache (cache &&)=default | |
Default move constructor. More... | |
cache & | operator= (cache &&)=default |
Default move assignment operator. More... | |
size_type | size () const ENTT_NOEXCEPT |
Number of resources managed by a cache. More... | |
bool | empty () const ENTT_NOEXCEPT |
Returns true if a cache contains no resources, false otherwise. More... | |
void | clear () ENTT_NOEXCEPT |
Clears a cache and discards all its resources. More... | |
template<typename Loader , typename... Args> | |
entt::handle< Resource > | load (const id_type id, Args &&... args) |
Loads the resource that corresponds to a given identifier. More... | |
template<typename Loader , typename... Args> | |
entt::handle< Resource > | reload (const id_type id, Args &&... args) |
Reloads a resource or loads it for the first time if not present. More... | |
template<typename Loader , typename... Args> | |
entt::handle< Resource > | temp (Args &&... args) const |
Creates a temporary handle for a resource. More... | |
entt::handle< Resource > | handle (const id_type id) const |
Creates a handle for a given resource identifier. More... | |
bool | contains (const id_type id) const ENTT_NOEXCEPT |
Checks if a cache contains a given identifier. More... | |
void | discard (const id_type id) ENTT_NOEXCEPT |
Discards the resource that corresponds to a given identifier. More... | |
template<typename Func > | |
void | each (Func func) const |
Iterates all resources. More... | |
Simple cache for resources of a given type.
Minimal implementation of a cache for resources of a given type. It doesn't offer much functionalities but it's suitable for small or medium sized applications and can be freely inherited to add targeted functionalities for large sized applications.
Resource | Type of resources managed by a cache. |
using entt::cache::id_type = ENTT_ID_TYPE |
Unique identifier type for resources.
using entt::cache::resource_type = Resource |
Type of resources managed by a cache.
using entt::cache::size_type = std::size_t |
Unsigned integer type.
|
default |
Default constructor.
|
default |
Default move constructor.
|
inline |
Clears a cache and discards all its resources.
Handles are not invalidated and the memory used by a resource isn't freed as long as at least a handle keeps the resource itself alive.
|
inline |
Checks if a cache contains a given identifier.
id | Unique resource identifier. |
|
inline |
Discards the resource that corresponds to a given identifier.
Handles are not invalidated and the memory used by the resource isn't freed as long as at least a handle keeps the resource itself alive.
id | Unique resource identifier. |
|
inline |
Iterates all resources.
The function object is invoked for each element. It is provided with either the resource identifier, the resource handle or both of them.
The signature of the function must be equivalent to one of the following forms:
Func | Type of the function object to invoke. |
func | A valid function object. |
|
inline |
Returns true if a cache contains no resources, false otherwise.
|
inline |
Creates a handle for a given resource identifier.
A resource handle can be in a either valid or invalid state. In other terms, a resource handle is properly initialized with a resource if the cache contains the resource itself. Otherwise the returned handle is uninitialized and accessing it results in undefined behavior.
id | Unique resource identifier. |
|
inline |
Loads the resource that corresponds to a given identifier.
In case an identifier isn't already present in the cache, it loads its resource and stores it aside for future uses. Arguments are forwarded directly to the loader in order to construct properly the requested resource.
Loader | Type of loader to use to load the resource if required. |
Args | Types of arguments to use to load the resource if required. |
id | Unique resource identifier. |
args | Arguments to use to load the resource if required. |
Default move assignment operator.
|
inline |
Reloads a resource or loads it for the first time if not present.
Equivalent to the following snippet (pseudocode):
Arguments are forwarded directly to the loader in order to construct properly the requested resource.
Loader | Type of loader to use to load the resource. |
Args | Types of arguments to use to load the resource. |
id | Unique resource identifier. |
args | Arguments to use to load the resource. |
|
inline |
Number of resources managed by a cache.
|
inline |
Creates a temporary handle for a resource.
Arguments are forwarded directly to the loader in order to construct properly the requested resource. The handle isn't stored aside and the cache isn't in charge of the lifetime of the resource itself.
Loader | Type of loader to use to load the resource. |
Args | Types of arguments to use to load the resource. |
args | Arguments to use to load the resource. |