2#include "utilities/ID.hpp"
5#include <unordered_map>
22 template<
typename EventType>
using EventFunction = std::function<void(
const EventType& e)>;
49 template<
typename EventType>
56 explicit EventHandler(
const EventFunction<EventType>& handler) : handler(handler) {};
60 if (event.
GetEventType() == EventType::GetStaticEventType()) {
61 handler(
static_cast<const EventType&
>(event));
68 EventFunction<EventType> handler;
109 std::unordered_map<std::string, std::vector<EventHandlerBase*>> subscribers;
Base class for event handlers.
Definition EventSystem.hpp:27
const Utilities::ID handlerType
Unique handler identifier.
Definition EventSystem.hpp:43
Utilities::ID GetType() const
Get handler type ID.
Definition EventSystem.hpp:39
virtual void Execute(const Event &e)=0
Execute handler with event.
Typed event handler implementation.
Definition EventSystem.hpp:50
void Execute(const Event &event) override
Execute handler with event.
Definition EventSystem.hpp:58
EventHandler(const EventFunction< EventType > &handler)
Create new event handler.
Definition EventSystem.hpp:56
Manages event subscriptions and publishing.
Definition EventSystem.hpp:74
void Publish(const Event &event)
Publish event to subscribers.
Definition EventSystem.cpp:28
void Unsubscribe(const std::string eventId, const Utilities::ID handler)
Unsubscribe from event.
Definition EventSystem.cpp:17
Utilities::ID Subscribe(EventFunction< EventType > handler)
Subscribe to event type.
Definition EventSystem.hpp:82
Base class for all engine events.
Definition EventSystem.hpp:12
virtual const std::string GetEventType() const =0
Get type identifier for this event.
UUID-based unique identifier.
Definition ID.hpp:13