signal.hpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Ifdefs
12 *****************************************************************************/
13 
14 #ifndef ECL_SIGSLOTS_SIGNAL_HPP_
15 #define ECL_SIGSLOTS_SIGNAL_HPP_
16 
17 /*****************************************************************************
18 ** Includes
19 *****************************************************************************/
20 
21 #include "sigslot.hpp"
22 #include <ecl/utilities/void.hpp>
23 #include <ecl/config/macros.hpp>
24 
25 /*****************************************************************************
26 ** Namespaces
27 *****************************************************************************/
28 
29 namespace ecl {
30 
31 /*****************************************************************************
32 ** Interface [General]
33 *****************************************************************************/
46 template <typename Data=Void>
47 class ECL_PUBLIC Signal {
48 public:
55  Signal() : sigslot(NULL) {
56  sigslot = new SigSlot<Data>();
57  }
61  Signal(const std::string &topic) : sigslot(NULL) {
62  sigslot = new SigSlot<Data>();
63  connect(topic);
64  }
65 
77  Signal(const Signal& signal) {
78  *this = signal;
79  sigslot->incrHandles();
80  }
81 
89  ~Signal() {
90  sigslot->decrHandles();
91  if ( sigslot->handles() == 0 ) {
92  delete sigslot;
93  }
94  }
95 
104  void connect(const std::string& topic) { sigslot->connectSignal(topic); }
113  void connectAsSlot(const std::string& topic) { sigslot->connectSlot(topic); }
119  void disconnect() { sigslot->disconnect(); }
120 
128  void emit(Data data) { sigslot->emit(data); }
129 
130 private:
131  SigSlot<Data>* sigslot;
132 };
133 
134 /*****************************************************************************
135 ** Interface [Void]
136 *****************************************************************************/
148 template<>
149 class ECL_PUBLIC Signal<Void> {
150 public:
157  Signal() : sigslot(NULL) {
158  sigslot = new SigSlot<Void>();
159  }
163  Signal(const std::string &topic) : sigslot(NULL) {
164  sigslot = new SigSlot<Void>();
165  connect(topic);
166  }
178  Signal(const Signal& signal) {
179  *this = signal;
180  sigslot->incrHandles();
181  }
189  ~Signal() {
190  sigslot->decrHandles();
191  if ( sigslot->handles() == 0 ) {
192  delete sigslot;
193  }
194  }
203  void connect(const std::string& topic) { sigslot->connectSignal(topic); }
212  void connectAsSlot(const std::string& topic) { sigslot->connectSlot(topic); }
218  void disconnect() { sigslot->disconnect(); }
219 
225  void emit() { sigslot->emit(); }
226 
227 private:
228  SigSlot<Void>* sigslot;
229 
230 };
231 
232 } // namespace ecl
233 
234 #endif /* ECL_SIGSLOTS_SIGNAL_HPP_ */
#define ECL_PUBLIC


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13