A central event handler class that connects event handlers with the events.
More...
#include <event_bus.hpp>
|
| event_bus ()=default |
|
template<typename EventType , typename EventHandler , typename = std::enable_if_t<std::is_invocable_v<EventHandler> || std::is_invocable_v<EventHandler, EventType>>> |
handler_registration | register_handler (EventHandler &&handler) |
| Register an event handler for a given event type. More...
|
|
template<typename EventType , typename ClassType , typename MemberFunction > |
handler_registration | register_handler (ClassType *class_instance, MemberFunction &&function) noexcept |
| Register an event handler for a given event type. More...
|
|
template<typename EventType , typename = std::enable_if_t<!std::is_pointer_v<EventType>>> |
void | fire_event (EventType &&evt) noexcept |
| Fire an event to notify event handlers. More...
|
|
bool | remove_handler (const handler_registration ®istration) noexcept |
| Remove a given handler from the event bus. More...
|
|
void | remove_handlers () noexcept |
| Remove all handlers from event bus. More...
|
|
std::size_t | handler_count () noexcept |
| Get the number of handlers registered with the event bus. More...
|
|
A central event handler class that connects event handlers with the events.
◆ event_bus()
dp::event_bus::event_bus |
( |
| ) |
|
|
default |
◆ fire_event()
template<typename EventType , typename = std::enable_if_t<!std::is_pointer_v<EventType>>>
void dp::event_bus::fire_event |
( |
EventType && |
evt | ) |
|
|
inlinenoexcept |
Fire an event to notify event handlers.
- Template Parameters
-
- Parameters
-
evt | The event to pass to all event handlers. |
◆ handler_count()
std::size_t dp::event_bus::handler_count |
( |
| ) |
|
|
inlinenoexcept |
Get the number of handlers registered with the event bus.
- Returns
- The total number of handlers.
◆ register_handler() [1/2]
template<typename EventType , typename ClassType , typename MemberFunction >
handler_registration dp::event_bus::register_handler |
( |
ClassType * |
class_instance, |
|
|
MemberFunction && |
function |
|
) |
| |
|
inlinenoexcept |
Register an event handler for a given event type.
- Template Parameters
-
EventType | The event type |
ClassType | Event handler class |
MemberFunction | Event handler member function |
- Parameters
-
class_instance | Instance of ClassType that will handle the event. |
function | Pointer to the MemberFunction of the ClassType. |
- Returns
- A handler_registration instance for the given handler.
◆ register_handler() [2/2]
template<typename EventType , typename EventHandler , typename = std::enable_if_t<std::is_invocable_v<EventHandler> || std::is_invocable_v<EventHandler, EventType>>>
Register an event handler for a given event type.
- Template Parameters
-
EventType | The event type |
EventHandler | The invocable event handler type. |
- Parameters
-
handler | A callable handler of the event type. Can accept the event as param or take no params. |
- Returns
- A handler_registration instance for the given handler.
◆ remove_handler()
Remove a given handler from the event bus.
- Parameters
-
registration | The registration object returned by register_handler. |
- Returns
- true is handler removal was successful, false otherwise.
◆ remove_handlers()
void dp::event_bus::remove_handlers |
( |
| ) |
|
|
inlinenoexcept |
Remove all handlers from event bus.
The documentation for this class was generated from the following file: