STM32LIB
slot.h
Go to the documentation of this file.
1 
29 #ifndef __WINK_SLOT_H__
30 #define __WINK_SLOT_H__
31 
32 #include "fd/FastDelegate.h"
33 
34 namespace wink
35 {
41  template <typename Signature>
42  struct slot
43  {
44  private:
45 
47 
48  public:
49 
51  typedef Signature FnPtr;
52 
56  static slot<Signature> bind(Signature fn)
57  {
58  return slot_type(fn);
59  }
60 
63  template <typename T, typename MemFnPtr>
64  static slot<Signature> bind(T* obj, MemFnPtr fn)
65  {
66  return __this_type(obj, fn);
67  }
68 
70  slot()
71  {}
72 
75  slot(FnPtr fn)
76  : _delegate(fn)
77  {}
78 
82  template <typename T, typename MemFnPtr>
83  slot(T* obj, MemFnPtr fn)
84  : _delegate(obj, fn)
85  {}
86 
88  slot(const __this_type& slot)
89  : _delegate(slot._delegate)
90  {}
91 
93  ~slot() {}
94 
98  __this_type& operator=(const __this_type& slot)
99  {
100  _delegate = slot._delegate;
101  return *this;
102  }
103 
106  template <class ...Args>
107  void operator()(Args&&... args) const
108  {
109  _delegate(args...);
110  }
111 
112 
113  // comparision operators for sorting and comparing
114 
115  bool operator==(const __this_type& slot) const
116  { return _delegate == slot._delegate; }
117 
118  bool operator!=(const __this_type& slot) const
119  { return !operator==(slot); }
120 
121  bool operator<(const __this_type& slot) const
122  { return _delegate < slot._delegate; }
123 
124  bool operator>(const __this_type& slot) const
125  { return slot._delegate < _delegate; }
126 
127  bool operator<=(const __this_type& slot) const
128  { return operator>(slot); }
129 
130  bool operator>=(const __this_type& slot) const
131  { return operator<(slot); }
132 
133  private:
134 
136  typedef fastdelegate::FastDelegate<Signature> __impl_delegate;
137 
138 
139  __impl_delegate _delegate;
140  };
141 }
142 
143 
144 #endif // __WINK_SLOT_H__
~slot()
Destructor.
Definition: slot.h:93
slot(FnPtr fn)
Definition: slot.h:75
bool operator>(const __this_type &slot) const
Definition: slot.h:124
slot(const __this_type &slot)
Copy constructor.
Definition: slot.h:88
static slot< Signature > bind(Signature fn)
Definition: slot.h:56
fastdelegate::FastDelegate< Signature > __impl_delegate
The implementation of the slot, as a delegate.
Definition: slot.h:136
__impl_delegate _delegate
Definition: slot.h:139
slot< Signature > __this_type
Definition: slot.h:46
void operator()(Args &&...args) const
Definition: slot.h:107
bool operator<=(const __this_type &slot) const
Definition: slot.h:127
__this_type & operator=(const __this_type &slot)
Definition: slot.h:98
bool operator==(const __this_type &slot) const
Definition: slot.h:115
Signature FnPtr
A static function pointer with the correct signature.
Definition: slot.h:51
slot(T *obj, MemFnPtr fn)
Definition: slot.h:83
bool operator!=(const __this_type &slot) const
Definition: slot.h:118
bool operator>=(const __this_type &slot) const
Definition: slot.h:130
static slot< Signature > bind(T *obj, MemFnPtr fn)
Definition: slot.h:64
slot()
Construct a slot with no call-back.
Definition: slot.h:70
Definition: signal.h:37
bool operator<(const __this_type &slot) const
Definition: slot.h:121
Describes a slot that may be added to a signal, or used stand-alone for a call-back.
Definition: slot.h:42