-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrivateEvent.h
70 lines (55 loc) · 1.38 KB
/
PrivateEvent.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
#pragma once
// Dependencies | std
#include <vector>
#include <functional>
// Dependencies | utility
#include <utility/DoublyLinkedList.h>
// Forward declarations | PrivateEvent
class EventListener;
class EventDispatcher;
class EventListener {
// Friends
friend class EventDispatcher;
// Object
private:
// Properties
void* owner;
EventDispatcher* eventDispatcher;
public:
// Properties
std::function<void(EventListener* eventListener, void* eventData)> function;
// Constructor / Destructor
EventListener();
EventListener(void* owner);
~EventListener();
// Getters
void* getOwner();
EventDispatcher* getEventDispatcher();
// Function
void connect(EventDispatcher& eventDispatcher);
void disconnect();
// Virtual functions
virtual void respondToEvent(void* eventData);
};
class EventDispatcher {
// Friends
friend class EventListener;
// Object
private:
// Properties
void* sender;
std::vector<EventListener*> eventListeners;
public:
// Constructor / Destructor
EventDispatcher();
EventDispatcher(void* sender);
~EventDispatcher();
// Getters
void* getSender();
std::vector<EventListener*> getEventListeners();
// Functions
void clearEventListeners();
void connect(EventListener& eventListener);
void disconnectAll();
void dispatch(void* eventData);
};