diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-11 16:12:09 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-11 16:12:09 +0100 |
commit | 80c74b90a3e44e25a4fa9fdd25bf0aa9efbaf6fd (patch) | |
tree | 1ac04e3434c8e775318b6f8519c6674bb2a3298d /src/crepe/api/EventManager.cpp | |
parent | 880a7b1fb233a67303ad5a4155dc459f79734762 (diff) |
interfaces working but unsubscribe broken
Diffstat (limited to 'src/crepe/api/EventManager.cpp')
-rw-r--r-- | src/crepe/api/EventManager.cpp | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/src/crepe/api/EventManager.cpp b/src/crepe/api/EventManager.cpp index 07ef1f7..7a8be53 100644 --- a/src/crepe/api/EventManager.cpp +++ b/src/crepe/api/EventManager.cpp @@ -1,69 +1,69 @@ #include "EventManager.h" -void EventManager::unsubscribe(std::type_index eventType, const std::string & handlerName, - int eventId) { - // if (eventId) { - // std::unordered_map< - // std::type_index, std::unordered_map< - // int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::iterator subscriber_list = subscribers_by_event_id.find(eventType); - // if (subscriber_list != 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(eventId); - // 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(); - // it != callbacks.end(); ++it) { - // if (it->get()->getType() == handlerName) { - // it = callbacks.erase(it); - // return; - // } - // } - // } - // } - // } else { - // std::unordered_map< - // std::type_index, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator - // handlers_it - // = subscribers.find(eventType); - // if (handlers_it != subscribers.end()) { - // std::vector<std::unique_ptr<IEventHandlerWrapper>> & handlers - // = handlers_it->second; - // for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::iterator it - // = handlers.begin(); - // it != handlers.end(); ++it) { - // if (it->get()->getType() == handlerName) { - // it = handlers.erase(it); - // return; - // } - // } - // } - // } -} +// void EventManager::unsubscribe(std::type_index eventType, const std::string & handlerName, +// int eventId) { +// if (eventId) { +// std::unordered_map< +// std::type_index, std::unordered_map< +// int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::iterator subscriber_list = subscribers_by_event_id.find(eventType); +// if (subscriber_list != 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(eventId); +// 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(); +// it != callbacks.end(); ++it) { +// if (it->get()->get_type() == handlerName) { +// it = callbacks.erase(it); +// return; +// } +// } +// } +// } +// } else { +// std::unordered_map< +// std::type_index, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator +// handlers_it +// = subscribers.find(eventType); +// if (handlers_it != subscribers.end()) { +// std::vector<std::unique_ptr<IEventHandlerWrapper>> & handlers +// = handlers_it->second; +// for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::iterator it +// = handlers.begin(); +// it != handlers.end(); ++it) { +// if (it->get()->get_type() == handlerName) { +// it = handlers.erase(it); +// return; +// } +// } +// } +// } +// } void EventManager::queue_event(std::unique_ptr<Event> && event_, int eventId) { events_queue.emplace_back(std::move(event_), eventId); } void EventManager::dispatch_events() { - // for (std::vector<std::pair<std::unique_ptr<Event>, int>>::iterator eventIt - // = eventsQueue.begin(); - // eventIt != eventsQueue.end();) { - // bool handled = false; - // if (!handled) { - // triggerEvent(*eventIt->first.get(), eventIt->second); - // eventIt = eventsQueue.erase(eventIt); - // } else { - // ++eventIt; - // } - // } + for (std::vector<std::pair<std::unique_ptr<Event>, int>>::iterator event_it + = events_queue.begin(); + event_it != events_queue.end();) { + bool handled = false; + if (!handled) { + trigger_event<Event>(*event_it->first.get(), event_it->second); + event_it = events_queue.erase(event_it); + } else { + ++event_it; + } + } } |