STM32LIB
signal.h
Go to the documentation of this file.
1 
33 #pragma once
34 #include <forward_list>
35 
36 
37 namespace wink {
38  template<class Slot>
39  struct signal {
40 
41  protected:
42 
43  typedef Slot slot_type;
44  std::forward_list<slot_type> _slots;
45 
46  public:
47 
51 
52  void insertSubscriber(const slot_type& slot) {
53  _slots.push_front(slot);
54  }
55 
59 
60  bool removeSubscriber(const slot_type& slot) {
61 
62  for(auto it=_slots.begin();it!=_slots.end();it++) {
63  if(*it==slot) {
64  _slots.erase(it);
65  return true;
66  }
67  }
68  return false;
69  }
70 
73  template <class ...Args>
74  void raiseEvent(Args&&... args) const {
75 
76  for(auto it=_slots.begin();it!=_slots.end();it++)
77  (*it)(args...);
78  }
79  };
80 }
Definition: signal.h:39
Slot slot_type
Definition: signal.h:43
bool removeSubscriber(const slot_type &slot)
Definition: signal.h:60
std::forward_list< slot_type > _slots
Definition: signal.h:44
void raiseEvent(Args &&...args) const
Definition: signal.h:74
void insertSubscriber(const slot_type &slot)
Definition: signal.h:52
Definition: signal.h:37
Describes a slot that may be added to a signal, or used stand-alone for a call-back.
Definition: slot.h:42