Clementine
Classes | Public Types | Public Member Functions | Friends | List of all members
entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... > Class Template Referencefinal

Owning group. More...

#include <entt.hpp>

Public Types

using entity_type = Entity
 Underlying entity identifier.
 
using size_type = std::size_t
 Unsigned integer type.
 
using iterator = typename basic_sparse_set< Entity >::iterator
 Random access iterator type.
 
using reverse_iterator = typename basic_sparse_set< Entity >::reverse_iterator
 Reversed iterator type.
 

Public Member Functions

 basic_group () ENTT_NOEXCEPT
 Default constructor to use to create empty, invalid groups.
 
size_type size () const ENTT_NOEXCEPT
 Returns the number of entities that have the given components. More...
 
bool empty () const ENTT_NOEXCEPT
 Checks whether a group is empty. More...
 
template<typename Component >
Component * raw () const ENTT_NOEXCEPT
 Direct access to the list of components of a given pool. More...
 
const entity_typedata () const ENTT_NOEXCEPT
 Direct access to the list of entities. More...
 
iterator begin () const ENTT_NOEXCEPT
 Returns an iterator to the first entity of the group. More...
 
iterator end () const ENTT_NOEXCEPT
 Returns an iterator that is past the last entity of the group. More...
 
reverse_iterator rbegin () const ENTT_NOEXCEPT
 Returns an iterator to the first entity of the reversed group. More...
 
reverse_iterator rend () const ENTT_NOEXCEPT
 Returns an iterator that is past the last entity of the reversed group. More...
 
entity_type front () const
 Returns the first entity of the group, if any. More...
 
entity_type back () const
 Returns the last entity of the group, if any. More...
 
iterator find (const entity_type entt) const
 Finds an entity. More...
 
entity_type operator[] (const size_type pos) const
 Returns the identifier that occupies the given position. More...
 
 operator bool () const ENTT_NOEXCEPT
 Checks if a group is properly initialized. More...
 
bool contains (const entity_type entt) const
 Checks if a group contains an entity. More...
 
template<typename... Component>
decltype(auto) get (const entity_type entt) const
 Returns the components assigned to the given entity. More...
 
template<typename Func >
void each (Func func) const
 Iterates entities and components and applies the given function object to them. More...
 
iterable_group each () const ENTT_NOEXCEPT
 Returns an iterable object to use to visit the group. More...
 
template<typename... Component, typename Compare , typename Sort = std_sort, typename... Args>
void sort (Compare compare, Sort algo=Sort{}, Args &&... args) const
 Sort a group according to the given comparison function. More...
 

Friends

class basic_registry< Entity >
 A registry is allowed to create groups.
 

Detailed Description

template<typename Entity, typename... Exclude, typename... Get, typename... Owned>
class entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >

Owning group.

Owning groups return all entities and only the entities that have at least the given components. Moreover:

The more types of components are owned by a group, the faster it is to iterate them.

Important

Iterators aren't invalidated if:

In all other cases, modifying the pools iterated by the group in any way invalidates all the iterators and using them results in undefined behavior.

Note
Groups share references to the underlying data structures of the registry that generated them. Therefore any change to the entities and to the components made by means of the registry are immediately reflected by all the groups. Moreover, sorting an owning group affects all the instance of the same group (it means that users don't have to call sort on each instance to sort all of them because they share the underlying data structure).
Warning
Lifetime of a group must not overcome that of the registry that generated it. In any other case, attempting to use a group results in undefined behavior.
Template Parameters
EntityA valid entity type (see entt_traits for more details).
ExcludeTypes of components used to filter the group.
GetTypes of components observed by the group.
OwnedTypes of components owned by the group.

Member Function Documentation

◆ back()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
entity_type entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::back ( ) const
inline

Returns the last entity of the group, if any.

Returns
The last entity of the group if one exists, the null entity otherwise.

◆ begin()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
iterator entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::begin ( ) const
inline

Returns an iterator to the first entity of the group.

The returned iterator points to the first entity of the group. If the group is empty, the returned iterator will be equal to end().

Returns
An iterator to the first entity of the group.

◆ contains()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
bool entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::contains ( const entity_type  entt) const
inline

Checks if a group contains an entity.

Parameters
enttA valid entity identifier.
Returns
True if the group contains the given entity, false otherwise.

◆ data()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
const entity_type* entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::data ( ) const
inline

Direct access to the list of entities.

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

Returns
A pointer to the array of entities.

◆ each() [1/2]

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
template<typename Func >
void entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::each ( Func  func) const
inline

Iterates entities and components and applies the given function object to them.

The function object is invoked for each entity. It is provided with the entity itself and a set of references to non-empty components. The constness of the components is as requested.
The signature of the function must be equivalent to one of the following forms:

void(const entity_type, Type &...);
void(Type &...);
Note
Empty types aren't explicitly instantiated and therefore they are never returned during iterations.
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

◆ each() [2/2]

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
iterable_group entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::each ( ) const
inline

Returns an iterable object to use to visit the group.

The iterable object returns tuples that contain the current entity and a set of references to its non-empty components. The constness of the components is as requested.

Note
Empty types aren't explicitly instantiated and therefore they are never returned during iterations.
Returns
An iterable object to use to visit the group.

◆ empty()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
bool entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::empty ( ) const
inline

Checks whether a group is empty.

Returns
True if the group is empty, false otherwise.

◆ end()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
iterator entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::end ( ) const
inline

Returns an iterator that is past the last entity of the group.

The returned iterator points to the entity following the last entity of the group. Attempting to dereference the returned iterator results in undefined behavior.

Returns
An iterator to the entity following the last entity of the group.

◆ find()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
iterator entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::find ( const entity_type  entt) const
inline

Finds an entity.

Parameters
enttA valid entity identifier.
Returns
An iterator to the given entity if it's found, past the end iterator otherwise.

◆ front()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
entity_type entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::front ( ) const
inline

Returns the first entity of the group, if any.

Returns
The first entity of the group if one exists, the null entity otherwise.

◆ get()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
template<typename... Component>
decltype(auto) entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::get ( const entity_type  entt) const
inline

Returns the components assigned to the given entity.

Prefer this function instead of registry::get during iterations. It has far better performance than its counterpart.

Warning
Attempting to use an invalid component type results in a compilation error. Attempting to use an entity that doesn't belong to the group results in undefined behavior.
Template Parameters
ComponentTypes of components to get.
Parameters
enttA valid entity identifier.
Returns
The components assigned to the entity.

◆ operator bool()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::operator bool ( ) const
inlineexplicit

Checks if a group is properly initialized.

Returns
True if the group is properly initialized, false otherwise.

◆ operator[]()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
entity_type entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::operator[] ( const size_type  pos) const
inline

Returns the identifier that occupies the given position.

Parameters
posPosition of the element to return.
Returns
The identifier that occupies the given position.

◆ raw()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
template<typename Component >
Component* entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::raw ( ) const
inline

Direct access to the list of components of a given pool.

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

Warning
This function is only available for owned types.
Template Parameters
ComponentType of component in which one is interested.
Returns
A pointer to the array of components.

◆ rbegin()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
reverse_iterator entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::rbegin ( ) const
inline

Returns an iterator to the first entity of the reversed group.

The returned iterator points to the first entity of the reversed group. If the group is empty, the returned iterator will be equal to rend().

Returns
An iterator to the first entity of the reversed group.

◆ rend()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
reverse_iterator entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::rend ( ) const
inline

Returns an iterator that is past the last entity of the reversed group.

The returned iterator points to the entity following the last entity of the reversed group. Attempting to dereference the returned iterator results in undefined behavior.

Returns
An iterator to the entity following the last entity of the reversed group.

◆ size()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
size_type entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::size ( ) const
inline

Returns the number of entities that have the given components.

Returns
Number of entities that have the given components.

◆ sort()

template<typename Entity , typename... Exclude, typename... Get, typename... Owned>
template<typename... Component, typename Compare , typename Sort = std_sort, typename... Args>
void entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... >::sort ( Compare  compare,
Sort  algo = Sort{},
Args &&...  args 
) const
inline

Sort a group according to the given comparison function.

Sort the group so that iterating it with a couple of iterators returns entities and components 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(std::tuple<Component &...>, std::tuple<Component &...>);
bool(const Component &, const Component &);
bool(const Entity, const Entity);

Where Component are either owned types or not but still such that they are iterated by the group.
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.
Template Parameters
ComponentOptional types of components to compare.
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.

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