Dispatcher Class
A generic event Dispatcher for type-safe event handling. More...
Declaration
Public Member Functions Index
template <typename EventType> | |
| void | subscribe (std::function< void(const EventType &)> callback) |
|
Subscribes a callback to a specific event type. More... | |
| void | dispatch (std::unique_ptr< const Event > event) |
|
Dispatches an event to all subscribed callbacks (i.e. listeners) of the specific EventType. More... | |
Private Member Attributes Index
| std::unordered_map< std::type_index, std::vector< std::function< void(const Event &)> > > | callbacks_ |
|
Internal map to store registered callbacks for various event types. More... | |
Description
A generic event Dispatcher for type-safe event handling.
The `Dispatcher` allows interested entities to subscribe to specific event types and dispatch events in a decoupled manner. Using `std::type_index` makes sure that only relevant handlers receive specific event instances.
Definition at line 27 of file Dispatcher.ixx.
Public Member Functions
dispatch()
| inline |
Dispatches an event to all subscribed callbacks (i.e. listeners) of the specific EventType.
This method will take ownership of the event to dispatch. Once this method returns, the unique_ptr to the `Event` will be a nullptr.
- Parameters
-
event A unique_ptr to the event instance to be dispatched.
Definition at line 70 of file Dispatcher.ixx.
subscribe()
| inline |
Subscribes a callback to a specific event type.
Registers a `std::function` to be invoked when an event of `EventType` is dispatched. The callback will receive the dispatched event as a const reference.
- Template Parameters
-
EventType The specific type of event to subscribe to. Must derive from `Event`.
- Parameters
-
callback The callback function to be executed when the event is dispatched. The function should accept `const EventType&` as its single argument.
Definition at line 47 of file Dispatcher.ixx.
Referenced by helios::app::controller::BasicWindowRenderingController::subscribeTo.
Private Member Attributes
callbacks_
|
Internal map to store registered callbacks for various event types.
Definition at line 33 of file Dispatcher.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.