blob: 7a8be53e6a9ab4b94828dcee329d676d6197da2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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()->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 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;
}
}
}
|