Clementine
Classes | Public Member Functions | List of all members
entt::dispatcher Class Reference

Basic dispatcher implementation. More...

#include <entt.hpp>

Public Member Functions

template<typename Event >
auto sink ()
 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 Type >
void disconnect (Type &value_or_instance)
 Utility function to disconnect everything related to a given value or instance from a dispatcher. More...
 
template<typename Type >
void disconnect (Type *value_or_instance)
 Utility function to disconnect everything related to a given value or instance from a dispatcher. More...
 
template<typename... Event>
void clear ()
 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 Event &, 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.

Member Function Documentation

◆ clear()

template<typename... Event>
void entt::dispatcher::clear ( )
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.

◆ disconnect() [1/2]

template<typename Type >
void entt::dispatcher::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.

◆ disconnect() [2/2]

template<typename Type >
void entt::dispatcher::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.

◆ 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 >
auto 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 compatible with:

void(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: