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_ */
ecl::Void
ecl::SigSlot< Void >
Not for direct use, provides the power behind both void signals and slots.
Definition: sigslot.hpp:220
ecl::Signal
Signalling component of a callback system.
Definition: signal.hpp:53
void.hpp
ecl::Signal::disconnect
void disconnect()
Disconnect the signal from all topics.
Definition: signal.hpp:133
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