| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #ifndef SOPHIAR2_TINY_SIGNAL_HPP
- #define SOPHIAR2_TINY_SIGNAL_HPP
- #include <boost/intrusive/list.hpp>
- #include <type_traits>
- template<typename... Args>
- class tiny_signal {
- public:
- using hook_type = boost::intrusive::list_base_hook<
- boost::intrusive::link_mode<
- boost::intrusive::auto_unlink>>;
- struct listener_type : public hook_type {
- virtual void on_signal_received(Args... args) = 0;
- };
- using list_type = boost::intrusive::list<
- listener_type, boost::intrusive::constant_time_size<false>>;
- void add_listener(listener_type &node) {
- if (node.is_linked()) {
- node.unlink();
- }
- node_list.push_back(node);
- }
- void emit_signal(Args... args) {
- for (auto &node: node_list) {
- node.on_signal_received(args...);
- }
- }
- private:
- list_type node_list;
- };
- #endif //SOPHIAR2_TINY_SIGNAL_HPP
|