EnTT 3.13.0
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
entt::basic_observer< Registry, Mask, Allocator > Class Template Reference

Observer. More...

#include <observer.hpp>

Inheritance diagram for entt::basic_observer< Registry, Mask, Allocator >:
Inheritance graph
[legend]
Collaboration diagram for entt::basic_observer< Registry, Mask, Allocator >:
Collaboration graph
[legend]

Public Types

using registry_type = Registry
 
using entity_type = typename registry_type::entity_type
 Underlying entity identifier.
 
using size_type = std::size_t
 Unsigned integer type.
 
using allocator_type = Allocator
 Allocator type.
 
using iterator = typename registry_type::common_type::iterator
 Random access iterator type.
 

Public Member Functions

 basic_observer ()
 Default constructor.
 
 basic_observer (const allocator_type &allocator)
 Constructs an empty storage with a given allocator.
 
 basic_observer (const basic_observer &)=delete
 Default copy constructor, deleted on purpose.
 
 basic_observer (basic_observer &&)=delete
 Default move constructor, deleted on purpose.
 
template<typename... Matcher>
 basic_observer (registry_type &reg, basic_collector< Matcher... >, const allocator_type &allocator=allocator_type{})
 Creates an observer and connects it to a given registry.
 
basic_observeroperator= (const basic_observer &)=delete
 Default copy assignment operator, deleted on purpose.
 
basic_observeroperator= (basic_observer &&)=delete
 Default move assignment operator, deleted on purpose.
 
template<typename... Matcher>
void connect (registry_type &reg, basic_collector< Matcher... >)
 Connects an observer to a given registry.
 
void disconnect ()
 Disconnects an observer from the registry it keeps track of.
 
size_type size () const noexcept
 Returns the number of elements in an observer.
 
bool empty () const noexcept
 Checks whether an observer is empty.
 
const entity_typedata () const noexcept
 Direct access to the list of entities of the observer.
 
iterator begin () const noexcept
 Returns an iterator to the first entity of the observer.
 
iterator end () const noexcept
 Returns an iterator that is past the last entity of the observer.
 
void clear () noexcept
 Clears the underlying container.
 
template<typename Func >
void each (Func func) const
 Iterates entities and applies the given function object to them.
 
template<typename Func >
void each (Func func)
 Iterates entities and applies the given function object to them, then clears the observer.
 

Detailed Description

template<typename Registry, typename Mask, typename Allocator>
class entt::basic_observer< Registry, Mask, Allocator >

Observer.

An observer returns all the entities and only the entities that fit the requirements of at least one matcher. Moreover, it's guaranteed that the entity list is tightly packed in memory for fast iterations.
In general, observers don't stay true to the order of any set of components.

Observers work mainly with two types of matchers, provided through a collector:

If an entity respects the requirements of multiple matchers, it will be returned once and only once by the observer in any case.

Matchers support also filtering by means of a where clause that accepts both a list of types and an exclusion list.
Whenever a matcher finds that an entity matches its requirements, the condition of the filter is verified before to register the entity itself. Moreover, a registered entity isn't returned by the observer if the condition set by the filter is broken in the meantime.

Important

Iterators aren't invalidated if:

In all the other cases, modifying the pools of the given components in any way invalidates all the iterators.

Warning
Lifetime of an observer doesn't necessarily have to overcome that of the registry to which it is connected. However, the observer must be disconnected from the registry before being destroyed to avoid crashes due to dangling pointers.
Template Parameters
RegistryBasic registry type.
MaskMask type.
AllocatorType of allocator used to manage memory and elements.

Definition at line 162 of file observer.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Registry , typename Mask , typename Allocator >
using entt::basic_observer< Registry, Mask, Allocator >::allocator_type = Allocator

Allocator type.

Definition at line 272 of file observer.hpp.

◆ entity_type

template<typename Registry , typename Mask , typename Allocator >
using entt::basic_observer< Registry, Mask, Allocator >::entity_type = typename registry_type::entity_type

Underlying entity identifier.

Definition at line 268 of file observer.hpp.

◆ iterator

template<typename Registry , typename Mask , typename Allocator >
using entt::basic_observer< Registry, Mask, Allocator >::iterator = typename registry_type::common_type::iterator

Random access iterator type.

Definition at line 274 of file observer.hpp.

◆ registry_type

template<typename Registry , typename Mask , typename Allocator >
using entt::basic_observer< Registry, Mask, Allocator >::registry_type = Registry

Basic registry type.

Definition at line 266 of file observer.hpp.

◆ size_type

template<typename Registry , typename Mask , typename Allocator >
using entt::basic_observer< Registry, Mask, Allocator >::size_type = std::size_t

Unsigned integer type.

Definition at line 270 of file observer.hpp.

Constructor & Destructor Documentation

◆ basic_observer() [1/3]

template<typename Registry , typename Mask , typename Allocator >
entt::basic_observer< Registry, Mask, Allocator >::basic_observer ( )
inline

Default constructor.

Definition at line 277 of file observer.hpp.

◆ basic_observer() [2/3]

template<typename Registry , typename Mask , typename Allocator >
entt::basic_observer< Registry, Mask, Allocator >::basic_observer ( const allocator_type allocator)
inlineexplicit

Constructs an empty storage with a given allocator.

Parameters
allocatorThe allocator to use.

Definition at line 284 of file observer.hpp.

◆ basic_observer() [3/3]

template<typename Registry , typename Mask , typename Allocator >
template<typename... Matcher>
entt::basic_observer< Registry, Mask, Allocator >::basic_observer ( registry_type reg,
basic_collector< Matcher... >  ,
const allocator_type allocator = allocator_type{} 
)
inline

Creates an observer and connects it to a given registry.

Template Parameters
MatcherTypes of matchers to use to initialize the observer.
Parameters
regA valid reference to a registry.
allocatorThe allocator to use.

Definition at line 301 of file observer.hpp.

Member Function Documentation

◆ begin()

template<typename Registry , typename Mask , typename Allocator >
iterator entt::basic_observer< Registry, Mask, Allocator >::begin ( ) const
inlinenoexcept

Returns an iterator to the first entity of the observer.

If the observer is empty, the returned iterator will be equal to end().

Returns
An iterator to the first entity of the observer.

Definition at line 377 of file observer.hpp.

◆ clear()

template<typename Registry , typename Mask , typename Allocator >
void entt::basic_observer< Registry, Mask, Allocator >::clear ( )
inlinenoexcept

Clears the underlying container.

Definition at line 391 of file observer.hpp.

◆ connect()

template<typename Registry , typename Mask , typename Allocator >
template<typename... Matcher>
void entt::basic_observer< Registry, Mask, Allocator >::connect ( registry_type reg,
basic_collector< Matcher... >   
)
inline

Connects an observer to a given registry.

Template Parameters
MatcherTypes of matchers to use to initialize the observer.
Parameters
regA valid reference to a registry.

Definition at line 324 of file observer.hpp.

◆ data()

template<typename Registry , typename Mask , typename Allocator >
const entity_type * entt::basic_observer< Registry, Mask, Allocator >::data ( ) const
inlinenoexcept

Direct access to the list of entities of the observer.

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

Note
Entities are in the reverse order as returned by the begin/end iterators.
Returns
A pointer to the array of entities.

Definition at line 366 of file observer.hpp.

◆ disconnect()

template<typename Registry , typename Mask , typename Allocator >
void entt::basic_observer< Registry, Mask, Allocator >::disconnect ( )
inline

Disconnects an observer from the registry it keeps track of.

Definition at line 331 of file observer.hpp.

◆ each() [1/2]

template<typename Registry , typename Mask , typename Allocator >
template<typename Func >
void entt::basic_observer< Registry, Mask, Allocator >::each ( Func  func)
inline

Iterates entities and applies the given function object to them, then clears the observer.

See also
each
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

Definition at line 425 of file observer.hpp.

◆ each() [2/2]

template<typename Registry , typename Mask , typename Allocator >
template<typename Func >
void entt::basic_observer< Registry, Mask, Allocator >::each ( Func  func) const
inline

Iterates entities and applies the given function object to them.

The function object is invoked for each entity.
The signature of the function must be equivalent to the following form:

void(const entity_type);
typename registry_type::entity_type entity_type
Underlying entity identifier.
Definition observer.hpp:268
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

Definition at line 409 of file observer.hpp.

◆ empty()

template<typename Registry , typename Mask , typename Allocator >
bool entt::basic_observer< Registry, Mask, Allocator >::empty ( ) const
inlinenoexcept

Checks whether an observer is empty.

Returns
True if the observer is empty, false otherwise.

Definition at line 350 of file observer.hpp.

◆ end()

template<typename Registry , typename Mask , typename Allocator >
iterator entt::basic_observer< Registry, Mask, Allocator >::end ( ) const
inlinenoexcept

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

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

Definition at line 386 of file observer.hpp.

◆ operator=() [1/2]

template<typename Registry , typename Mask , typename Allocator >
basic_observer & entt::basic_observer< Registry, Mask, Allocator >::operator= ( basic_observer< Registry, Mask, Allocator > &&  )
delete

Default move assignment operator, deleted on purpose.

Returns
This observer.

◆ operator=() [2/2]

template<typename Registry , typename Mask , typename Allocator >
basic_observer & entt::basic_observer< Registry, Mask, Allocator >::operator= ( const basic_observer< Registry, Mask, Allocator > &  )
delete

Default copy assignment operator, deleted on purpose.

Returns
This observer.

◆ size()

template<typename Registry , typename Mask , typename Allocator >
size_type entt::basic_observer< Registry, Mask, Allocator >::size ( ) const
inlinenoexcept

Returns the number of elements in an observer.

Returns
Number of elements.

Definition at line 342 of file observer.hpp.


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