mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-23 15:29:24 +00:00
105032f08a
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
24 lines
404 B
C++
24 lines
404 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <functional>
|
|
|
|
template<class T> class Signal {
|
|
private:
|
|
typedef std::function<void(T&)> delegate_t;
|
|
typedef std::vector<delegate_t> delegates_t;
|
|
|
|
delegates_t delegates;
|
|
|
|
public:
|
|
void connect(delegate_t functor) {
|
|
delegates.push_back(functor);
|
|
}
|
|
|
|
void fire(T& e) const {
|
|
if (!delegates.empty())
|
|
for (auto& delegate : delegates)
|
|
delegate(e);
|
|
}
|
|
};
|