EnTT: entt::resource_cache< Type, Loader, Allocator > Class Template Reference

EnTT 3.15.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
entt::resource_cache< Type, Loader, Allocator > Class Template Reference

Basic cache for resources of any type. More...

`#include <cache.hpp>`

## Public Types
using | allocator_type = Allocator
| Allocator type.
using | value_type = Type
| Resource type.
using | size_type = std::size_t
| Unsigned integer type.
using | loader_type = Loader
| Loader type.
using | iterator = internal::resource_cache_iterator<Type, typename container_type::iterator>
| Input iterator type.
using | const_iterator = internal::resource_cache_iterator<const Type, typename container_type::const_iterator>
| Constant input iterator type.

## Public Member Functions
| resource_cache ()
| Default constructor.
| resource_cache (const allocator_type &allocator)
| Constructs an empty cache with a given allocator.
| resource_cache (const loader_type &callable, const allocator_type &allocator=allocator_type{})
| Constructs an empty cache with a given allocator and loader.
| resource_cache (const resource_cache &)=default
| Default copy constructor.
| resource_cache (const resource_cache &other, const allocator_type &allocator)
| Allocator-extended copy constructor.
| resource_cache (resource_cache &&) noexcept=default
| Default move constructor.
| resource_cache (resource_cache &&other, const allocator_type &allocator)
| Allocator-extended move constructor.
| ~resource_cache ()=default
| Default destructor.
resource_cache & | operator= (const resource_cache &)=default
| Default copy assignment operator.
resource_cache & | operator= (resource_cache &&) noexcept=default
| Default move assignment operator.
constexpr allocator_type | get_allocator () const noexcept
| Returns the associated allocator.
const_iterator | cbegin () const noexcept
| Returns an iterator to the beginning.
const_iterator | begin () const noexcept
| Returns an iterator to the beginning.
iterator | begin () noexcept
| Returns an iterator to the beginning.
const_iterator | cend () const noexcept
| Returns an iterator to the end.
const_iterator | end () const noexcept
| Returns an iterator to the end.
iterator | end () noexcept
| Returns an iterator to the end.
bool | empty () const noexcept
| Returns true if a cache contains no resources, false otherwise.
size_type | size () const noexcept
| Number of resources managed by a cache.
void | clear () noexcept
| Clears a cache.
template<typename... Args>
std::pair< iterator, bool > | load (const id_type id, Args &&...args)
| Loads a resource, if its identifier does not exist.
template<typename... Args>
std::pair< iterator, bool > | force_load (const id_type id, Args &&...args)
| Force loads a resource, if its identifier does not exist.
resource< const value_type > | operator[] (const id_type id) const
| Returns a handle for a given resource identifier.
resource< value_type > | operator[] (const id_type id)
| Returns a handle for a given resource identifier.
bool | contains (const id_type id) const
| Checks if a cache contains a given identifier.
iterator | erase (const_iterator pos)
| Removes an element from a given position.
iterator | erase (const_iterator first, const_iterator last)
| Removes the given elements from a cache.
size_type | erase (const id_type id)
| Removes the given elements from a cache.
loader_type | loader () const
| Returns the loader used to create resources.

## Detailed Description

template<typename Type, typename Loader, typename Allocator>
class entt::resource_cache< Type, Loader, Allocator >

Basic cache for resources of any type.

Template Parameters

  Type | Type of resources managed by a cache.
  Loader | Type of loader used to create the resources.
  Allocator | Type of allocator used to manage memory and elements.

Definition at line 153 of file cache.hpp.

## Member Typedef Documentation

## ◆ allocator_type

template<typename Type, typename Loader, typename Allocator>

using entt::resource_cache< Type, Loader, Allocator >::allocator_type = Allocator

Allocator type.

Definition at line 161 of file cache.hpp.

## ◆ const_iterator

template<typename Type, typename Loader, typename Allocator>

using entt::resource_cache< Type, Loader, Allocator >::const_iterator = internal::resource_cache_iterator<const Type, typename container_type::const_iterator>

Constant input iterator type.

Definition at line 171 of file cache.hpp.

## ◆ iterator

template<typename Type, typename Loader, typename Allocator>

using entt::resource_cache< Type, Loader, Allocator >::iterator = internal::resource_cache_iterator<Type, typename container_type::iterator>

Input iterator type.

Definition at line 169 of file cache.hpp.

## ◆ loader_type

template<typename Type, typename Loader, typename Allocator>

using entt::resource_cache< Type, Loader, Allocator >::loader_type = Loader

Loader type.

Definition at line 167 of file cache.hpp.

## ◆ size_type

template<typename Type, typename Loader, typename Allocator>

using entt::resource_cache< Type, Loader, Allocator >::size_type = std::size_t

Unsigned integer type.

Definition at line 165 of file cache.hpp.

## ◆ value_type

template<typename Type, typename Loader, typename Allocator>

using entt::resource_cache< Type, Loader, Allocator >::value_type = Type

Resource type.

Definition at line 163 of file cache.hpp.

## Constructor & Destructor Documentation

## ◆ resource_cache() [1/5]

template<typename Type, typename Loader, typename Allocator>

entt::resource_cache< Type, Loader, Allocator >::resource_cache | ( |  | ) |
| inline

Default constructor.

Definition at line 174 of file cache.hpp.

## ◆ resource_cache() [2/5]

template<typename Type, typename Loader, typename Allocator>

entt::resource_cache< Type, Loader, Allocator >::resource_cache | ( | const allocator_type & | allocator | ) |
| inlineexplicit

Constructs an empty cache with a given allocator.

Parameters

  allocator | The allocator to use.

Definition at line 181 of file cache.hpp.

## ◆ resource_cache() [3/5]

template<typename Type, typename Loader, typename Allocator>

entt::resource_cache< Type, Loader, Allocator >::resource_cache | ( | const loader_type & | callable,
|  | const allocator_type & | allocator = allocator_type{} )
| inlineexplicit

Constructs an empty cache with a given allocator and loader.

Parameters

  callable | The loader to use.
  allocator | The allocator to use.

Definition at line 189 of file cache.hpp.

## ◆ resource_cache() [4/5]

template<typename Type, typename Loader, typename Allocator>

entt::resource_cache< Type, Loader, Allocator >::resource_cache | ( | const resource_cache< Type, Loader, Allocator > & | other,
|  | const allocator_type & | allocator )
| inline

Allocator-extended copy constructor.

Parameters

  other | The instance to copy from.
  allocator | The allocator to use.

Definition at line 200 of file cache.hpp.

## ◆ resource_cache() [5/5]

template<typename Type, typename Loader, typename Allocator>

entt::resource_cache< Type, Loader, Allocator >::resource_cache | ( | resource_cache< Type, Loader, Allocator > && | other,
|  | const allocator_type & | allocator )
| inline

Allocator-extended move constructor.

Parameters

  other | The instance to move from.
  allocator | The allocator to use.

Definition at line 211 of file cache.hpp.

## Member Function Documentation

## ◆ begin() [1/2]

template<typename Type, typename Loader, typename Allocator>

const_iterator entt::resource_cache< Type, Loader, Allocator >::begin | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the beginning.

If the cache is empty, the returned iterator will be equal to `end()`.

Returns
  An iterator to the first instance of the internal cache.

Definition at line 249 of file cache.hpp.

## ◆ begin() [2/2]

template<typename Type, typename Loader, typename Allocator>

iterator entt::resource_cache< Type, Loader, Allocator >::begin | ( |  | ) |
| inlinenodiscardnoexcept

Returns an iterator to the beginning.

If the cache is empty, the returned iterator will be equal to `end()`.

Returns
  An iterator to the first instance of the internal cache.

Definition at line 254 of file cache.hpp.

## ◆ cbegin()

template<typename Type, typename Loader, typename Allocator>

const_iterator entt::resource_cache< Type, Loader, Allocator >::cbegin | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the beginning.

If the cache is empty, the returned iterator will be equal to `end()`.

Returns
  An iterator to the first instance of the internal cache.

Definition at line 244 of file cache.hpp.

## ◆ cend()

template<typename Type, typename Loader, typename Allocator>

const_iterator entt::resource_cache< Type, Loader, Allocator >::cend | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the end.

Returns
  An iterator to the element following the last instance of the internal cache.

Definition at line 263 of file cache.hpp.

## ◆ clear()

template<typename Type, typename Loader, typename Allocator>

void entt::resource_cache< Type, Loader, Allocator >::clear | ( |  | ) |
| inlinenoexcept

Clears a cache.

Definition at line 294 of file cache.hpp.

## ◆ contains()

template<typename Type, typename Loader, typename Allocator>

bool entt::resource_cache< Type, Loader, Allocator >::contains | ( | const id_type | id | ) | const
| inlinenodiscard

Checks if a cache contains a given identifier.

Parameters

  id | Unique resource identifier.

Returns
  True if the cache contains the resource, false otherwise.

Definition at line 365 of file cache.hpp.

## ◆ empty()

template<typename Type, typename Loader, typename Allocator>

bool entt::resource_cache< Type, Loader, Allocator >::empty | ( |  | ) | const
| inlinenodiscardnoexcept

Returns true if a cache contains no resources, false otherwise.

Returns
  True if the cache contains no resources, false otherwise.

Definition at line 281 of file cache.hpp.

## ◆ end() [1/2]

template<typename Type, typename Loader, typename Allocator>

const_iterator entt::resource_cache< Type, Loader, Allocator >::end | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the end.

Returns
  An iterator to the element following the last instance of the internal cache.

Definition at line 268 of file cache.hpp.

## ◆ end() [2/2]

template<typename Type, typename Loader, typename Allocator>

iterator entt::resource_cache< Type, Loader, Allocator >::end | ( |  | ) |
| inlinenodiscardnoexcept

Returns an iterator to the end.

Returns
  An iterator to the element following the last instance of the internal cache.

Definition at line 273 of file cache.hpp.

## ◆ erase() [1/3]

template<typename Type, typename Loader, typename Allocator>

size_type entt::resource_cache< Type, Loader, Allocator >::erase | ( | const id_type | id | ) |
| inline

Removes the given elements from a cache.

Parameters

  id | Unique resource identifier.

Returns
  Number of resources erased (either 0 or 1).

Definition at line 395 of file cache.hpp.

## ◆ erase() [2/3]

template<typename Type, typename Loader, typename Allocator>

iterator entt::resource_cache< Type, Loader, Allocator >::erase | ( | const_iterator | first,
|  | const_iterator | last )
| inline

Removes the given elements from a cache.

Parameters

  first | An iterator to the first element of the range of elements.
  last | An iterator past the last element of the range of elements.

Returns
  An iterator following the last removed element.

Definition at line 385 of file cache.hpp.

## ◆ erase() [3/3]

template<typename Type, typename Loader, typename Allocator>

iterator entt::resource_cache< Type, Loader, Allocator >::erase | ( | const_iterator | pos | ) |
| inline

Removes an element from a given position.

Parameters

  pos | An iterator to the element to remove.

Returns
  An iterator following the removed element.

Definition at line 374 of file cache.hpp.

## ◆ force_load()

template<typename Type, typename Loader, typename Allocator>
template<typename... Args>

std::pair< iterator, bool > entt::resource_cache< Type, Loader, Allocator >::force_load | ( | const id_type | id,
|  | Args &&... | args )
| inline

Force loads a resource, if its identifier does not exist.

Arguments are forwarded directly to the loader and consumed only if the resource doesn't already exist.

Warning
  If the resource isn't loaded correctly, the returned handle could be invalid and any use of it will result in undefined behavior.

Template Parameters

  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 pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a bool denoting whether the insertion took place.

Definition at line 329 of file cache.hpp.

## ◆ get_allocator()

template<typename Type, typename Loader, typename Allocator>

allocator_type entt::resource_cache< Type, Loader, Allocator >::get_allocator | ( |  | ) | const
| inlinenodiscardconstexprnoexcept

Returns the associated allocator.

Returns
  The associated allocator.

Definition at line 233 of file cache.hpp.

## ◆ load()

template<typename Type, typename Loader, typename Allocator>
template<typename... Args>

std::pair< iterator, bool > entt::resource_cache< Type, Loader, Allocator >::load | ( | const id_type | id,
|  | Args &&... | args )
| inline

Loads a resource, if its identifier does not exist.

Arguments are forwarded directly to the loader and consumed only if the resource doesn't already exist.

Warning
  If the resource isn't loaded correctly, the returned handle could be invalid and any use of it will result in undefined behavior.

Template Parameters

  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 pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a bool denoting whether the insertion took place.

Definition at line 316 of file cache.hpp.

## ◆ loader()

template<typename Type, typename Loader, typename Allocator>

loader_type entt::resource_cache< Type, Loader, Allocator >::loader | ( |  | ) | const
| inlinenodiscard

Returns the loader used to create resources.

Returns
  The loader used to create resources.

Definition at line 403 of file cache.hpp.

## ◆ operator=() [1/2]

template<typename Type, typename Loader, typename Allocator>

resource_cache & entt::resource_cache< Type, Loader, Allocator >::operator= | ( | const resource_cache< Type, Loader, Allocator > & |  | ) |
| default

Default copy assignment operator.

Returns
  This cache.

## ◆ operator=() [2/2]

template<typename Type, typename Loader, typename Allocator>

resource_cache & entt::resource_cache< Type, Loader, Allocator >::operator= | ( | resource_cache< Type, Loader, Allocator > && |  | ) |
| defaultnoexcept

Default move assignment operator.

Returns
  This cache.

## ◆ operator[]() [1/2]

template<typename Type, typename Loader, typename Allocator>

resource< value_type > entt::resource_cache< Type, Loader, Allocator >::operator[] | ( | const id_type | id | ) |
| inlinenodiscard

Returns a handle for a given resource identifier.

Warning
  There is no guarantee that the returned handle is valid.
  If it is not, any use will result in indefinite behavior.

Parameters

  id | Unique resource identifier.

Returns
  A handle for the given resource.

Definition at line 352 of file cache.hpp.

## ◆ operator[]() [2/2]

template<typename Type, typename Loader, typename Allocator>

resource< const value_type > entt::resource_cache< Type, Loader, Allocator >::operator[] | ( | const id_type | id | ) | const
| inlinenodiscard

Returns a handle for a given resource identifier.

Warning
  There is no guarantee that the returned handle is valid.
  If it is not, any use will result in indefinite behavior.

Parameters

  id | Unique resource identifier.

Returns
  A handle for the given resource.

Definition at line 343 of file cache.hpp.

## ◆ size()

template<typename Type, typename Loader, typename Allocator>

size_type entt::resource_cache< Type, Loader, Allocator >::size | ( |  | ) | const
| inlinenodiscardnoexcept

Number of resources managed by a cache.

Returns
  Number of resources currently stored.

Definition at line 289 of file cache.hpp.

The documentation for this class was generated from the following file:

- src/entt/resource/cache.hpp