1#ifndef CODEX_EVENT_DISPATCHER_EVENT_DISPATCHER_HPP
2#define CODEX_EVENT_DISPATCHER_EVENT_DISPATCHER_HPP
19template<
typename T>
concept Event = std::derived_from<T, BaseEvent>;
21template<
typename T,
typename E>
27template<Event E>
struct EventListenerVec
28 {
protected: std::vector<std::function<void(
E)>>
v; };
43 template<Event E, EventListener<E> L>
50 requires std::is_base_of_v<
A type-safe event listener/dispatcher.
Definition event_dispatcher.hpp:40
void add_listener(L l)
Adds a callback for a given event type.
Definition event_dispatcher.hpp:44
decltype(auto) vec()
Helper method to access the storage for a particular event type.
Definition event_dispatcher.hpp:52
void trigger(E e)
Invokes all listeners associated with the event type.
Definition event_dispatcher.hpp:46
Constrains a callable to an event type.
Definition event_dispatcher.hpp:22
Semi-arbitrary method to identify an event type.
Definition event_dispatcher.hpp:19
#define x
Definition gcc14.c:1
Base class tag to identify events.
Definition event_dispatcher.hpp:12
Sample button click event.
Definition event_dispatcher.hpp:14
int button
Definition event_dispatcher.hpp:14
Sample key press event.
Definition event_dispatcher.hpp:16
int key
Definition event_dispatcher.hpp:16
Storage base class for a given event type.
Definition event_dispatcher.hpp:28
std::vector< std::function< void(E)> > v
Definition event_dispatcher.hpp:28