OpenLexocad  27.1
entt::basic_storage< Entity, Type, typename > Class Template Reference

Basic storage implementation. More...

#include <entt.hpp>

Inheritance diagram for entt::basic_storage< Entity, Type, typename >:
entt::sparse_set< Entity > entt::storage< Entity, Type >

Public Types

using object_type = Type
 Type of the objects associated with the entities. More...
 
using entity_type = Entity
 Underlying entity identifier. More...
 
using size_type = std::size_t
 Unsigned integer type. More...
 
using iterator_type = iterator< false >
 Random access iterator type. More...
 
using const_iterator_type = iterator< true >
 Constant random access iterator type. More...
 
- Public Types inherited from entt::sparse_set< Entity >
using entity_type = Entity
 Underlying entity identifier. More...
 
using size_type = std::size_t
 Unsigned integer type. More...
 
using iterator_type = iterator
 Random access iterator type. More...
 

Public Member Functions

void reserve (const size_type cap)
 Increases the capacity of a storage. More...
 
void shrink_to_fit ()
 Requests the removal of unused capacity. More...
 
const object_typeraw () const ENTT_NOEXCEPT
 Direct access to the array of objects. More...
 
object_typeraw () ENTT_NOEXCEPT
 Direct access to the array of objects. More...
 
const_iterator_type cbegin () const ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
const_iterator_type begin () const ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
iterator_type begin () ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
const_iterator_type cend () const ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
const_iterator_type end () const ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
iterator_type end () ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
const object_typeget (const entity_type entt) const ENTT_NOEXCEPT
 Returns the object associated with an entity. More...
 
object_typeget (const entity_type entt) ENTT_NOEXCEPT
 Returns the object associated with an entity. More...
 
const object_typetry_get (const entity_type entt) const ENTT_NOEXCEPT
 Returns a pointer to the object associated with an entity, if any. More...
 
object_typetry_get (const entity_type entt) ENTT_NOEXCEPT
 Returns a pointer to the object associated with an entity, if any. More...
 
template<typename... Args>
object_typeconstruct (const entity_type entt, Args &&... args)
 Assigns an entity to a storage and constructs its object. More...
 
template<typename It , typename... Args>
iterator_type batch (It first, It last, Args &&... args)
 Assigns one or more entities to a storage and default constructs or copy constructs their objects. More...
 
void destroy (const entity_type entt)
 Removes an entity from a storage and destroys its object. More...
 
void swap (const entity_type lhs, const entity_type rhs) ENTT_NOEXCEPT override
 Swaps entities and objects in the internal packed arrays. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort (iterator_type first, iterator_type last, Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort elements according to the given comparison function. More...
 
void reset ()
 Resets a storage. More...
 
- Public Member Functions inherited from entt::sparse_set< Entity >
 sparse_set ()=default
 Default constructor. More...
 
 sparse_set (const sparse_set &other)
 Copy constructor. More...
 
 sparse_set (sparse_set &&)=default
 Default move constructor. More...
 
virtual ~sparse_set () ENTT_NOEXCEPT=default
 Default destructor. More...
 
sparse_setoperator= (const sparse_set &other)
 Copy assignment operator. More...
 
sparse_setoperator= (sparse_set &&)=default
 Default move assignment operator. More...
 
void reserve (const size_type cap)
 Increases the capacity of a sparse set. More...
 
size_type capacity () const ENTT_NOEXCEPT
 Returns the number of elements that a sparse set has currently allocated space for. More...
 
void shrink_to_fit ()
 Requests the removal of unused capacity. More...
 
size_type extent () const ENTT_NOEXCEPT
 Returns the extent of a sparse set. More...
 
size_type size () const ENTT_NOEXCEPT
 Returns the number of elements in a sparse set. More...
 
bool empty () const ENTT_NOEXCEPT
 Checks whether a sparse set is empty. More...
 
const entity_typedata () const ENTT_NOEXCEPT
 Direct access to the internal packed array. More...
 
iterator_type begin () const ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
iterator_type end () const ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
iterator_type find (const entity_type entt) const ENTT_NOEXCEPT
 Finds an entity. More...
 
bool has (const entity_type entt) const ENTT_NOEXCEPT
 Checks if a sparse set contains an entity. More...
 
size_type index (const entity_type entt) const ENTT_NOEXCEPT
 Returns the position of an entity in a sparse set. More...
 
void construct (const entity_type entt)
 Assigns an entity to a sparse set. More...
 
template<typename It >
void batch (It first, It last)
 Assigns one or more entities to a sparse set. More...
 
void destroy (const entity_type entt)
 Removes an entity from a sparse set. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort (iterator_type first, iterator_type last, Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort elements according to the given comparison function. More...
 
template<typename Apply , typename Compare , typename Sort = std_sort, typename... Args>
void arrange (iterator_type first, iterator_type last, Apply apply, Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort elements according to the given comparison function. More...
 
void respect (const sparse_set &other) ENTT_NOEXCEPT
 Sort entities according to their order in another sparse set. More...
 
void reset ()
 Resets a sparse set. More...
 

Detailed Description

template<typename Entity, typename Type, typename = std::void_t<>>
class entt::basic_storage< Entity, Type, typename >

Basic storage implementation.

This class is a refinement of a sparse set that associates an object to an entity. The main purpose of this class is to extend sparse sets to store components in a registry. It guarantees fast access both to the elements and to the entities.

Note
Entities and objects have the same order. It's guaranteed both in case of raw access (either to entities or objects) and when using random or input access iterators.
Internal data structures arrange elements to maximize performance. Because of that, there are no guarantees that elements have the expected order when iterate directly the internal packed array (see raw and size member functions for that). Use begin and end instead.
Warning
Empty types aren't explicitly instantiated. Temporary objects are returned in place of the instances of the components and raw access isn't available for them.
See also
sparse_set<Entity>
Template Parameters
EntityA valid entity type (see entt_traits for more details).
TypeType of objects assigned to the entities.

Member Typedef Documentation

◆ const_iterator_type

template<typename Entity, typename Type, typename = std::void_t<>>
using entt::basic_storage< Entity, Type, typename >::const_iterator_type = iterator<true>

Constant random access iterator type.

◆ entity_type

template<typename Entity, typename Type, typename = std::void_t<>>
using entt::basic_storage< Entity, Type, typename >::entity_type = Entity

Underlying entity identifier.

◆ iterator_type

template<typename Entity, typename Type, typename = std::void_t<>>
using entt::basic_storage< Entity, Type, typename >::iterator_type = iterator<false>

Random access iterator type.

◆ object_type

template<typename Entity, typename Type, typename = std::void_t<>>
using entt::basic_storage< Entity, Type, typename >::object_type = Type

Type of the objects associated with the entities.

◆ size_type

template<typename Entity, typename Type, typename = std::void_t<>>
using entt::basic_storage< Entity, Type, typename >::size_type = std::size_t

Unsigned integer type.

Member Function Documentation

◆ batch()

template<typename Entity, typename Type, typename = std::void_t<>>
template<typename It , typename... Args>
iterator_type entt::basic_storage< Entity, Type, typename >::batch ( It  first,
It  last,
Args &&...  args 
)
inline

Assigns one or more entities to a storage and default constructs or copy constructs their objects.

The object type must be at least move and default insertable if no arguments are provided, move and copy insertable otherwise.

Warning
Attempting to assign an entity that already belongs to the storage results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the storage already contains the given entity.
Template Parameters
ItType of forward iterator.
ArgsTypes of arguments to use to construct the object.
Parameters
firstAn iterator to the first element of the range of entities.
lastAn iterator past the last element of the range of entities.
argsParameters to use to construct an object for the entities.
Returns
An iterator to the list of instances just created and sorted the same of the entities.

◆ begin() [1/2]

template<typename Entity, typename Type, typename = std::void_t<>>
const_iterator_type entt::basic_storage< Entity, Type, typename >::begin ( ) const
inline

Returns an iterator to the beginning.

The returned iterator points to the first instance of the given type. If the storage is empty, the returned iterator will be equal to end().

Note
Random access iterators stay true to the order imposed by a call to either sort or respect.
Returns
An iterator to the first instance of the given type.

◆ begin() [2/2]

template<typename Entity, typename Type, typename = std::void_t<>>
iterator_type entt::basic_storage< Entity, Type, typename >::begin ( )
inline

Returns an iterator to the beginning.

The returned iterator points to the first instance of the given type. If the storage is empty, the returned iterator will be equal to end().

Note
Random access iterators stay true to the order imposed by a call to either sort or respect.
Returns
An iterator to the first instance of the given type.

◆ cbegin()

template<typename Entity, typename Type, typename = std::void_t<>>
const_iterator_type entt::basic_storage< Entity, Type, typename >::cbegin ( ) const
inline

Returns an iterator to the beginning.

The returned iterator points to the first instance of the given type. If the storage is empty, the returned iterator will be equal to end().

Note
Random access iterators stay true to the order imposed by a call to either sort or respect.
Returns
An iterator to the first instance of the given type.

◆ cend()

template<typename Entity, typename Type, typename = std::void_t<>>
const_iterator_type entt::basic_storage< Entity, Type, typename >::cend ( ) const
inline

Returns an iterator to the end.

The returned iterator points to the element following the last instance of the given type. Attempting to dereference the returned iterator results in undefined behavior.

Note
Random access iterators stay true to the order imposed by a call to either sort or respect.
Returns
An iterator to the element following the last instance of the given type.

◆ construct()

template<typename Entity, typename Type, typename = std::void_t<>>
template<typename... Args>
object_type& entt::basic_storage< Entity, Type, typename >::construct ( const entity_type  entt,
Args &&...  args 
)
inline

Assigns an entity to a storage and constructs its object.

This version accept both types that can be constructed in place directly and types like aggregates that do not work well with a placement new as performed usually under the hood during an emplace back.

Warning
Attempting to use an entity that already belongs to the storage results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the storage already contains the given entity.
Template Parameters
ArgsTypes of arguments to use to construct the object.
Parameters
enttA valid entity identifier.
argsParameters to use to construct an object for the entity.
Returns
The object associated with the entity.

◆ destroy()

template<typename Entity, typename Type, typename = std::void_t<>>
void entt::basic_storage< Entity, Type, typename >::destroy ( const entity_type  entt)
inline

Removes an entity from a storage and destroys its object.

Warning
Attempting to use an entity that doesn't belong to the storage results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the storage doesn't contain the given entity.
Parameters
enttA valid entity identifier.

◆ end() [1/2]

template<typename Entity, typename Type, typename = std::void_t<>>
const_iterator_type entt::basic_storage< Entity, Type, typename >::end ( ) const
inline

Returns an iterator to the end.

The returned iterator points to the element following the last instance of the given type. Attempting to dereference the returned iterator results in undefined behavior.

Note
Random access iterators stay true to the order imposed by a call to either sort or respect.
Returns
An iterator to the element following the last instance of the given type.

◆ end() [2/2]

template<typename Entity, typename Type, typename = std::void_t<>>
iterator_type entt::basic_storage< Entity, Type, typename >::end ( )
inline

Returns an iterator to the end.

The returned iterator points to the element following the last instance of the given type. Attempting to dereference the returned iterator results in undefined behavior.

Note
Random access iterators stay true to the order imposed by a call to either sort or respect.
Returns
An iterator to the element following the last instance of the given type.

◆ get() [1/2]

template<typename Entity, typename Type, typename = std::void_t<>>
const object_type& entt::basic_storage< Entity, Type, typename >::get ( const entity_type  entt) const
inline

Returns the object associated with an entity.

Warning
Attempting to use an entity that doesn't belong to the storage results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the storage doesn't contain the given entity.
Parameters
enttA valid entity identifier.
Returns
The object associated with the entity.

◆ get() [2/2]

template<typename Entity, typename Type, typename = std::void_t<>>
object_type& entt::basic_storage< Entity, Type, typename >::get ( const entity_type  entt)
inline

Returns the object associated with an entity.

Warning
Attempting to use an entity that doesn't belong to the storage results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the storage doesn't contain the given entity.
Parameters
enttA valid entity identifier.
Returns
The object associated with the entity.

◆ raw() [1/2]

template<typename Entity, typename Type, typename = std::void_t<>>
const object_type* entt::basic_storage< Entity, Type, typename >::raw ( ) const
inline

Direct access to the array of objects.

The returned pointer is such that range [raw(), raw() + size()] is always a valid range, even if the container is empty.

Note
There are no guarantees on the order, even though either sort or respect has been previously invoked. Internal data structures arrange elements to maximize performance. Accessing them directly gives a performance boost but less guarantees. Use begin and end if you want to iterate the storage in the expected order.
Returns
A pointer to the array of objects.

◆ raw() [2/2]

template<typename Entity, typename Type, typename = std::void_t<>>
object_type* entt::basic_storage< Entity, Type, typename >::raw ( )
inline

Direct access to the array of objects.

The returned pointer is such that range [raw(), raw() + size()] is always a valid range, even if the container is empty.

Note
There are no guarantees on the order, even though either sort or respect has been previously invoked. Internal data structures arrange elements to maximize performance. Accessing them directly gives a performance boost but less guarantees. Use begin and end if you want to iterate the storage in the expected order.
Returns
A pointer to the array of objects.

◆ reserve()

template<typename Entity, typename Type, typename = std::void_t<>>
void entt::basic_storage< Entity, Type, typename >::reserve ( const size_type  cap)
inline

Increases the capacity of a storage.

If the new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.

Parameters
capDesired capacity.

◆ reset()

template<typename Entity, typename Type, typename = std::void_t<>>
void entt::basic_storage< Entity, Type, typename >::reset ( )
inline

Resets a storage.

◆ shrink_to_fit()

template<typename Entity, typename Type, typename = std::void_t<>>
void entt::basic_storage< Entity, Type, typename >::shrink_to_fit ( )
inline

Requests the removal of unused capacity.

◆ sort()

template<typename Entity, typename Type, typename = std::void_t<>>
template<typename Compare , typename Sort = std_sort, typename... Args>
void entt::basic_storage< Entity, Type, typename >::sort ( iterator_type  first,
iterator_type  last,
Compare  compare,
Sort  algo = Sort{},
Args &&...  args 
)
inline

Sort elements according to the given comparison function.

Sort the elements so that iterating the range with a couple of iterators returns them in the expected order. See begin and end for more details.

The comparison function object must return true if the first element is less than the second one, false otherwise. The signature of the comparison function should be equivalent to one of the following:

bool(const Entity, const Entity);
bool(const Type &, const Type &);

Moreover, the comparison function object shall induce a strict weak ordering on the values.

The sort function oject must offer a member function template operator() that accepts three arguments:

  • An iterator to the first element of the range to sort.
  • An iterator past the last element of the range to sort.
  • A comparison function to use to compare the elements.
Note
Attempting to iterate elements using a raw pointer returned by a call to either data or raw gives no guarantees on the order, even though sort has been invoked.
Warning
Empty types are never instantiated. Therefore, only comparison function objects that require to return entities rather than components are accepted.
Template Parameters
CompareType of comparison function object.
SortType of sort function object.
ArgsTypes of arguments to forward to the sort function object.
Parameters
firstAn iterator to the first element of the range to sort.
lastAn iterator past the last element of the range to sort.
compareA valid comparison function object.
algoA valid sort function object.
argsArguments to forward to the sort function object, if any.

◆ swap()

template<typename Entity, typename Type, typename = std::void_t<>>
void entt::basic_storage< Entity, Type, typename >::swap ( const entity_type  lhs,
const entity_type  rhs 
)
inlineoverridevirtual

Swaps entities and objects in the internal packed arrays.

Warning
Attempting to swap entities that don't belong to the sparse set results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the sparse set doesn't contain the given entities.
Parameters
lhsA valid entity identifier.
rhsA valid entity identifier.

Reimplemented from entt::sparse_set< Entity >.

◆ try_get() [1/2]

template<typename Entity, typename Type, typename = std::void_t<>>
const object_type* entt::basic_storage< Entity, Type, typename >::try_get ( const entity_type  entt) const
inline

Returns a pointer to the object associated with an entity, if any.

Parameters
enttA valid entity identifier.
Returns
The object associated with the entity, if any.

◆ try_get() [2/2]

template<typename Entity, typename Type, typename = std::void_t<>>
object_type* entt::basic_storage< Entity, Type, typename >::try_get ( const entity_type  entt)
inline

Returns a pointer to the object associated with an entity, if any.

Parameters
enttA valid entity identifier.
Returns
The object associated with the entity, if any.

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