-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseEvent.cpp
70 lines (54 loc) · 1.14 KB
/
BaseEvent.cpp
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
#include <assert.h>
#include <algorithm>
#include "BaseEvent.h"
using namespace std;
///Public
BaseEvent::BaseEvent(name_t name): disabled(false)
{
names.push_back(name);
}
BaseEvent::name_t BaseEvent::getName()
{
return names.front();
}
bool BaseEvent::hasName(name_t name)
{
return std::find(names.begin(), names.end(), name) != names.end();
}
const BaseEvent::names_t& BaseEvent::getNames()
{
return names;
}
void BaseEvent::add(action_name_t actionName, void* funct, bool append)
{
assert(funct != NULL);
if (!append)
clear();
functs.insert(std::make_pair(actionName, funct));
}
void BaseEvent::replace(action_name_t actionName, void* funct)
{
assert(funct != NULL);
if (exists(actionName))
functs[actionName] = funct;
}
bool BaseEvent::exists(action_name_t actionName)
{
return functs.find(actionName) != functs.end();
}
bool BaseEvent::remove(action_name_t actionName)
{
functs_t::iterator it = functs.find(actionName);
if (it == functs.end())
return false;
functs.erase(it);
return true;
}
void BaseEvent::clear()
{
functs.clear();
}
bool BaseEvent::canCall()
{
return !disabled;
}