OpenLexocad  27.0
entt::basic_view< Entity, exclude_t<>, Component > Class Template Reference

Single component view specialization. More...

#include <entt.hpp>

Public Types

using raw_type = Component
 Type of component iterated by the view. More...
 
using entity_type = Entity
 Underlying entity identifier. More...
 
using size_type = std::size_t
 Unsigned integer type. More...
 
using iterator_type = typename sparse_set< Entity >::iterator_type
 Input iterator type. More...
 

Public Member Functions

size_type size () const ENTT_NOEXCEPT
 Returns the number of entities that have the given component. More...
 
bool empty () const ENTT_NOEXCEPT
 Checks whether the view is empty. More...
 
raw_typeraw () const ENTT_NOEXCEPT
 Direct access to the list of components. More...
 
const entity_typedata () const ENTT_NOEXCEPT
 Direct access to the list of entities. More...
 
iterator_type begin () const ENTT_NOEXCEPT
 Returns an iterator to the first entity that has the given component. More...
 
iterator_type end () const ENTT_NOEXCEPT
 Returns an iterator that is past the last entity that has the given component. More...
 
iterator_type find (const entity_type entt) const ENTT_NOEXCEPT
 Finds an entity. More...
 
entity_type operator[] (const size_type pos) const ENTT_NOEXCEPT
 Returns the identifier that occupies the given position. More...
 
bool contains (const entity_type entt) const ENTT_NOEXCEPT
 Checks if a view contains an entity. More...
 
template<typename Comp = Component>
decltype(auto) get (const entity_type entt) const ENTT_NOEXCEPT
 Returns the component 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...
 
template<typename Func >
void less (Func func) const
 Iterates entities and components and applies the given function object to them. More...
 

Friends

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

Detailed Description

template<typename Entity, typename Component>
class entt::basic_view< Entity, exclude_t<>, Component >

Single component view specialization.

Single component views are specialized in order to get a boost in terms of performance. This kind of views can access the underlying data structure directly and avoid superfluous checks.
Order of elements during iterations are highly dependent on the order of the underlying data structure. See sparse_set for more details.

Important

Iterators aren't invalidated if:

  • New instances of the given component are created and assigned to entities.
  • The entity currently pointed is modified (as an example, the given component is removed from the entity to which the iterator points).
  • The entity currently pointed is destroyed.

In all the other cases, modifying the pool of the given component in any way invalidates all the iterators and using them results in undefined behavior.

Note
Views share a reference to the underlying data structure 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 views.
Warning
Lifetime of a view must overcome the one of the registry that generated it. In any other case, attempting to use a view results in undefined behavior.
Template Parameters
EntityA valid entity type (see entt_traits for more details).
ComponentType of component iterated by the view.

Member Typedef Documentation

◆ entity_type

template<typename Entity , typename Component >
using entt::basic_view< Entity, exclude_t<>, Component >::entity_type = Entity

Underlying entity identifier.

◆ iterator_type

template<typename Entity , typename Component >
using entt::basic_view< Entity, exclude_t<>, Component >::iterator_type = typename sparse_set<Entity>::iterator_type

Input iterator type.

◆ raw_type

template<typename Entity , typename Component >
using entt::basic_view< Entity, exclude_t<>, Component >::raw_type = Component

Type of component iterated by the view.

◆ size_type

template<typename Entity , typename Component >
using entt::basic_view< Entity, exclude_t<>, Component >::size_type = std::size_t

Unsigned integer type.

Member Function Documentation

◆ begin()

template<typename Entity , typename Component >
iterator_type entt::basic_view< Entity, exclude_t<>, Component >::begin ( ) const
inline

Returns an iterator to the first entity that has the given component.

The returned iterator points to the first entity that has the given component. If the view is empty, the returned iterator will be equal to end().

Note
Input iterators stay true to the order imposed to the underlying data structures.
Returns
An iterator to the first entity that has the given component.

◆ contains()

template<typename Entity , typename Component >
bool entt::basic_view< Entity, exclude_t<>, Component >::contains ( const entity_type  entt) const
inline

Checks if a view contains an entity.

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

◆ data()

template<typename Entity , typename Component >
const entity_type* entt::basic_view< Entity, exclude_t<>, Component >::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.

Note
There are no guarantees on the order of the entities. Use begin and end if you want to iterate the view in the expected order.
Returns
A pointer to the array of entities.

◆ each()

template<typename Entity , typename Component >
template<typename Func >
void entt::basic_view< Entity, exclude_t<>, Component >::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 reference to its component. The constness of the component is as requested.
The signature of the function must be equivalent to one of the following forms:

void(const entity_type, Component &);
void(Component &);
Note
Empty types aren't explicitly instantiated. Therefore, temporary objects are returned during iterations. They can be caught only by copy or with const references.
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

◆ empty()

template<typename Entity , typename Component >
bool entt::basic_view< Entity, exclude_t<>, Component >::empty ( ) const
inline

Checks whether the view is empty.

Returns
True if the view is empty, false otherwise.

◆ end()

template<typename Entity , typename Component >
iterator_type entt::basic_view< Entity, exclude_t<>, Component >::end ( ) const
inline

Returns an iterator that is past the last entity that has the given component.

The returned iterator points to the entity following the last entity that has the given component. Attempting to dereference the returned iterator results in undefined behavior.

Note
Input iterators stay true to the order imposed to the underlying data structures.
Returns
An iterator to the entity following the last entity that has the given component.

◆ find()

template<typename Entity , typename Component >
iterator_type entt::basic_view< Entity, exclude_t<>, Component >::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.

◆ get()

template<typename Entity , typename Component >
template<typename Comp = Component>
decltype(auto) entt::basic_view< Entity, exclude_t<>, Component >::get ( const entity_type  entt) const
inline

Returns the component assigned to the given entity.

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

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

◆ less()

template<typename Entity , typename Component >
template<typename Func >
void entt::basic_view< Entity, exclude_t<>, Component >::less ( 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 reference to its component if it's a non-empty one. The constness of the component is as requested.
The signature of the function must be equivalent to one of the following forms in case the component isn't an empty one:

void(const entity_type, Component &);
void(Component &);

In case the component is an empty one instead, the following forms are accepted:

void(const entity_type);
void();
See also
each
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

◆ operator[]()

template<typename Entity , typename Component >
entity_type entt::basic_view< Entity, exclude_t<>, Component >::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 Component >
raw_type* entt::basic_view< Entity, exclude_t<>, Component >::raw ( ) const
inline

Direct access to the list of components.

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 of the components. Use begin and end if you want to iterate the view in the expected order.
Returns
A pointer to the array of components.

◆ size()

template<typename Entity , typename Component >
size_type entt::basic_view< Entity, exclude_t<>, Component >::size ( ) const
inline

Returns the number of entities that have the given component.

Returns
Number of entities that have the given component.

Friends And Related Function Documentation

◆ basic_registry< Entity >

template<typename Entity , typename Component >
friend class basic_registry< Entity >
friend

A registry is allowed to create views.


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