slot.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_SIGSLOTS_LITE_SLOT_HPP_
13 #define ECL_SIGSLOTS_LITE_SLOT_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <cstddef> // defines NULL
20 
21 /*****************************************************************************
22 ** Namespaces
23 *****************************************************************************/
24 
25 namespace ecl {
26 namespace lite {
27 
28 /*****************************************************************************
29 ** Slots
30 *****************************************************************************/
31 
32 namespace sigslots {
40 template <typename Data>
41 class SlotBase {
42 public:
43  virtual void execute(Data data) = 0;
44 };
51 template <typename Data, typename FunctionClass>
52 class MemberSlot : public SlotBase<Data> {
53 public:
55  MemberSlot(void (FunctionClass::*func)(Data), FunctionClass &instance) :
56  object(&instance),
57  member_function(func)
58  {}
59 
60  void execute(Data data) {
61  (*object.*member_function)(data);
62  }
63  FunctionClass *object;
64  void (FunctionClass::*member_function)(Data);
65 private:
66 };
67 
68 
74 template <typename Data>
75 class GlobalSlot : public SlotBase<Data> {
76 public:
77  GlobalSlot() : global_function(NULL) {}
78  GlobalSlot(void (*func)(Data)) : global_function(func) {}
79 
80  void execute(Data data) {
81  if ( global_function != NULL ) {
82  (*global_function)(data);
83  }
84  }
85  void (*global_function)(Data);
86 };
87 
88 /*****************************************************************************
89 ** Slot Specialisations
90 *****************************************************************************/
91 
97 template <>
98 class SlotBase<void> {
99 public:
100  virtual void execute() = 0;
101 };
102 
109 template <typename FunctionClass>
110 class MemberSlot<void,FunctionClass> : public SlotBase<void> {
111 public:
113  MemberSlot(void (FunctionClass::*func)(void), FunctionClass &instance) :
114  object(&instance),
115  member_function(func)
116  {}
117 
118  void execute() {
119  (*object.*member_function)();
120  }
121  FunctionClass *object;
122  void (FunctionClass::*member_function)(void);
123 private:
124 };
125 
131 template <>
132 class GlobalSlot<void> : public SlotBase<void> {
133 public:
134  GlobalSlot() : global_function(NULL) {}
135  GlobalSlot(void (*func)(void)) : global_function(func) {}
136 
137  void execute() {
138  if ( global_function != NULL ) {
139  (*global_function)();
140  }
141  }
142  void (*global_function)(void);
143 };
144 
145 } // namespace sigslots
146 } // namespace lite
147 } // namespace ecl
148 
149 #endif /* ECL_SIGSLOTS_LITE_SLOT_HPP_ */
GlobalSlot(void(*func)(Data))
Definition: slot.hpp:78
A slot with member callback function.
Definition: slot.hpp:52
void execute(Data data)
Definition: slot.hpp:60
virtual void execute(Data data)=0
void execute(Data data)
Definition: slot.hpp:80
Parent slot class with the common, publicly exposed interface.
Definition: slot.hpp:41
MemberSlot(void(FunctionClass::*func)(void), FunctionClass &instance)
Definition: slot.hpp:113
A slot with global/static callback function.
Definition: slot.hpp:75
FunctionClass * object
Definition: slot.hpp:63
MemberSlot(void(FunctionClass::*func)(Data), FunctionClass &instance)
Definition: slot.hpp:55


ecl_sigslots_lite
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:09:06