|
| resource_cache ()=default |
| Default constructor.
|
|
| resource_cache (resource_cache &&)=default |
| Default move constructor.
|
|
resource_cache & | operator= (resource_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> |
resource_handle< Resource > | load (const id_type id, Args &&... args) |
| Loads the resource that corresponds to a given identifier. More...
|
|
template<typename Loader , typename... Args> |
resource_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> |
resource_handle< Resource > | temp (Args &&... args) const |
| Creates a temporary handle for a resource. More...
|
|
resource_handle< Resource > | handle (const id_type id) const |
| Creates a handle for a given resource identifier. More...
|
|
bool | contains (const id_type id) const |
| Checks if a cache contains a given identifier. More...
|
|
void | discard (const id_type id) |
| Discards the resource that corresponds to a given identifier. More...
|
|
template<typename Func > |
void | each (Func func) const |
| Iterates all resources. More...
|
|
template<typename Resource>
struct entt::resource_cache< Resource >
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.
- Template Parameters
-
Resource | Type of resources managed by a cache. |
template<typename Resource >
template<typename Loader , typename... Args>
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.
- Note
- If the identifier is already present in the cache, this function does nothing and the arguments are simply discarded.
- Warning
- If the resource cannot be loaded correctly, the returned handle will be invalid and any use of it will result in undefined behavior.
- Template Parameters
-
Loader | Type of loader to use to load the resource if required. |
Args | Types of arguments to use to load the resource if required. |
- Parameters
-
id | Unique resource identifier. |
args | Arguments to use to load the resource if required. |
- Returns
- A handle for the given resource.
template<typename Resource >
template<typename Loader , typename... Args>
Reloads a resource or loads it for the first time if not present.
Equivalent to the following snippet (pseudocode):
cache.discard(id);
cache.load(id, args...);
Arguments are forwarded directly to the loader in order to construct properly the requested resource.
- Warning
- If the resource cannot be loaded correctly, the returned handle will be invalid and any use of it will result in undefined behavior.
- Template Parameters
-
Loader | Type of loader to use to load the resource. |
Args | Types of arguments to use to load the resource. |
- Parameters
-
id | Unique resource identifier. |
args | Arguments to use to load the resource. |
- Returns
- A handle for the given resource.
template<typename Resource >
template<typename Loader , typename... Args>
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.
- Template Parameters
-
Loader | Type of loader to use to load the resource. |
Args | Types of arguments to use to load the resource. |
- Parameters
-
args | Arguments to use to load the resource. |
- Returns
- A handle for the given resource.