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. |
Definition at line 30 of file cache.hpp.
template<typename Resource >
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.
- See also
- resource_handle
- Parameters
-
| id | Unique resource identifier. |
- Returns
- A handle for the given resource.
Definition at line 168 of file cache.hpp.
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.
Definition at line 94 of file cache.hpp.
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.
Definition at line 134 of file cache.hpp.
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.
Definition at line 151 of file cache.hpp.