-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.cpp
47 lines (41 loc) · 969 Bytes
/
Events.cpp
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
#include "Events.hpp"
namespace gGUI {
void Slot::disconnect(Signal &sig)
{
auto it = signals.begin();
while (it != signals.end() and *it != &sig)
++it;
if (it != signals.end())
signals.erase(it);
}
Slot::~Slot()
{
for (auto sig : signals)
sig->disconnect(*this);
}
void Signal::connect(Slot &slt)
{
slots.push_back(&slt);
slt.signals.push_back(this);
}
void Signal::disconnect(Slot &slt)
{
auto it = slots.begin();
while (it != slots.end() and *it != &slt)
++it;
if (it != slots.end())
slots.erase(it);
}
void Signal::call(Event ev)
{
for (auto elem : slots) {
assert(elem->widget);
((elem->widget)->*(elem->handler))(ev);
}
}
Signal::~Signal()
{
for (auto slt : slots)
slt->disconnect(*this);
}
}