-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEvent.h
64 lines (50 loc) · 1.12 KB
/
Event.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
/*
Derivable event object for use in a derived "events" class.
Upon creation is associated with a event identifier.
*/
#pragma once
#include "BaseEvent.h"
template <typename T = void>
class Event: public BaseEvent
{
public:
typedef T return_t;
Event(name_t name = "");
template <typename... Args>
return_t call(Args... args);
};
///Public
template <typename T>
Event<T>::Event(name_t name): BaseEvent(name)
{
}
template <>
template <typename... Args>
typename Event<bool>::return_t Event<bool>::call(Args... args)
{
typedef return_t (*funct_t)(Args...);
if (!canCall())
return false;
funct_t funct;
for(functs_t::value_type& pair: functs)
{
funct = (funct_t)pair.second;
if (!funct(args...)) //Block
return false;
}
return true;
}
template <typename T>
template <typename... Args>
typename Event<T>::return_t Event<T>::call(Args... args)
{
typedef return_t (*funct_t)(Args...);
if (disabled)
return;
funct_t funct;
for(functs_t::value_type& pair: functs)
{
funct = (funct_t)pair.second;
funct(args...);
}
}