EnTT 3.13.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 value_type = Type
 Resource type.
 
using size_type = std::size_t
 Unsigned integer type.
 
using loader_type = Loader
 Loader type.
 
using allocator_type = Allocator
 Allocator 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 &&)=default
 Default move constructor.
 
 resource_cache (resource_cache &&other, const allocator_type &allocator)
 Allocator-extended move constructor.
 
resource_cacheoperator= (const resource_cache &)=default
 Default copy assignment operator.
 
resource_cacheoperator= (resource_cache &&)=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_typeoperator[] (const id_type id) const
 Returns a handle for a given resource identifier.
 
resource< value_typeoperator[] (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
TypeType of resources managed by a cache.
LoaderType of loader used to create the resources.
AllocatorType 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 167 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 165 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 163 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 161 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
allocatorThe 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
callableThe loader to use.
allocatorThe 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
otherThe instance to copy from.
allocatorThe 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
otherThe instance to move from.
allocatorThe 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
inlinenoexcept

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 246 of file cache.hpp.

◆ begin() [2/2]

template<typename Type , typename Loader , typename Allocator >
iterator entt::resource_cache< Type, Loader, Allocator >::begin ( )
inlinenoexcept

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 251 of file cache.hpp.

◆ cbegin()

template<typename Type , typename Loader , typename Allocator >
const_iterator entt::resource_cache< Type, Loader, Allocator >::cbegin ( ) const
inlinenoexcept

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 241 of file cache.hpp.

◆ cend()

template<typename Type , typename Loader , typename Allocator >
const_iterator entt::resource_cache< Type, Loader, Allocator >::cend ( ) const
inlinenoexcept

Returns an iterator to the end.

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

Definition at line 260 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 291 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
inline

Checks if a cache contains a given identifier.

Parameters
idUnique resource identifier.
Returns
True if the cache contains the resource, false otherwise.

Definition at line 362 of file cache.hpp.

◆ empty()

template<typename Type , typename Loader , typename Allocator >
bool entt::resource_cache< Type, Loader, Allocator >::empty ( ) const
inlinenoexcept

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

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

Definition at line 278 of file cache.hpp.

◆ end() [1/2]

template<typename Type , typename Loader , typename Allocator >
const_iterator entt::resource_cache< Type, Loader, Allocator >::end ( ) const
inlinenoexcept

Returns an iterator to the end.

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

Definition at line 265 of file cache.hpp.

◆ end() [2/2]

template<typename Type , typename Loader , typename Allocator >
iterator entt::resource_cache< Type, Loader, Allocator >::end ( )
inlinenoexcept

Returns an iterator to the end.

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

Definition at line 270 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
idUnique resource identifier.
Returns
Number of resources erased (either 0 or 1).

Definition at line 392 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
firstAn iterator to the first element of the range of elements.
lastAn iterator past the last element of the range of elements.
Returns
An iterator following the last removed element.

Definition at line 382 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
posAn iterator to the element to remove.
Returns
An iterator following the removed element.

Definition at line 371 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
ArgsTypes of arguments to use to load the resource if required.
Parameters
idUnique resource identifier.
argsArguments 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 326 of file cache.hpp.

◆ get_allocator()

template<typename Type , typename Loader , typename Allocator >
constexpr allocator_type entt::resource_cache< Type, Loader, Allocator >::get_allocator ( ) const
inlineconstexprnoexcept

Returns the associated allocator.

Returns
The associated allocator.

Definition at line 230 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
ArgsTypes of arguments to use to load the resource if required.
Parameters
idUnique resource identifier.
argsArguments 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 313 of file cache.hpp.

◆ loader()

template<typename Type , typename Loader , typename Allocator >
loader_type entt::resource_cache< Type, Loader, Allocator >::loader ( ) const
inline

Returns the loader used to create resources.

Returns
The loader used to create resources.

Definition at line 400 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 > &&  )
default

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)
inline

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
idUnique resource identifier.
Returns
A handle for the given resource.

Definition at line 349 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
inline

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
idUnique resource identifier.
Returns
A handle for the given resource.

Definition at line 340 of file cache.hpp.

◆ size()

template<typename Type , typename Loader , typename Allocator >
size_type entt::resource_cache< Type, Loader, Allocator >::size ( ) const
inlinenoexcept

Number of resources managed by a cache.

Returns
Number of resources currently stored.

Definition at line 286 of file cache.hpp.


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