mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-11-09 13:07:15 +00:00
d70f6b375b
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
26 lines
462 B
C++
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);
|
|
}
|
|
};
|
|
}
|