-
Notifications
You must be signed in to change notification settings - Fork 8
/
CCallback.cpp
41 lines (34 loc) · 879 Bytes
/
CCallback.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
#include "pch.h"
#include "CCallback.h"
template<class T, class... Args>
CCallback<T(Args...)>::CCallback() : callbacks()
{
}
template<class T, class... Args>
CCallback<T(Args...)>::~CCallback()
{
UnbindAll();
}
template<class T, class... Args>
CCallback<T(Args...)> &CCallback<T(Args...)>::operator+=(CFunction<T, Args...> Y)
{
callbacks.push_back(Y);
return *this;
}
template<class T, class... Args>
CCallback<T(Args...)> &CCallback<T(Args...)>::operator-=(CFunction<T, Args...> Y)
{
callbacks.erase(std::remove(callbacks.begin(), callbacks.end(), Y), callbacks.end());
return *this;
}
template<class T, class... Args>
void CCallback<T(Args...)>::UnbindAll()
{
callbacks.clear();
}
template<class T, class... Args>
void CCallback<T(Args...)>::operator()(Args... args)
{
for (CFunction<T, Args...> func : callbacks)
(*func)(args...);
}