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

Basic dispatcher implementation. More...

#include <dispatcher.hpp>

Public Types

using allocator_type = Allocator
 Allocator type.
 
using size_type = std::size_t
 Unsigned integer type.
 

Public Member Functions

 basic_dispatcher ()
 Default constructor.
 
 basic_dispatcher (const allocator_type &allocator)
 Constructs a dispatcher with a given allocator.
 
 basic_dispatcher (basic_dispatcher &&other) noexcept
 Move constructor.
 
 basic_dispatcher (basic_dispatcher &&other, const allocator_type &allocator) noexcept
 Allocator-extended move constructor.
 
basic_dispatcheroperator= (basic_dispatcher &&other) noexcept
 Move assignment operator.
 
void swap (basic_dispatcher &other)
 Exchanges the contents with those of a given dispatcher.
 
constexpr allocator_type get_allocator () const noexcept
 Returns the associated allocator.
 
template<typename Type >
size_type size (const id_type id=type_hash< Type >::value()) const noexcept
 Returns the number of pending events for a given type.
 
size_type size () const noexcept
 Returns the total number of pending events.
 
template<typename Type >
auto sink (const id_type id=type_hash< Type >::value())
 Returns a sink object for the given event and queue.
 
template<typename Type >
void trigger (Type &&value={})
 Triggers an immediate event of a given type.
 
template<typename Type >
void trigger (const id_type id, Type &&value={})
 Triggers an immediate event on a queue of a given type.
 
template<typename Type , typename... Args>
void enqueue (Args &&...args)
 Enqueues an event of the given type.
 
template<typename Type >
void enqueue (Type &&value)
 Enqueues an event of the given type.
 
template<typename Type , typename... Args>
void enqueue_hint (const id_type id, Args &&...args)
 Enqueues an event of the given type.
 
template<typename Type >
void enqueue_hint (const id_type id, Type &&value)
 Enqueues an event of the given type.
 
template<typename Type >
void disconnect (Type &value_or_instance)
 Utility function to disconnect everything related to a given value or instance from a dispatcher.
 
template<typename Type >
void disconnect (Type *value_or_instance)
 Utility function to disconnect everything related to a given value or instance from a dispatcher.
 
template<typename Type >
void clear (const id_type id=type_hash< Type >::value())
 Discards all the events stored so far in a given queue.
 
void clear () noexcept
 Discards all the events queued so far.
 
template<typename Type >
void update (const id_type id=type_hash< Type >::value())
 Delivers all the pending events of a given queue.
 
void update () const
 Delivers all the pending events.
 

Detailed Description

template<typename Allocator>
class entt::basic_dispatcher< Allocator >

Basic dispatcher implementation.

A dispatcher can be used either to trigger an immediate event or to enqueue events to be published all together once per tick.
Listeners are provided in the form of member functions. For each event of type Type, listeners are such that they can be invoked with an argument of type Type &, no matter what the return type is.

The dispatcher creates instances of the sigh class internally. Refer to the documentation of the latter for more details.

Template Parameters
AllocatorType of allocator used to manage memory and elements.

Definition at line 108 of file dispatcher.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Allocator >
using entt::basic_dispatcher< Allocator >::allocator_type = Allocator

Allocator type.

Definition at line 146 of file dispatcher.hpp.

◆ size_type

template<typename Allocator >
using entt::basic_dispatcher< Allocator >::size_type = std::size_t

Unsigned integer type.

Definition at line 148 of file dispatcher.hpp.

Constructor & Destructor Documentation

◆ basic_dispatcher() [1/4]

template<typename Allocator >
entt::basic_dispatcher< Allocator >::basic_dispatcher ( )
inline

Default constructor.

Definition at line 151 of file dispatcher.hpp.

◆ basic_dispatcher() [2/4]

template<typename Allocator >
entt::basic_dispatcher< Allocator >::basic_dispatcher ( const allocator_type allocator)
inlineexplicit

Constructs a dispatcher with a given allocator.

Parameters
allocatorThe allocator to use.

Definition at line 158 of file dispatcher.hpp.

◆ basic_dispatcher() [3/4]

template<typename Allocator >
entt::basic_dispatcher< Allocator >::basic_dispatcher ( basic_dispatcher< Allocator > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherThe instance to move from.

Definition at line 165 of file dispatcher.hpp.

◆ basic_dispatcher() [4/4]

template<typename Allocator >
entt::basic_dispatcher< Allocator >::basic_dispatcher ( basic_dispatcher< Allocator > &&  other,
const allocator_type allocator 
)
inlinenoexcept

Allocator-extended move constructor.

Parameters
otherThe instance to move from.
allocatorThe allocator to use.

Definition at line 173 of file dispatcher.hpp.

Member Function Documentation

◆ clear() [1/2]

template<typename Allocator >
void entt::basic_dispatcher< Allocator >::clear ( )
inlinenoexcept

Discards all the events queued so far.

Definition at line 356 of file dispatcher.hpp.

◆ clear() [2/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::clear ( const id_type  id = type_hash<Type>::value())
inline

Discards all the events stored so far in a given queue.

Template Parameters
TypeType of event to discard.
Parameters
idName used to map the event queue within the dispatcher.

Definition at line 351 of file dispatcher.hpp.

◆ disconnect() [1/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::disconnect ( Type &  value_or_instance)
inline

Utility function to disconnect everything related to a given value or instance from a dispatcher.

Template Parameters
TypeType of class or type of payload.
Parameters
value_or_instanceA valid object that fits the purpose.

Definition at line 328 of file dispatcher.hpp.

◆ disconnect() [2/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::disconnect ( Type *  value_or_instance)
inline

Utility function to disconnect everything related to a given value or instance from a dispatcher.

Template Parameters
TypeType of class or type of payload.
Parameters
value_or_instanceA valid object that fits the purpose.

Definition at line 339 of file dispatcher.hpp.

◆ enqueue() [1/2]

template<typename Allocator >
template<typename Type , typename... Args>
void entt::basic_dispatcher< Allocator >::enqueue ( Args &&...  args)
inline

Enqueues an event of the given type.

Template Parameters
TypeType of event to enqueue.
ArgsTypes of arguments to use to construct the event.
Parameters
argsArguments to use to construct the event.

Definition at line 284 of file dispatcher.hpp.

◆ enqueue() [2/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::enqueue ( Type &&  value)
inline

Enqueues an event of the given type.

Template Parameters
TypeType of event to enqueue.
Parameters
valueAn instance of the given type of event.

Definition at line 294 of file dispatcher.hpp.

◆ enqueue_hint() [1/2]

template<typename Allocator >
template<typename Type , typename... Args>
void entt::basic_dispatcher< Allocator >::enqueue_hint ( const id_type  id,
Args &&...  args 
)
inline

Enqueues an event of the given type.

Template Parameters
TypeType of event to enqueue.
ArgsTypes of arguments to use to construct the event.
Parameters
idName used to map the event queue within the dispatcher.
argsArguments to use to construct the event.

Definition at line 306 of file dispatcher.hpp.

◆ enqueue_hint() [2/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::enqueue_hint ( const id_type  id,
Type &&  value 
)
inline

Enqueues an event of the given type.

Template Parameters
TypeType of event to enqueue.
Parameters
idName used to map the event queue within the dispatcher.
valueAn instance of the given type of event.

Definition at line 317 of file dispatcher.hpp.

◆ get_allocator()

template<typename Allocator >
constexpr allocator_type entt::basic_dispatcher< Allocator >::get_allocator ( ) const
inlineconstexprnoexcept

Returns the associated allocator.

Returns
The associated allocator.

Definition at line 202 of file dispatcher.hpp.

◆ operator=()

template<typename Allocator >
basic_dispatcher & entt::basic_dispatcher< Allocator >::operator= ( basic_dispatcher< Allocator > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe instance to move from.
Returns
This dispatcher.

Definition at line 183 of file dispatcher.hpp.

◆ sink()

template<typename Allocator >
template<typename Type >
auto entt::basic_dispatcher< Allocator >::sink ( const id_type  id = type_hash<Type>::value())
inline

Returns a sink object for the given event and queue.

A sink is an opaque object used to connect listeners to events.

The function type for a listener is compatible with:

void(Type &);

The order of invocation of the listeners isn't guaranteed.

See also
sink
Template Parameters
TypeType of event of which to get the sink.
Parameters
idName used to map the event queue within the dispatcher.
Returns
A temporary sink object.

Definition at line 252 of file dispatcher.hpp.

◆ size() [1/2]

template<typename Allocator >
size_type entt::basic_dispatcher< Allocator >::size ( ) const
inlinenoexcept

Returns the total number of pending events.

Returns
The total number of pending events.

Definition at line 222 of file dispatcher.hpp.

◆ size() [2/2]

template<typename Allocator >
template<typename Type >
size_type entt::basic_dispatcher< Allocator >::size ( const id_type  id = type_hash<Type>::value()) const
inlinenoexcept

Returns the number of pending events for a given type.

Template Parameters
TypeType of event for which to return the count.
Parameters
idName used to map the event queue within the dispatcher.
Returns
The number of pending events for the given type.

Definition at line 213 of file dispatcher.hpp.

◆ swap()

template<typename Allocator >
void entt::basic_dispatcher< Allocator >::swap ( basic_dispatcher< Allocator > &  other)
inline

Exchanges the contents with those of a given dispatcher.

Parameters
otherDispatcher to exchange the content with.

Definition at line 193 of file dispatcher.hpp.

◆ trigger() [1/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::trigger ( const id_type  id,
Type &&  value = {} 
)
inline

Triggers an immediate event on a queue of a given type.

Template Parameters
TypeType of event to trigger.
Parameters
valueAn instance of the given type of event.
idName used to map the event queue within the dispatcher.

Definition at line 273 of file dispatcher.hpp.

◆ trigger() [2/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::trigger ( Type &&  value = {})
inline

Triggers an immediate event of a given type.

Template Parameters
TypeType of event to trigger.
Parameters
valueAn instance of the given type of event.

Definition at line 262 of file dispatcher.hpp.

◆ update() [1/2]

template<typename Allocator >
void entt::basic_dispatcher< Allocator >::update ( ) const
inline

Delivers all the pending events.

Definition at line 373 of file dispatcher.hpp.

◆ update() [2/2]

template<typename Allocator >
template<typename Type >
void entt::basic_dispatcher< Allocator >::update ( const id_type  id = type_hash<Type>::value())
inline

Delivers all the pending events of a given queue.

Template Parameters
TypeType of event to send.
Parameters
idName used to map the event queue within the dispatcher.

Definition at line 368 of file dispatcher.hpp.


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