-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventListenerList.h
More file actions
51 lines (40 loc) · 1.55 KB
/
EventListenerList.h
File metadata and controls
51 lines (40 loc) · 1.55 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
// Copyright 2006-12 HumaNature Studios Inc.
#ifndef __EVENTLISTENERLIST_H__
#define __EVENTLISTENERLIST_H__
#include "EventListener.h"
namespace core {
class Event;
class EventListenerList
: public std::list<EventListener*>
{
public:
~EventListenerList();
// gets called for all events
template <typename tListener>
void addEventListener(tListener* listener, void (tListener::*memberFunction)(const Event* event), bool removeAfterDispatch=false)
{
push_back(HNS_NEW_TAGGED(EventListenerTemplate<tListener>, GetCoreTypeName<tListener>())(listener, memberFunction, removeAfterDispatch));
}
template <typename tListener>
void removeEventListener(tListener* listener, void (tListener::*memberFunction)(const Event* event))
{
EventListenerList::iterator iter = begin();
for(; iter != end();)
{
EventListenerTemplate<tListener>* listenerDownCast = static_cast<EventListenerTemplate<tListener>*>(*iter);
if(listenerDownCast->mObject == listener
&& listenerDownCast->mMemberFunction == memberFunction)
{
SafeDelete(*iter);
iter = erase(iter);
}
else
{
++iter;
}
}
}
void dispatchEvent(const Event& event);
};
} // namespace core
#endif // __EVENTLISTENERLIST_H__