|
utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
|
Dispatches typed events to registered listeners. More...
#include <headers/utility/event/event_dispatcher.hpp>
Public Member Functions | |
| EventDispatcher (void)=default | |
| Default constructor. | |
| ~EventDispatcher (void)=default | |
| Default destructor. | |
| template<InheritFromEvent EventType, typename Callable > | |
| void | addListener (Callable &&listener) |
| Register a listener for a concrete event type. | |
| template<InheritFromEvent EventType> | |
| void | emit (const EventType &event) const |
| Emit an event to all listeners registered for its concrete type. | |
| template<InheritFromEvent EventType> | |
| void | clearListeners (void) |
| Remove all listeners registered for a concrete event type. | |
| void | clearAll (void) noexcept |
| Remove all listeners for every event type. | |
Dispatches typed events to registered listeners.
Listeners are registered per concrete event type. When an event is emitted, all listeners registered for that type are invoked with a strongly typed reference. Events are dispatched to the concrete type derived from the base Event pointer via a runtime type check.
The dispatcher owns no events; it only forwards them. It is safe to register and emit from the same thread.
Definition at line 48 of file event_dispatcher.hpp.
|
inline |
Register a listener for a concrete event type.
| EventType | The concrete event type (must derive from Event). |
| listener | Callable invoked with a const reference to the event. |
Definition at line 79 of file event_dispatcher.hpp.
|
inlinenoexcept |
Remove all listeners for every event type.
Definition at line 119 of file event_dispatcher.hpp.
|
inline |
Remove all listeners registered for a concrete event type.
| EventType | The concrete event type. |
Definition at line 111 of file event_dispatcher.hpp.
|
inline |
Emit an event to all listeners registered for its concrete type.
| EventType | The concrete event type. |
| event | The event to dispatch. |
Definition at line 95 of file event_dispatcher.hpp.