2017-06-04 20:38:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace EightBit {
|
2018-04-14 08:39:06 +00:00
|
|
|
template<class T> class Signal final {
|
2017-06-04 20:38:34 +00:00
|
|
|
private:
|
2018-06-24 19:58:20 +00:00
|
|
|
typedef std::function<void(T&)> delegate_t;
|
2017-06-04 20:38:34 +00:00
|
|
|
typedef std::vector<delegate_t> delegates_t;
|
|
|
|
|
2017-11-03 22:05:01 +00:00
|
|
|
delegates_t m_delegates;
|
2017-06-04 20:38:34 +00:00
|
|
|
|
|
|
|
public:
|
2018-04-14 08:39:06 +00:00
|
|
|
void connect(const delegate_t functor) {
|
2017-11-03 22:05:01 +00:00
|
|
|
m_delegates.push_back(functor);
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 19:58:20 +00:00
|
|
|
void fire(T& e) const {
|
2018-03-10 01:53:57 +00:00
|
|
|
for (auto& delegate : m_delegates)
|
|
|
|
delegate(e);
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|