2017-06-04 21:38:34 +01:00
|
|
|
#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;
|
|
|
|
|
2017-11-03 22:05:01 +00:00
|
|
|
delegates_t m_delegates;
|
2017-06-04 21:38:34 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
void connect(delegate_t functor) {
|
2017-11-03 22:05:01 +00:00
|
|
|
m_delegates.push_back(functor);
|
2017-06-04 21:38:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void fire(const T& e) const {
|
2017-11-03 22:05:01 +00:00
|
|
|
if (!m_delegates.empty())
|
|
|
|
for (auto& delegate : m_delegates)
|
2017-06-04 21:38:34 +01:00
|
|
|
delegate(e);
|
|
|
|
}
|
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|