diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-16 13:55:47 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-16 13:55:47 +0100 |
commit | 6e7003c73110cf9ad7e4c72de703dfdc2292d8ca (patch) | |
tree | 124818d404aab746cfd36a544f5c8241a4306b15 /src/crepe/api/EventManager.hpp | |
parent | 337a957a9e605f16287506b6afda56950e562db3 (diff) |
added hpp files and auto
Diffstat (limited to 'src/crepe/api/EventManager.hpp')
-rw-r--r-- | src/crepe/api/EventManager.hpp | 42 |
1 files changed, 10 insertions, 32 deletions
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<EventType> && callback, int channel) { std::vector<std::unique_ptr<IEventHandlerWrapper>>> & handlers_map = this->subscribers_by_event_id[event_type]; - std::unordered_map< - int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::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<std::unique_ptr<IEventHandlerWrapper>>> & handlers_map = this->subscribers_by_event_id[event_type]; - std::unordered_map< - int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator - handlers_it - = handlers_map.find(channel); + auto handlers_it = handlers_map.find(channel); if (handlers_it != handlers_map.end()) { std::vector<std::unique_ptr<IEventHandlerWrapper>> & handlers = handlers_it->second; - for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::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<std::unique_ptr<IEventHandlerWrapper>> & handlers = this->subscribers[event_type]; - for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::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<EventType> & callback, std::string handler_name = callback.target_type().name(); if (channel) { - std::unordered_map< - std::type_index, - std::unordered_map< - int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>:: - 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<std::unique_ptr<IEventHandlerWrapper>>> & handlers_map = subscriber_list->second; - std::unordered_map< - int, - std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator - handlers - = handlers_map.find(channel); + auto handlers = handlers_map.find(channel); if (handlers != handlers_map.end()) { std::vector<std::unique_ptr<IEventHandlerWrapper>> & callbacks = handlers->second; - for (std::vector< - std::unique_ptr<IEventHandlerWrapper>>::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<EventType> & callback, } } } else { - std::unordered_map<std::type_index, - std::vector<std::unique_ptr<IEventHandlerWrapper>>>:: - iterator handlers_it - = this->subscribers.find(event_type); + auto handlers_it = this->subscribers.find(event_type); if (handlers_it != this->subscribers.end()) { std::vector<std::unique_ptr<IEventHandlerWrapper>> & handlers = handlers_it->second; - for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::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<EventType> & callback, } } -} +} // namespace crepe |