From e7377daf2fe3b759fbbf7e57f88c412c3b1cf011 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 24 Oct 2024 10:56:19 +0200 Subject: `make format` --- mwe/events/include/eventManager.h | 81 ++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 36 deletions(-) (limited to 'mwe/events/include/eventManager.h') diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h index 709796a..af41b82 100644 --- a/mwe/events/include/eventManager.h +++ b/mwe/events/include/eventManager.h @@ -1,57 +1,66 @@ #pragma once -#include -#include #include "event.h" -#include "keyCodes.h" #include "eventHandler.h" +#include "keyCodes.h" +#include +#include #include // using EventType = std::uint32_t; // using EventId = std::uint64_t; class EventManager { public: - EventManager(const EventManager&) = delete; - const EventManager& operator=(const EventManager&) = delete; - static EventManager& getInstance() { - static EventManager instance; - return instance; - } + EventManager(const EventManager &) = delete; + const EventManager & operator=(const EventManager &) = delete; + static EventManager & getInstance() { + static EventManager instance; + return instance; + } - void shutdown(); - void subscribe(int eventType, std::unique_ptr&& handler, 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_, int eventId); - void dispatchEvents(); + void shutdown(); + void subscribe(int eventType, + std::unique_ptr && handler, + 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_, int eventId); + void dispatchEvents(); private: - EventManager() = default; - std::vector, int>> m_eventsQueue; - std::unordered_map>> m_subscribers; - std::unordered_map>>> m_subscribersByEventId; + EventManager() = default; + std::vector, int>> m_eventsQueue; + std::unordered_map>> + m_subscribers; + std::unordered_map< + int, std::unordered_map< + int, std::vector>>> + m_subscribersByEventId; }; - -template -inline void subscribe(const EventHandler& callback, int eventId = 0, const bool unsubscribeOnSuccess = false) -{ - std::unique_ptr handler = std::make_unique>(callback, unsubscribeOnSuccess); - EventManager::getInstance().subscribe(EventType::getStaticEventType(), std::move(handler), eventId); +template +inline void subscribe(const EventHandler & callback, int eventId = 0, + const bool unsubscribeOnSuccess = false) { + std::unique_ptr handler + = std::make_unique>( + callback, unsubscribeOnSuccess); + EventManager::getInstance().subscribe(EventType::getStaticEventType(), + std::move(handler), eventId); } -template -inline void unsubscribe(const EventHandler& callback, int eventId = 0) -{ - const std::string handlerName = callback.target_type().name(); - EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), handlerName, eventId); +template +inline void unsubscribe(const EventHandler & callback, + int eventId = 0) { + const std::string handlerName = callback.target_type().name(); + EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), + handlerName, eventId); } -inline void triggerEvent(const Event& triggeredEvent, int eventId = 0) -{ - EventManager::getInstance().triggerEvent(triggeredEvent, eventId); +inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) { + EventManager::getInstance().triggerEvent(triggeredEvent, eventId); } -inline void queueEvent(std::unique_ptr&& queuedEvent, int eventId = 0) -{ - EventManager::getInstance().queueEvent(std::forward>(queuedEvent), eventId); +inline void queueEvent(std::unique_ptr && queuedEvent, int eventId = 0) { + EventManager::getInstance().queueEvent( + std::forward>(queuedEvent), eventId); } -- cgit v1.2.3