-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
executable file
·75 lines (58 loc) · 1.35 KB
/
Copy pathtest.cpp
File metadata and controls
executable file
·75 lines (58 loc) · 1.35 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
72
73
74
#include "events.h"
#include <iostream>
using namespace tjm::events;
class Test
{
public:
Event0<Test> ItemMoved;
void Move() { ItemMoved.Fire(); }
// Other random events..
PublicEvent0 EventA;
Event1<Test,int> EventB;
PublicEvent1<int> EventC;
Event2<Test,int,int> EventD;
PublicEvent2<int,int> EventE;
Event3<Test,int,int,int> EventF;
PublicEvent3<int,int,int> EventG;
};
void Hi0()
{
std::cout << "Hi0!\n";
}
void Hi1(int x)
{
std::cout << "Hi1! " << x << "\n";
}
void Hi2(int x, int y)
{
std::cout << "Hi2! " << x << " " << y << "\n";
}
void Hi3(int x, int y, int z)
{
std::cout << "Hi3! " << x << " " << y << " " << z << "\n";
}
int main()
{
Test t;
// Register a callback when the ItemMoved event is fired
int mine = t.ItemMoved += Hi0;
// Same as above
// int mine = t.ItemMoved.Register(Hi0);
// This line doesn't compile, Fire is a private method
//t.ItemMoved.Fire();
// Should print out "Hi0!"
t.Move();
// Unregister
t.ItemMoved -= mine;
// Same as above
// t.ItemMoved.Unregister(mine);
// You can call Fire directly on public events
t.EventA.Fire();
// You can pass parameters to Events
t.EventC += Hi1;
t.EventC.Fire(42);
t.EventE += Hi2;
t.EventE.Fire(4, 20);
t.EventG += Hi3;
t.EventG.Fire(1, 2, 3);
}