aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include/eventManager.h
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-18 14:08:36 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-18 14:08:36 +0100
commit20fc8401083e23e414feae2a9a4d217b228b8f15 (patch)
tree08c9e9c4ddcde5438eb54f6b051895c0896f935b /mwe/events/include/eventManager.h
parent60669b60e63532bc264ecd6d106bd15f0688a5b6 (diff)
parent121b64b1cb6cfead5814070c8b0185d3d7308095 (diff)
Merge remote-tracking branch 'origin/master' into niels/rendering_color
Diffstat (limited to 'mwe/events/include/eventManager.h')
-rw-r--r--mwe/events/include/eventManager.h30
1 files changed, 12 insertions, 18 deletions
diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h
index 508a5e2..30e927f 100644
--- a/mwe/events/include/eventManager.h
+++ b/mwe/events/include/eventManager.h
@@ -18,11 +18,9 @@ public:
}
void shutdown();
- void subscribe(int eventType,
- std::unique_ptr<IEventHandlerWrapper> && handler,
+ void subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler,
int eventId);
- void unsubscribe(int eventType, const std::string & handlerName,
- int eventId);
+ void unsubscribe(int eventType, const std::string & handlerName, int eventId);
void triggerEvent(const Event & event_, int eventId);
void queueEvent(std::unique_ptr<Event> && event_, int eventId);
void dispatchEvents();
@@ -30,11 +28,9 @@ public:
private:
EventManager() = default;
std::vector<std::pair<std::unique_ptr<Event>, int>> eventsQueue;
- std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>
- subscribers;
+ std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> subscribers;
std::unordered_map<
- int, std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>
+ int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>
subscribersByEventId;
};
@@ -42,18 +38,16 @@ template <typename EventType>
inline void subscribe(const EventHandler<EventType> & callback, int eventId = 0,
const bool unsubscribeOnSuccess = false) {
std::unique_ptr<IEventHandlerWrapper> handler
- = std::make_unique<EventHandlerWrapper<EventType>>(
- callback, unsubscribeOnSuccess);
- EventManager::getInstance().subscribe(EventType::getStaticEventType(),
- std::move(handler), eventId);
+ = std::make_unique<EventHandlerWrapper<EventType>>(callback, unsubscribeOnSuccess);
+ EventManager::getInstance().subscribe(EventType::getStaticEventType(), std::move(handler),
+ eventId);
}
template <typename EventType>
-inline void unsubscribe(const EventHandler<EventType> & callback,
- int eventId = 0) {
+inline void unsubscribe(const EventHandler<EventType> & callback, int eventId = 0) {
const std::string handlerName = callback.target_type().name();
- EventManager::getInstance().unsubscribe(EventType::getStaticEventType(),
- handlerName, eventId);
+ EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), handlerName,
+ eventId);
}
inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) {
@@ -61,6 +55,6 @@ inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) {
}
inline void queueEvent(std::unique_ptr<Event> && queuedEvent, int eventId = 0) {
- EventManager::getInstance().queueEvent(
- std::forward<std::unique_ptr<Event>>(queuedEvent), eventId);
+ EventManager::getInstance().queueEvent(std::forward<std::unique_ptr<Event>>(queuedEvent),
+ eventId);
}