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>
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:
132 };
133 
134 /*****************************************************************************
135 ** Interface [Void]
136 *****************************************************************************/
148 template<>
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  }
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:
229 
230 };
231 
232 } // namespace ecl
233 
234 #endif /* ECL_SIGSLOTS_SIGNAL_HPP_ */
Signal(const Signal &signal)
Copy constructor.
Definition: signal.hpp:77
Signal(const std::string &topic)
Creates a signal and connects.
Definition: signal.hpp:163
void connectAsSlot(const std::string &topic)
Connect as a slot, with the emit function loaded.
Definition: signal.hpp:212
void connectAsSlot(const std::string &topic)
Connect as a slot, with the emit function loaded.
Definition: signal.hpp:113
Signal()
Default constructor.
Definition: signal.hpp:157
File comment.
Signal()
Default constructor.
Definition: signal.hpp:55
void emit()
The primary purpose of the signal, to emit!
Definition: signal.hpp:225
void disconnect()
Disconnect the signal from all topics.
Definition: signal.hpp:218
SigSlot< Void > * sigslot
Definition: signal.hpp:228
Signal(const std::string &topic)
Creates a signal and connects.
Definition: signal.hpp:61
void connect(const std::string &topic)
Make a connection to the specified topic.
Definition: signal.hpp:203
Not for direct use, provides the power behind both void signals and slots.
Definition: sigslot.hpp:214
void disconnect()
Disconnect the signal from all topics.
Definition: signal.hpp:119
Not for direct use, provides the power behind both signals and slots.
Definition: sigslot.hpp:46
Signalling component of a callback system.
Definition: signal.hpp:47
SigSlot< Data > * sigslot
Definition: signal.hpp:131
void connect(const std::string &topic)
Make a connection to the specified topic.
Definition: signal.hpp:104
~Signal()
Default destructor.
Definition: signal.hpp:89
void emit(Data data)
The primary purpose of the signal, to emit!
Definition: signal.hpp:128
~Signal()
Default destructor.
Definition: signal.hpp:189
#define ECL_PUBLIC
Signal(const Signal &signal)
Copy constructor.
Definition: signal.hpp:178


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