aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/EventManager.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api/EventManager.hpp')
-rw-r--r--src/crepe/api/EventManager.hpp42
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