EightBit/inc/Signal.h
Adrian Conlon d70f6b375b Ensure each header file has a newline on its own at the end of each file.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2017-11-30 23:19:17 +00:00

26 lines
462 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);
}
};
}