forked from GrandOrgue/grandorgue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGOEventHandlerList.h
148 lines (121 loc) · 3.93 KB
/
GOEventHandlerList.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
#ifndef GOEVENTHANDLERLIST_H
#define GOEVENTHANDLERLIST_H
#include <algorithm>
#include <unordered_set>
#include <vector>
class GOCacheObject;
class GOCombinationButtonSet;
class GOControl;
class GOControlChangedHandler;
class GOEventHandler;
class GOMidiObject;
class GOReferencingObject;
class GOSoundStateHandler;
class GOSaveableObject;
class GOEventHandlerList {
private:
template <class T> class UPVector {
private:
std::vector<T *> objVector;
std::unordered_set<T *> objSet;
public:
void Add(T *pObj) {
if (objSet.find(pObj) == objSet.end()) {
objSet.insert(pObj);
objVector.push_back(pObj);
}
}
void Remove(T *pObj) {
auto sIt = objSet.find(pObj);
if (sIt != objSet.end()) {
auto vIt = std::find(objVector.begin(), objVector.end(), pObj);
if (vIt != objVector.end())
objVector.erase(vIt);
objSet.erase(sIt);
}
}
const std::vector<T *> &AsVector() const { return objVector; }
void Clear() {
objVector.clear();
objSet.clear();
}
};
UPVector<GOCacheObject> m_CacheObjects;
UPVector<GOReferencingObject> m_ReferencingObjects;
UPVector<GOCombinationButtonSet> m_CombinationButtonSets;
UPVector<GOControlChangedHandler> m_ControlChangedHandlers;
UPVector<GOMidiObject> m_MidiConfigurators;
UPVector<GOEventHandler> m_MidiEventHandlers;
UPVector<GOSoundStateHandler> m_SoundStateHandlers;
UPVector<GOSaveableObject> m_SaveableObjects;
public:
const std::vector<GOCacheObject *> &GetCacheObjects() const {
return m_CacheObjects.AsVector();
}
const std::vector<GOReferencingObject *> &GetReferencingObjects() const {
return m_ReferencingObjects.AsVector();
}
const std::vector<GOCombinationButtonSet *> &GetCombinationButtonSets()
const {
return m_CombinationButtonSets.AsVector();
}
const std::vector<GOMidiObject *> &GetMidiConfigurators() const {
return m_MidiConfigurators.AsVector();
}
const std::vector<GOEventHandler *> &GetMidiEventHandlers() const {
return m_MidiEventHandlers.AsVector();
}
const std::vector<GOSoundStateHandler *> &GetSoundStateHandlers() const {
return m_SoundStateHandlers.AsVector();
}
const std::vector<GOSaveableObject *> &GetSaveableObjects() const {
return m_SaveableObjects.AsVector();
}
void RegisterCacheObject(GOCacheObject *obj) { m_CacheObjects.Add(obj); }
void RegisterReferencingObject(GOReferencingObject *pObj) {
m_ReferencingObjects.Add(pObj);
}
void UnRegisterReferencingObject(GOReferencingObject *pObj) {
m_ReferencingObjects.Remove(pObj);
}
void RegisterCombinationButtonSet(GOCombinationButtonSet *obj) {
m_CombinationButtonSets.Add(obj);
}
void RegisterControlChangedHandler(GOControlChangedHandler *handler) {
m_ControlChangedHandlers.Add(handler);
}
void UnRegisterControlChangedHandler(GOControlChangedHandler *handler) {
m_ControlChangedHandlers.Remove(handler);
}
void RegisterMidiConfigurator(GOMidiObject *obj) {
m_MidiConfigurators.Add(obj);
}
void RegisterEventHandler(GOEventHandler *handler) {
m_MidiEventHandlers.Add(handler);
}
void RegisterSoundStateHandler(GOSoundStateHandler *handler) {
m_SoundStateHandlers.Add(handler);
}
void UnRegisterSoundStateHandler(GOSoundStateHandler *handler) {
m_SoundStateHandlers.Remove(handler);
}
void RegisterSaveableObject(GOSaveableObject *obj) {
m_SaveableObjects.Add(obj);
}
void UnregisterSaveableObject(GOSaveableObject *obj) {
m_SaveableObjects.Remove(obj);
}
/**
* Calls ControlChanged for all ControlChanged handlers
* @param pControl - the control that state is changed
*/
void SendControlChanged(GOControl *pControl);
void Cleanup();
};
#endif /* GOEVENTHANDLERLIST_H */