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>
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:
162 };
163 
164 /*****************************************************************************
165 ** Interface [Void]
166 *****************************************************************************/
176 template<>
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:
277 
278 // unused:
279 // unsigned int copies() { return sigslot->handles(); }
280 };
281 
282 } // namespace ecl
283 
284 #endif /* ECL_SIGSLOTS_SLOT_HPP_ */
void connect(const std::string &topic)
Make a connection to the specified topic.
Definition: slot.hpp:267
Slot(VoidFunction f)
Load with a global/static function.
Definition: slot.hpp:187
Slot(VoidFunction f, const std::string &topic)
Load with a global/static function and connect.
Definition: slot.hpp:199
Slot(const Slot &slot)
Copy constructor.
Definition: slot.hpp:242
Slot(void(C::*f)(void), C &c, const std::string &topic)
Load with a member function and connect.
Definition: slot.hpp:227
Slot(const Slot &slot)
Copy constructor.
Definition: slot.hpp:119
~Slot()
Default destructor.
Definition: slot.hpp:253
Slot(void(C::*f)(Data), C &c, const std::string &topic)
Load with a member function and connect.
Definition: slot.hpp:103
void(* VoidFunction)()
~Slot()
Default destructor.
Definition: slot.hpp:131
File comment.
SigSlot< Void > * sigslot
Definition: slot.hpp:276
Slot(void(*f)(Data))
Load with a global/static function.
Definition: slot.hpp:58
Slot(void(*f)(Data), const std::string &topic)
Load with a global/static function and connect.
Definition: slot.hpp:72
void connect(const std::string &topic)
Make a connection to the specified topic.
Definition: slot.hpp:152
void disconnect()
Disconnect the slot from all topics.
Definition: slot.hpp:273
const std::set< std::string > & connections()
Lists the topics this slot is connected to.
Definition: slot.hpp:143
Slot(void(C::*f)(Data), C &c)
Load with a member function.
Definition: slot.hpp:87
Not for direct use, provides the power behind both void signals and slots.
Definition: sigslot.hpp:214
void f(int i)
void disconnect()
Disconnect the slot from all topics.
Definition: slot.hpp:158
Slot(void(C::*f)(void), C &c)
Load with a member function.
Definition: slot.hpp:213
Not for direct use, provides the power behind both signals and slots.
Definition: sigslot.hpp:46
SigSlot< Data > * sigslot
Definition: slot.hpp:161
Function loading component of a callback system.
Definition: slot.hpp:48
#define ECL_PUBLIC


ecl_sigslots
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:57