-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventListenerList.cpp
More file actions
52 lines (43 loc) · 1.33 KB
/
EventListenerList.cpp
File metadata and controls
52 lines (43 loc) · 1.33 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
// Copyright 2006-12 HumaNature Studios Inc.
#include "CorePch.h"
#include "EventListenerList.h"
// needed for ~EventListener
#include "EventListener.h"
namespace core {
EventListenerList::~EventListenerList()
{
for(iterator i = begin(); i != end(); ++i)
{
SafeDelete(*i);
}
}
void EventListenerList::dispatchEvent(const Event& event)
{
if (empty())
return;
// TODO - stl sooo slow for this...
// if there's a performance issue, make our own containers,
// or replace with fast stl impl
// reverse direction for when remove is called during callback
for (iterator i = begin(); i != end();)
{
EventListener* listener = *i;
// cache this, since the listener could get deleted in a callback,
// causing the pointer to result in true
bool removeAfter = listener->mRemoveAfterDispatch;
if(removeAfter)
{
i = erase(i);
}
else
{
++i;
}
(*listener)(const_cast<Event*>(&event));
if(removeAfter)
{
SafeDelete(listener);
}
}
}
} // namespace core