EightBit/inc/Signal.h
Adrian Conlon c292fb552e A whole bunch of consistency changes. No functional changes.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2017-11-03 22:05:01 +00:00

25 lines
461 B
C++

#pragma once
#include <vector>
#include <functional>
namespace EightBit {
template<class T> class Signal {
private:
typedef std::function<void(const T&)> delegate_t;
typedef std::vector<delegate_t> delegates_t;
delegates_t m_delegates;
public:
void connect(delegate_t functor) {
m_delegates.push_back(functor);
}
void fire(const T& e) const {
if (!m_delegates.empty())
for (auto& delegate : m_delegates)
delegate(e);
}
};
}