#include <event_dispatcher.h>
|
template<typename Tevent > |
static void | AddEventListner (base_event_callback &&EventCallback) |
|
template<typename Tevent > |
static void | AddEventListner (std::function< bool(Tevent &)> &&EventCallback) |
|
template<typename Tevent > |
static void | Invoke (Tevent &Event) |
|
Static event dispatcher class. Should be created once, then event listners added to it and dispatched on event invoke.
Definition at line 19 of file event_dispatcher.h.
◆ AddEventListner() [1/2]
template<typename Tevent >
static void scl::event_dispatcher::AddEventListner |
( |
base_event_callback && |
EventCallback | ) |
|
|
inlinestatic |
Static event dispatcher methods.
- Add event listner to specific event function.
- Template Parameters
-
Tevent | - event to set listner to. |
- Parameters
-
Event | - callback to be called on event dispatch. |
- Returns
- None.
Definition at line 38 of file event_dispatcher.h.
39 {
40 auto event_handlers = EventHandlers.find(Tevent::StaticType);
41 if (event_handlers == EventHandlers.end())
42 EventHandlers.emplace(Tevent::StaticType, std::vector { std::move(EventCallback) });
43 else
44 event_handlers->second.push_back(std::move(EventCallback));
45 }
◆ AddEventListner() [2/2]
template<typename Tevent >
static void scl::event_dispatcher::AddEventListner |
( |
std::function< bool(Tevent &)> && |
EventCallback | ) |
|
|
inlinestatic |
- Add event listner to specific event function.
- Template Parameters
-
Tevent | - event to set listner to. |
- Parameters
-
Event | - callback to be called on event dispatch. |
- Returns
- None.
Definition at line 55 of file event_dispatcher.h.
56 {
57 AddEventListner<Tevent>([callback = std::move(EventCallback)](event &Event)
58 {
59 if (Event.GetType() != Tevent::StaticType) return false;
60 return callback(static_cast<Tevent &>(Event));
61 });
62 }
◆ Invoke()
template<typename Tevent >
static void scl::event_dispatcher::Invoke |
( |
Tevent & |
Event | ) |
|
|
inlinestatic |
- Dispatch specific event function. Calls all callbacks, listing to that event.
- Parameters
-
- Returns
- None.
Definition at line 72 of file event_dispatcher.h.
73 {
74 std::map<string_id, callback_list>::iterator event_handlers = EventHandlers.find(Event.GetType());
75 if (event_handlers == EventHandlers.end()) return;
76
77 for (const auto &callback : event_handlers->second)
78 {
79 Event.Handled |= callback(Event);
80 if (Event.Handled) break;
81 }
82 }
The documentation for this class was generated from the following files: