OpenLexocad  27.1
entt::dispatcher Class Reference

Basic dispatcher implementation. More...

#include <entt.hpp>

Public Types

template<typename Event >
using sink_type = typename signal_wrapper< Event >::sink_type
 Type of sink for the given event. More...
 

Public Member Functions

template<typename Event >
sink_type< Event > sink () ENTT_NOEXCEPT
 Returns a sink object for the given event. More...
 
template<typename Event , typename... Args>
void trigger (Args &&... args)
 Triggers an immediate event of the given type. More...
 
template<typename Event >
void trigger (Event &&event)
 Triggers an immediate event of the given type. More...
 
template<typename Event , typename... Args>
void enqueue (Args &&... args)
 Enqueues an event of the given type. More...
 
template<typename Event >
void enqueue (Event &&event)
 Enqueues an event of the given type. More...
 
template<typename... Event>
void discard ()
 Discards all the events queued so far. More...
 
template<typename Event >
void update ()
 Delivers all the pending events of the given type. More...
 
void update () const
 Delivers all the pending events. More...
 

Detailed Description

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 Event, listeners are such that they can be invoked with an argument of type const Event &, no matter what the return type is.

The types of the instances are Class &. Users must guarantee that the lifetimes of the objects overcome the one of the dispatcher itself to avoid crashes.

Member Typedef Documentation

◆ sink_type

template<typename Event >
using entt::dispatcher::sink_type = typename signal_wrapper<Event>::sink_type

Type of sink for the given event.

Member Function Documentation

◆ discard()

template<typename... Event>
void entt::dispatcher::discard ( )
inline

Discards all the events queued so far.

If no types are provided, the dispatcher will clear all the existing pools.

Template Parameters
EventType of events to discard.

◆ enqueue() [1/2]

template<typename Event , typename... Args>
void entt::dispatcher::enqueue ( Args &&...  args)
inline

Enqueues an event of the given type.

An event of the given type is queued. No listener is invoked. Use the update member function to notify listeners when ready.

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

◆ enqueue() [2/2]

template<typename Event >
void entt::dispatcher::enqueue ( Event &&  event)
inline

Enqueues an event of the given type.

An event of the given type is queued. No listener is invoked. Use the update member function to notify listeners when ready.

Template Parameters
EventType of event to enqueue.
Parameters
eventAn instance of the given type of event.

◆ sink()

template<typename Event >
sink_type<Event> entt::dispatcher::sink ( )
inline

Returns a sink object for the given event.

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

The function type for a listener is:

void(const Event &);

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

See also
sink
Template Parameters
EventType of event of which to get the sink.
Returns
A temporary sink object.

◆ trigger() [1/2]

template<typename Event , typename... Args>
void entt::dispatcher::trigger ( Args &&...  args)
inline

Triggers an immediate event of the given type.

All the listeners registered for the given type are immediately notified. The event is discarded after the execution.

Template Parameters
EventType of event to trigger.
ArgsTypes of arguments to use to construct the event.
Parameters
argsArguments to use to construct the event.

◆ trigger() [2/2]

template<typename Event >
void entt::dispatcher::trigger ( Event &&  event)
inline

Triggers an immediate event of the given type.

All the listeners registered for the given type are immediately notified. The event is discarded after the execution.

Template Parameters
EventType of event to trigger.
Parameters
eventAn instance of the given type of event.

◆ update() [1/2]

template<typename Event >
void entt::dispatcher::update ( )
inline

Delivers all the pending events of the given type.

This method is blocking and it doesn't return until all the events are delivered to the registered listeners. It's responsibility of the users to reduce at a minimum the time spent in the bodies of the listeners.

Template Parameters
EventType of events to send.

◆ update() [2/2]

void entt::dispatcher::update ( ) const
inline

Delivers all the pending events.

This method is blocking and it doesn't return until all the events are delivered to the registered listeners. It's responsibility of the users to reduce at a minimum the time spent in the bodies of the listeners.


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