-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventListener.h
More file actions
50 lines (36 loc) · 1.21 KB
/
EventListener.h
File metadata and controls
50 lines (36 loc) · 1.21 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
// Copyright 2006-12 HumaNature Studios Inc.
#ifndef __EVENTLISTENER_H__
#define __EVENTLISTENER_H__
namespace core {
class Event;
// internally used classes for EventDispatcher
class EventListener
: public MemoryObject
{
public:
const bool mRemoveAfterDispatch;
EventListener(bool removeAfterDispatch);
virtual ~EventListener();
virtual void operator()(const Event* event) = 0;
protected:
EventListener& operator=(const EventListener&);
};
template <class TClass>
class EventListenerTemplate : public EventListener
{
public:
TClass* mObject;
void (TClass::*mMemberFunction)(const Event* event);
EventListenerTemplate(TClass* object, void (TClass::*memberFunction)(const Event* event), bool removeAfterDispatch)
: EventListener(removeAfterDispatch)
, mObject(object)
, mMemberFunction(memberFunction)
{
};
virtual void operator()(const Event* event)
{
(*mObject.*mMemberFunction)(event);
};
};
} // namespace core
#endif // __EVENTLISTENER_H__