-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cpp
More file actions
121 lines (92 loc) · 2.87 KB
/
Example.cpp
File metadata and controls
121 lines (92 loc) · 2.87 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
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
// FunctionPointers.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "Event.h"
#include <iostream>
//Example Class 1
class SomeClass
{
public:
void SomeFunction()
{
printf("SomeFunction\n");
}
void FunctionWithFloat(float Number)
{
printf("This is a value: %f\n", Number);
}
void FunctionWithString(const std::string& string)
{
printf("This is a string: %s\n", string.c_str());
}
void FunctionWithMultiple(bool boolean, const std::string& string)
{
if (boolean)
{
printf("This statement is true: %s\n", string.c_str());
}
else
{
printf("This statement is false: %s\n", string.c_str());
}
}
};
//Example Class 2
class SomeOtherClass
{
public:
void SomeOtherFunction()
{
printf("SomeOtherFunction\n");
}
void SomeOtherStringfunction(const std::string& string)
{
printf("SomeOtherStringFunction: %s\n", string.c_str());
}
void SomeOtherFunctionWithMultiple(bool boolean, const std::string& string)
{
if (boolean)
{
printf("This is another true statement: %s\n", string.c_str());
}
else
{
printf("This is another false statement: %s\n", string.c_str());
}
}
};
int main()
{
//Instantiate possible subscriber objects
SomeClass* ClassOne = new SomeClass();
SomeOtherClass* ClassTwo = new SomeOtherClass();
//Event with no dispatch Arguments;
Event<> VoidEvent = Event<>();
//Event with float as dispatch argument
Event<float> FloatEvent = Event<float>();
//Event With String as dispatch argument
Event<const std::string&> StringEvent = Event<const std::string&>();
//Event with multiple dispatch arguments
Event<bool, const std::string&> MultipleEvent = Event<bool, const std::string&>();
//Register Memberfunctions of objects to a VoidEvent
VoidEvent.Register<SomeClass>(ClassOne, &SomeClass::SomeFunction);
VoidEvent.Register<SomeOtherClass>(ClassTwo, &SomeOtherClass::SomeOtherFunction);
//Register Memberfunctions of objects to a FloatEvent
FloatEvent.Register<SomeClass>(ClassOne, &SomeClass::FunctionWithFloat);
//Register Memberfunctions of objects to a string event
StringEvent.Register<SomeClass>(ClassOne, &SomeClass::FunctionWithString);
StringEvent.Register<SomeOtherClass>(ClassTwo, &SomeOtherClass::SomeOtherStringfunction);
//Register Memberfunctions of objects to multiple argument events
MultipleEvent.Register<SomeClass>(ClassOne, &SomeClass::FunctionWithMultiple);
MultipleEvent.Register<SomeOtherClass>(ClassTwo, &SomeOtherClass::SomeOtherFunctionWithMultiple);
VoidEvent.Dispatch();
FloatEvent.Dispatch(1000.0f);
StringEvent.Dispatch("String Event Dispatched!");
MultipleEvent.Dispatch(true, "Apples are a fruit");
MultipleEvent.Dispatch(false, "Apples are meat");
printf("Unregister String event");
StringEvent.UnregisterAll();
StringEvent.Dispatch("String Event Dispatched Again!");
delete ClassOne;
delete ClassTwo;
return 0;
}