From 6e7003c73110cf9ad7e4c72de703dfdc2292d8ca Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Sat, 16 Nov 2024 13:55:47 +0100 Subject: added hpp files and auto --- src/crepe/api/EventManager.hpp | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'src/crepe/api/EventManager.hpp') diff --git a/src/crepe/api/EventManager.hpp b/src/crepe/api/EventManager.hpp index b509097..70f0a31 100644 --- a/src/crepe/api/EventManager.hpp +++ b/src/crepe/api/EventManager.hpp @@ -12,10 +12,7 @@ void EventManager::subscribe(EventHandler && callback, int channel) { std::vector>> & handlers_map = this->subscribers_by_event_id[event_type]; - std::unordered_map< - int, std::vector>>::iterator - handlers - = handlers_map.find(channel); + auto handlers = handlers_map.find(channel); if (handlers != handlers_map.end()) { handlers->second.emplace_back(std::move(handler)); } else { @@ -49,16 +46,12 @@ void EventManager::trigger_event(const EventType & event, int channel) { std::vector>> & handlers_map = this->subscribers_by_event_id[event_type]; - std::unordered_map< - int, std::vector>>::iterator - handlers_it - = handlers_map.find(channel); + auto handlers_it = handlers_map.find(channel); if (handlers_it != handlers_map.end()) { std::vector> & handlers = handlers_it->second; - for (std::vector>::iterator it - = handlers.begin(); + for (auto it = handlers.begin(); it != handlers.end();++it) { // stops when callback returns true if((*it)->exec(event)){ @@ -69,7 +62,7 @@ void EventManager::trigger_event(const EventType & event, int channel) { } else { std::vector> & handlers = this->subscribers[event_type]; - for (std::vector>::iterator it + for (auto it = handlers.begin(); it != handlers.end();++it) { // stops when callback returns true @@ -87,28 +80,17 @@ void EventManager::unsubscribe(const EventHandler & callback, std::string handler_name = callback.target_type().name(); if (channel) { - std::unordered_map< - std::type_index, - std::unordered_map< - int, std::vector>>>:: - iterator subscriber_list - = this->subscribers_by_event_id.find(event_type); + auto subscriber_list = this->subscribers_by_event_id.find(event_type); if (subscriber_list != this->subscribers_by_event_id.end()) { std::unordered_map< int, std::vector>> & handlers_map = subscriber_list->second; - std::unordered_map< - int, - std::vector>>::iterator - handlers - = handlers_map.find(channel); + auto handlers = handlers_map.find(channel); if (handlers != handlers_map.end()) { std::vector> & callbacks = handlers->second; - for (std::vector< - std::unique_ptr>::iterator it - = callbacks.begin(); + for (auto it = callbacks.begin(); it != callbacks.end(); ++it) { if ((*it)->get_type() == handler_name) { it = callbacks.erase(it); @@ -118,15 +100,11 @@ void EventManager::unsubscribe(const EventHandler & callback, } } } else { - std::unordered_map>>:: - iterator handlers_it - = this->subscribers.find(event_type); + auto handlers_it = this->subscribers.find(event_type); if (handlers_it != this->subscribers.end()) { std::vector> & handlers = handlers_it->second; - for (std::vector>::iterator it - = handlers.begin(); + for (auto it = handlers.begin(); it != handlers.end(); ++it) { if ((*it)->get_type() == handler_name) { it = handlers.erase(it); @@ -137,4 +115,4 @@ void EventManager::unsubscribe(const EventHandler & callback, } } -} +} // namespace crepe -- cgit v1.2.3