signal.hpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Ifdefs
12 *****************************************************************************/
13 
14 #ifndef ECL_SIGSLOTS_LITE_SIGNAL_HPP_
15 #define ECL_SIGSLOTS_LITE_SIGNAL_HPP_
16 
17 /*****************************************************************************
18 ** Includes
19 *****************************************************************************/
20 
21 #include "slot.hpp"
22 #include "errors.hpp"
23 
24 /*****************************************************************************
25 ** Namespaces
26 *****************************************************************************/
27 
28 namespace ecl {
29 namespace lite {
30 
31 /*****************************************************************************
32 ** Classes
33 *****************************************************************************/
62 template <typename Data=void, unsigned int Capacity = 1>
63 class Signal {
64 public:
68  Signal() {
69  for ( unsigned int i = 0; i < Capacity; ++i) {
70  slots[i] = NULL;
71  }
72  }
89  for (unsigned int i = 0; i < Capacity; ++i ) {
90  if ( slots[i] == NULL ) {
91  slots[i] = &slot;
93  }
94  }
95  // if we reach here, we've run out of resources.
97  }
103  unsigned int capacity() const { return Capacity; }
109  unsigned int stored() const {
110  unsigned int i;
111  for (i = 0; i < Capacity; ++i ) {
112  if ( slots[i] == NULL ) {
113  break;
114  }
115  }
116  return i;
117 
118  }
119 
125  void emit(Data data) const {
126  for (unsigned int i = 0; i < Capacity; ++i ) {
127  if ( slots[i] == NULL ) {
128  break;
129  } else {
130  slots[i]->execute(data);
131  }
132  }
133  }
134 
135 private:
137 };
138 
147 template <unsigned int Capacity>
148 class Signal<void,Capacity> {
149 public:
153  Signal() {
154  for ( unsigned int i = 0; i < Capacity; ++i) {
155  slots[i] = NULL;
156  }
157  }
174  for (unsigned int i = 0; i < Capacity; ++i ) {
175  if ( slots[i] == NULL ) {
176  slots[i] = &slot;
178  }
179  }
180  // if we reach here, we've run out of resources.
182  }
188  unsigned int capacity() const { return Capacity; }
189 
195  unsigned int stored() const {
196  unsigned int i;
197  for (i = 0; i < Capacity; ++i ) {
198  if ( slots[i] == NULL ) {
199  break;
200  }
201  }
202  return i;
203 
204  }
208  void emit() const {
209  for (unsigned int i = 0; i < Capacity; ++i ) {
210  if ( slots[i] == NULL ) {
211  break;
212  } else {
213  slots[i]->execute();
214  }
215  }
216  }
217 
218 private:
220 };
221 
222 
223 } // namespace lite
224 } // namespace ecl
225 
226 #endif /* ECL_SIGSLOTS_LITE_SIGNAL_HPP_ */
Error handling types and classes for lite sigslots.
A simple signal class.
Definition: managers.hpp:32
sigslots::Error connect(sigslots::SlotBase< Data > &slot)
Connect the signal to the specified slot.
Definition: signal.hpp:88
Signal()
Initialise the storage.
Definition: signal.hpp:153
void emit(Data data) const
Signal slots with the specified data.
Definition: signal.hpp:125
Extends the generic ecl error handler with some time specific error strings.
Definition: errors.hpp:41
unsigned int capacity() const
The reserved capacity for this signaller.
Definition: signal.hpp:188
sigslots::SlotBase< Data > * slots[Capacity]
Definition: signal.hpp:136
sigslots::Error connect(sigslots::SlotBase< void > &slot)
Connect the signal to the specified slot.
Definition: signal.hpp:173
Signal()
Initialise the storage.
Definition: signal.hpp:68
Parent slot class with the common, publicly exposed interface.
Definition: slot.hpp:98
Parent slot class with the common, publicly exposed interface.
Definition: slot.hpp:41
unsigned int stored() const
The current number of connections stored.
Definition: signal.hpp:109
void emit() const
Signal slots with the specified data.
Definition: signal.hpp:208
unsigned int capacity() const
The reserved capacity for this signaller.
Definition: signal.hpp:103
unsigned int stored() const
The current number of connections stored.
Definition: signal.hpp:195
Simple slots - these are actually all hidden from the user.


ecl_sigslots_lite
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:09:06