Clementine
Classes | Public Types | Public Member Functions | List of all members
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 >:
Inheritance graph
[legend]
Collaboration diagram for entt::basic_storage< Entity, Type, typename >:
Collaboration graph
[legend]

Public Types

using value_type = Type
 Type of the objects associated with the entities.
 
using entity_type = Entity
 Underlying entity identifier.
 
using size_type = std::size_t
 Unsigned integer type.
 
using iterator = storage_iterator< Type >
 Random access iterator type.
 
using const_iterator = storage_iterator< const Type >
 Constant random access iterator type.
 
using reverse_iterator = Type *
 Reverse iterator type.
 
using const_reverse_iterator = const Type *
 Constant reverse iterator type.
 
using storage_category = dense_storage_tag
 Storage category.
 
- Public Types inherited from entt::basic_sparse_set< Entity >
using entity_type = Entity
 Underlying entity identifier.
 
using size_type = std::size_t
 Unsigned integer type.
 
using iterator = sparse_set_iterator
 Random access iterator type.
 
using reverse_iterator = const entity_type *
 Reverse iterator type.
 

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.
 
const value_typeraw () const ENTT_NOEXCEPT
 Direct access to the array of objects. More...
 
value_typeraw () ENTT_NOEXCEPT
 Direct access to the array of objects. More...
 
const_iterator cbegin () const ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
const_iterator begin () const ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
iterator begin () ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
const_iterator cend () const ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
const_iterator end () const ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
iterator end () ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
const_reverse_iterator crbegin () const ENTT_NOEXCEPT
 Returns a reverse iterator to the beginning. More...
 
const_reverse_iterator rbegin () const ENTT_NOEXCEPT
 Returns a reverse iterator to the beginning. More...
 
reverse_iterator rbegin () ENTT_NOEXCEPT
 Returns a reverse iterator to the beginning. More...
 
const_reverse_iterator crend () const ENTT_NOEXCEPT
 Returns a reverse iterator to the end. More...
 
const_reverse_iterator rend () const ENTT_NOEXCEPT
 Returns a reverse iterator to the end. More...
 
reverse_iterator rend () ENTT_NOEXCEPT
 Returns a reverse iterator to the end. More...
 
const value_typeget (const entity_type entt) const
 Returns the object associated with an entity. More...
 
value_typeget (const entity_type entt)
 Returns the object associated with an entity. More...
 
template<typename... Args>
value_typeemplace (const entity_type entt, Args &&... args)
 Assigns an entity to a storage and constructs its object. More...
 
template<typename It >
void insert (It first, It last, const value_type &value={})
 Assigns one or more entities to a storage and constructs their objects from a given instance. More...
 
template<typename EIt , typename CIt >
void insert (EIt first, EIt last, CIt from, CIt to)
 Assigns one or more entities to a storage and constructs their objects from a given range. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort_n (const size_type count, Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort elements according to the given comparison function. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort (Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort all elements according to the given comparison function. More...
 
- Public Member Functions inherited from entt::basic_sparse_set< Entity >
 basic_sparse_set ()=default
 Default constructor.
 
 basic_sparse_set (basic_sparse_set &&)=default
 Default move constructor.
 
virtual ~basic_sparse_set ()=default
 Default destructor.
 
basic_sparse_setoperator= (basic_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.
 
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 begin () const ENTT_NOEXCEPT
 Returns an iterator to the beginning. More...
 
iterator end () const ENTT_NOEXCEPT
 Returns an iterator to the end. More...
 
reverse_iterator rbegin () const ENTT_NOEXCEPT
 Returns a reverse iterator to the beginning. More...
 
reverse_iterator rend () const ENTT_NOEXCEPT
 Returns a reverse iterator to the end. More...
 
iterator find (const entity_type entt) const
 Finds an entity. More...
 
bool contains (const entity_type entt) const
 Checks if a sparse set contains an entity. More...
 
size_type index (const entity_type entt) const
 Returns the position of an entity in a sparse set. More...
 
void emplace (const entity_type entt)
 Assigns an entity to a sparse set. More...
 
template<typename It >
void insert (It first, It last)
 Assigns one or more entities to a sparse set. More...
 
void remove (const entity_type entt)
 Removes an entity from a sparse set. More...
 
template<typename It >
void remove (It first, It last)
 Removes multiple entities from a pool. More...
 
void swap (const entity_type lhs, const entity_type rhs)
 Swaps two entities in the internal packed array. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort_n (const size_type count, Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort the first count elements according to the given comparison function. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort (Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort all elements according to the given comparison function. More...
 
void respect (const basic_sparse_set &other)
 Sort entities according to their order in another sparse set. More...
 
void clear () ENTT_NOEXCEPT
 Clears a sparse set.
 

Detailed Description

template<typename Entity, typename Type, typename = void>
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. There are no guarantees that objects are returned in the insertion order when iterate a storage. Do not make assumption on the order in any case.
Warning
Empty types aren't explicitly instantiated. Therefore, many of the functions normally available for non-empty types will not be available for empty ones.
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 Function Documentation

◆ begin() [1/2]

template<typename Entity, typename Type, typename = void>
const_iterator 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 internal array. If the storage is empty, the returned iterator will be equal to end().

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

◆ begin() [2/2]

template<typename Entity, typename Type, typename = void>
iterator entt::basic_storage< Entity, Type, typename >::begin ( )
inline

Returns an iterator to the beginning.

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

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

◆ cbegin()

template<typename Entity, typename Type, typename = void>
const_iterator 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 internal array. If the storage is empty, the returned iterator will be equal to end().

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

◆ cend()

template<typename Entity, typename Type, typename = void>
const_iterator 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 internal array. Attempting to dereference the returned iterator results in undefined behavior.

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

◆ crbegin()

template<typename Entity, typename Type, typename = void>
const_reverse_iterator entt::basic_storage< Entity, Type, typename >::crbegin ( ) const
inline

Returns a reverse iterator to the beginning.

The returned iterator points to the first instance of the reversed internal array. If the storage is empty, the returned iterator will be equal to rend().

Returns
An iterator to the first instance of the reversed internal array.

◆ crend()

template<typename Entity, typename Type, typename = void>
const_reverse_iterator entt::basic_storage< Entity, Type, typename >::crend ( ) const
inline

Returns a reverse iterator to the end.

The returned iterator points to the element following the last instance of the reversed internal array. Attempting to dereference the returned iterator results in undefined behavior.

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

◆ emplace()

template<typename Entity, typename Type, typename = void>
template<typename... Args>
value_type& entt::basic_storage< Entity, Type, typename >::emplace ( 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.
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
A reference to the newly created object.

◆ end() [1/2]

template<typename Entity, typename Type, typename = void>
const_iterator 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 internal array. Attempting to dereference the returned iterator results in undefined behavior.

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

◆ end() [2/2]

template<typename Entity, typename Type, typename = void>
iterator 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 internal array. Attempting to dereference the returned iterator results in undefined behavior.

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

◆ get() [1/2]

template<typename Entity, typename Type, typename = void>
const value_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.
Parameters
enttA valid entity identifier.
Returns
The object associated with the entity.

◆ get() [2/2]

template<typename Entity, typename Type, typename = void>
value_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.
Parameters
enttA valid entity identifier.
Returns
The object associated with the entity.

◆ insert() [1/2]

template<typename Entity, typename Type, typename = void>
template<typename It >
void entt::basic_storage< Entity, Type, typename >::insert ( It  first,
It  last,
const value_type value = {} 
)
inline

Assigns one or more entities to a storage and constructs their objects from a given instance.

Warning
Attempting to assign an entity that already belongs to the storage results in undefined behavior.
Template Parameters
ItType of input iterator.
Parameters
firstAn iterator to the first element of the range of entities.
lastAn iterator past the last element of the range of entities.
valueAn instance of the object to construct.

◆ insert() [2/2]

template<typename Entity, typename Type, typename = void>
template<typename EIt , typename CIt >
void entt::basic_storage< Entity, Type, typename >::insert ( EIt  first,
EIt  last,
CIt  from,
CIt  to 
)
inline

Assigns one or more entities to a storage and constructs their objects from a given range.

See also
construct
Template Parameters
EItType of input iterator.
CItType of input iterator.
Parameters
firstAn iterator to the first element of the range of entities.
lastAn iterator past the last element of the range of entities.
fromAn iterator to the first element of the range of objects.
toAn iterator past the last element of the range of objects.

◆ raw() [1/2]

template<typename Entity, typename Type, typename = void>
const value_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
Objects are in the reverse order as returned by the begin/end iterators.
Returns
A pointer to the array of objects.

◆ raw() [2/2]

template<typename Entity, typename Type, typename = void>
value_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
Objects are in the reverse order as returned by the begin/end iterators.
Returns
A pointer to the array of objects.

◆ rbegin() [1/2]

template<typename Entity, typename Type, typename = void>
const_reverse_iterator entt::basic_storage< Entity, Type, typename >::rbegin ( ) const
inline

Returns a reverse iterator to the beginning.

The returned iterator points to the first instance of the reversed internal array. If the storage is empty, the returned iterator will be equal to rend().

Returns
An iterator to the first instance of the reversed internal array.

◆ rbegin() [2/2]

template<typename Entity, typename Type, typename = void>
reverse_iterator entt::basic_storage< Entity, Type, typename >::rbegin ( )
inline

Returns a reverse iterator to the beginning.

The returned iterator points to the first instance of the reversed internal array. If the storage is empty, the returned iterator will be equal to rend().

Returns
An iterator to the first instance of the reversed internal array.

◆ rend() [1/2]

template<typename Entity, typename Type, typename = void>
const_reverse_iterator entt::basic_storage< Entity, Type, typename >::rend ( ) const
inline

Returns a reverse iterator to the end.

The returned iterator points to the element following the last instance of the reversed internal array. Attempting to dereference the returned iterator results in undefined behavior.

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

◆ rend() [2/2]

template<typename Entity, typename Type, typename = void>
reverse_iterator entt::basic_storage< Entity, Type, typename >::rend ( )
inline

Returns a reverse iterator to the end.

The returned iterator points to the element following the last instance of the reversed internal array. Attempting to dereference the returned iterator results in undefined behavior.

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

◆ reserve()

template<typename Entity, typename Type, typename = void>
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.

◆ sort()

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

Sort all elements according to the given comparison function.

See also
sort_n
Template Parameters
CompareType of comparison function object.
SortType of sort function object.
ArgsTypes of arguments to forward to the sort function object.
Parameters
compareA valid comparison function object.
algoA valid sort function object.
argsArguments to forward to the sort function object, if any.

◆ sort_n()

template<typename Entity, typename Type, typename = void>
template<typename Compare , typename Sort = std_sort, typename... Args>
void entt::basic_storage< Entity, Type, typename >::sort_n ( const size_type  count,
Compare  compare,
Sort  algo = Sort{},
Args &&...  args 
)
inline

Sort elements according to the given comparison function.

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.
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
countNumber of elements to sort.
compareA valid comparison function object.
algoA valid sort function object.
argsArguments to forward to the sort function object, if any.

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