EnTT  3.6.0
Public Types | Public Member Functions | List of all members
entt::default_pool< Entity, Type > Struct Template Referencefinal

Default pool implementation. More...

#include <pool.hpp>

Inheritance diagram for entt::default_pool< Entity, Type >:
Inheritance graph
[legend]
Collaboration diagram for entt::default_pool< Entity, Type >:
Collaboration graph
[legend]

Public Types

using object_type = Type
 Type of the objects associated with the entities.
 
using entity_type = Entity
 Underlying entity identifier.
 
- Public Types inherited from entt::storage< Entity, Type, typename >
using object_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< false >
 Random access iterator type.
 
using const_iterator = storage_iterator< true >
 Constant random access iterator type.
 
using reverse_iterator = Type *
 Reverse iterator type.
 
using const_reverse_iterator = const Type *
 Constant reverse iterator type.
 
- Public Types inherited from entt::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

auto on_construct () noexcept
 Returns a sink object. More...
 
auto on_update () noexcept
 Returns a sink object for the given type. More...
 
auto on_destroy () noexcept
 Returns a sink object for the given type. More...
 
template<typename... Args>
decltype(auto) emplace (const entity_type entity, Args &&... args)
 Assigns an entity to a pool. More...
 
template<typename It , typename... Args>
void insert (It first, It last, Args &&... args)
 Assigns multiple entities to a pool. More...
 
void erase (const entity_type entity) override
 Removes an entity from a pool. More...
 
template<typename It >
void erase (It first, It last)
 Removes multiple entities from a pool. More...
 
template<typename... Func>
decltype(auto) patch (const entity_type entity, [[maybe_unused]] Func &&... func)
 Patches the given instance for an entity. More...
 
decltype(auto) replace (const entity_type entity, object_type value)
 Replaces the object associated with an entity in a pool. More...
 
- Public Member Functions inherited from entt::storage< Entity, Type, typename >
void reserve (const size_type cap)
 Increases the capacity of a storage. More...
 
void shrink_to_fit ()
 Requests the removal of unused capacity.
 
const object_type * raw () const noexcept
 Direct access to the array of objects. More...
 
object_type * raw () noexcept
 Direct access to the array of objects. More...
 
const_iterator cbegin () const noexcept
 Returns an iterator to the beginning. More...
 
const_iterator begin () const noexcept
 Returns an iterator to the beginning. More...
 
iterator begin () noexcept
 Returns an iterator to the beginning. More...
 
const_iterator cend () const noexcept
 Returns an iterator to the end. More...
 
const_iterator end () const noexcept
 Returns an iterator to the end. More...
 
iterator end () noexcept
 Returns an iterator to the end. More...
 
const_reverse_iterator crbegin () const noexcept
 Returns a reverse iterator to the beginning. More...
 
const_reverse_iterator rbegin () const noexcept
 Returns a reverse iterator to the beginning. More...
 
reverse_iterator rbegin () noexcept
 Returns a reverse iterator to the beginning. More...
 
const_reverse_iterator crend () const noexcept
 Returns a reverse iterator to the end. More...
 
const_reverse_iterator rend () const noexcept
 Returns a reverse iterator to the end. More...
 
reverse_iterator rend () noexcept
 Returns a reverse iterator to the end. More...
 
const object_type & get (const entity_type entt) const
 Returns the object associated with an entity. More...
 
object_type & get (const entity_type entt)
 Returns the object associated with an entity. More...
 
const object_type * try_get (const entity_type entt) const
 Returns a pointer to the object associated with an entity, if any. More...
 
object_type * try_get (const entity_type entt)
 Returns a pointer to the object associated with an entity, if any. More...
 
template<typename... Args>
void emplace (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 object_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...
 
void erase (const entity_type entt) override
 Removes an entity from a storage and destroys its object. More...
 
void swap (const entity_type lhs, const entity_type rhs) override
 Swaps entities and objects in the internal packed arrays. More...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort (iterator first, iterator last, Compare compare, Sort algo=Sort{}, Args &&... args)
 Sort elements according to the given comparison function. More...
 
void clear ()
 Clears a storage.
 
- Public Member Functions inherited from entt::sparse_set< Entity >
 sparse_set ()=default
 Default constructor.
 
 sparse_set (sparse_set &&)=default
 Default move constructor.
 
virtual ~sparse_set ()=default
 Default destructor.
 
sparse_set & operator= (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 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 noexcept
 Returns the extent of a sparse set. More...
 
size_type size () const noexcept
 Returns the number of elements in a sparse set. More...
 
bool empty () const noexcept
 Checks whether a sparse set is empty. More...
 
const entity_type * data () const noexcept
 Direct access to the internal packed array. More...
 
iterator begin () const noexcept
 Returns an iterator to the beginning. More...
 
iterator end () const noexcept
 Returns an iterator to the end. More...
 
reverse_iterator rbegin () const noexcept
 Returns a reverse iterator to the beginning. More...
 
reverse_iterator rend () const 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...
 
template<typename Compare , typename Sort = std_sort, typename... Args>
void sort (iterator first, iterator 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 first, iterator 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)
 Sort entities according to their order in another sparse set. More...
 
void clear () noexcept
 Clears a sparse set.
 

Detailed Description

template<typename Entity, typename Type>
struct entt::default_pool< Entity, Type >

Default pool implementation.

Template Parameters
EntityA valid entity type (see entt_traits for more details).
TypeType of objects assigned to the entities.

Definition at line 23 of file pool.hpp.

Member Function Documentation

◆ emplace()

template<typename Entity , typename Type >
template<typename... Args>
decltype(auto) entt::default_pool< Entity, Type >::emplace ( const entity_type  entity,
Args &&...  args 
)
inline

Assigns an entity to a pool.

A new object is created and initialized with the arguments provided (the object type must have a proper constructor or be of aggregate type). Then the instance is assigned to the given entity.

Warning
Attempting to use an invalid entity or to assign an entity that already belongs to the pool results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity already belongs to the pool.
Template Parameters
ArgsTypes of arguments to use to construct the object.
Parameters
entityA valid entity identifier.
argsParameters to use to initialize the object.
Returns
A reference to the newly created object.

Definition at line 115 of file pool.hpp.

◆ erase() [1/2]

template<typename Entity , typename Type >
void entt::default_pool< Entity, Type >::erase ( const entity_type  entity)
inlineoverridevirtual

Removes an entity from a pool.

Warning
Attempting to use an invalid entity or to remove an entity that doesn't belong to the pool results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't belong to the pool.
Parameters
entityA valid entity identifier.

Reimplemented from entt::sparse_set< Entity >.

Definition at line 157 of file pool.hpp.

◆ erase() [2/2]

template<typename Entity , typename Type >
template<typename It >
void entt::default_pool< Entity, Type >::erase ( It  first,
It  last 
)
inline

Removes multiple entities from a pool.

See also
remove
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.

Definition at line 172 of file pool.hpp.

◆ insert()

template<typename Entity , typename Type >
template<typename It , typename... Args>
void entt::default_pool< Entity, Type >::insert ( It  first,
It  last,
Args &&...  args 
)
inline

Assigns multiple entities to a pool.

See also
emplace
Template Parameters
ItType of input 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 initialize the object.

Definition at line 136 of file pool.hpp.

◆ on_construct()

template<typename Entity , typename Type >
auto entt::default_pool< Entity, Type >::on_construct ( )
inlinenoexcept

Returns a sink object.

The sink returned by this function can be used to receive notifications whenever a new instance is created and assigned to an entity.
The function type for a listener is equivalent to:

void(Entity);

Listeners are invoked after the object has been assigned to the entity.

See also
sink
Returns
A temporary sink object.

Definition at line 49 of file pool.hpp.

◆ on_destroy()

template<typename Entity , typename Type >
auto entt::default_pool< Entity, Type >::on_destroy ( )
inlinenoexcept

Returns a sink object for the given type.

The sink returned by this function can be used to receive notifications whenever an instance is removed from an entity and thus destroyed.
The function type for a listener is equivalent to:

void(Entity);

Listeners are invoked before the object has been removed from the entity.

See also
sink
Returns
A temporary sink object.

Definition at line 92 of file pool.hpp.

◆ on_update()

template<typename Entity , typename Type >
auto entt::default_pool< Entity, Type >::on_update ( )
inlinenoexcept

Returns a sink object for the given type.

The sink returned by this function can be used to receive notifications whenever an instance is explicitly updated.
The function type for a listener is equivalent to:

void(Entity);

Listeners are invoked after the object has been updated.

See also
sink
Returns
A temporary sink object.

Definition at line 70 of file pool.hpp.

◆ patch()

template<typename Entity , typename Type >
template<typename... Func>
decltype(auto) entt::default_pool< Entity, Type >::patch ( const entity_type  entity,
[[maybe_unused] ] Func &&...  func 
)
inline

Patches the given instance for an entity.

The signature of the functions should be equivalent to the following:

void(Type &);
Note
Empty types aren't explicitly instantiated and therefore they are never returned. However, this function can be used to trigger an update signal for them.
Warning
Attempting to use an invalid entity or to patch an object of an entity that doesn't belong to the pool results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't belong to the pool.
Template Parameters
FuncTypes of the function objects to invoke.
Parameters
entityA valid entity identifier.
funcValid function objects.
Returns
A reference to the patched instance.

Definition at line 214 of file pool.hpp.

◆ replace()

template<typename Entity , typename Type >
decltype(auto) entt::default_pool< Entity, Type >::replace ( const entity_type  entity,
object_type  value 
)
inline

Replaces the object associated with an entity in a pool.

A new object is created and initialized with the arguments provided (the object type must have a proper constructor or be of aggregate type). Then the instance is assigned to the given entity.

Warning
Attempting to use an invalid entity or to replace an object of an entity that doesn't belong to the pool results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't belong to the pool.
Parameters
entityA valid entity identifier.
valueAn instance of the type to assign.
Returns
A reference to the object being replaced.

Definition at line 241 of file pool.hpp.


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