-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (56 loc) · 1.48 KB
/
main.cpp
File metadata and controls
71 lines (56 loc) · 1.48 KB
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
#include <iostream>
#include <functional>
#include <vector>
#include "observable.h"
class Callback : public Observable<
void(void),
void(int,std::string),
void(int,int)
>
{
public:
private:
int a;
std::string s;
};
class ReceiverA
{
public:
void EventZeroHappened()
{
std::cout << "A has observed event zero\n";
}
void EventOneHappened(int a, std::string s)
{
std::cout << "A has observed event one with params: " << a << " and " << "\"" << s << "\"" <<'\n';
}
void EventTwoHappened(int a, int b)
{
std::cout << "A has observed event two with params: " << a << " and " << b <<'\n';
}
};
class ReceiverB
{
public:
void EventZeroHappened()
{
std::cout << "B has observed event zero\n";
}
};
int main()
{
Callback cb;
ReceiverA r1;
ReceiverB r2;
cb.registerCallback<0, 100>([&r1](){r1.EventZeroHappened();});
cb.registerCallback<1, 101>([&r1](int i, std::string s){r1.EventOneHappened(i,s);});
cb.registerCallback<2, 102>([&r1](int i, int j){r1.EventTwoHappened(i,j);});
cb.registerCallback<0, 103>([&r2](){r2.EventZeroHappened();});
cb.raiseEvent<0>();
cb.raiseEvent<1>(37,"Hello There");
cb.raiseEvent<2>(182,150);
std::cout << "pre";
cb.unregisterCallback<0, 104>([&r2](){r2.EventZeroHappened();});
std::cout << "apres";
cb.raiseEvent<0>();
}