slot.hpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Ifdefs
12 *****************************************************************************/
13 
14 #ifndef ECL_SIGSLOTS_SLOT_HPP_
15 #define ECL_SIGSLOTS_SLOT_HPP_
16 
17 /*****************************************************************************
18 ** Includes
19 *****************************************************************************/
20 
21 #include "sigslot.hpp"
22 #include <ecl/config/macros.hpp>
23 #include <ecl/utilities/void.hpp>
24 
25 /*****************************************************************************
26 ** Namespaces
27 *****************************************************************************/
28 
29 namespace ecl {
30 
31 /*****************************************************************************
32 ** Interface [General]
33 *****************************************************************************/
34 
47 template <typename Data=Void>
48 class ECL_PUBLIC Slot {
49 public:
58  Slot(void (*f)(Data)) : sigslot(NULL) {
59  sigslot = new SigSlot<Data>(f);
60  }
72  Slot(void (*f)(Data), const std::string &topic) : sigslot(NULL) {
73  sigslot = new SigSlot<Data>(f);
74  connect(topic);
75  }
76 
86  template <typename C>
87  Slot(void (C::*f)(Data), C &c) : sigslot(NULL) {
88  sigslot = new SigSlot<Data>(f,c);
89  }
102  template <typename C>
103  Slot(void (C::*f)(Data), C &c, const std::string& topic) : sigslot(NULL) {
104  sigslot = new SigSlot<Data>(f,c);
105  connect(topic);
106  }
107 
119  Slot(const Slot& slot) {
120  *this = slot;
121  sigslot->incrHandles();
122  }
123 
131  ~Slot() {
132  sigslot->decrHandles();
133  if ( sigslot->handles() == 0 ) {
134  delete sigslot;
135  }
136  }
143  const std::set<std::string>& connections() { return sigslot->subscribedTopics(); }
152  void connect(const std::string& topic) { sigslot->connectSlot(topic); }
158  void disconnect() { sigslot->disconnect(); }
159 
160 private:
161  SigSlot<Data>* sigslot;
162 };
163 
164 /*****************************************************************************
165 ** Interface [Void]
166 *****************************************************************************/
176 template<>
177 class ECL_PUBLIC Slot<Void> {
178 public:
187  Slot(VoidFunction f) : sigslot(NULL) {
188  sigslot = new SigSlot<Void>(f);
189  }
199  Slot(VoidFunction f, const std::string &topic) : sigslot(NULL) {
200  sigslot = new SigSlot<Void>(f);
201  connect(topic);
202  }
212  template <typename C>
213  Slot(void (C::*f)(void), C &c) : sigslot(NULL) {
214  sigslot = new SigSlot<Void>(f,c);
215  }
226  template <typename C>
227  Slot(void (C::*f)(void), C &c, const std::string &topic) : sigslot(NULL) {
228  sigslot = new SigSlot<Void>(f,c);
229  connect(topic);
230  }
242  Slot(const Slot& slot) {
243  *this = slot;
244  sigslot->incrHandles();
245  }
253  ~Slot() {
254  sigslot->decrHandles();
255  if ( sigslot->handles() == 0 ) {
256  delete sigslot;
257  }
258  }
267  void connect(const std::string& topic) { sigslot->connectSlot(topic); }
273  void disconnect() { sigslot->disconnect(); }
274 
275 private:
276  SigSlot<Void>* sigslot;
277 
278 // unused:
279 // unsigned int copies() { return sigslot->handles(); }
280 };
281 
282 } // namespace ecl
283 
284 #endif /* ECL_SIGSLOTS_SLOT_HPP_ */
ecl::Slot
Function loading component of a callback system.
Definition: slot.hpp:54
ecl::SigSlot
Not for direct use, provides the power behind both signals and slots.
Definition: sigslot.hpp:52
ecl::Void
ecl::VoidFunction
void(* VoidFunction)()
f
void f(int i)
ecl::SigSlot< Void >
Not for direct use, provides the power behind both void signals and slots.
Definition: sigslot.hpp:220
ecl::Slot::Slot
Slot(void(*f)(Data))
Load with a global/static function.
Definition: slot.hpp:72
ecl::Slot::disconnect
void disconnect()
Disconnect the slot from all topics.
Definition: slot.hpp:172
void.hpp
sigslot.hpp
File comment.
macros.hpp
ecl
ECL_PUBLIC
#define ECL_PUBLIC


ecl_sigslots
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:47