A simple signal class. More...
#include <signal.hpp>
Public Member Functions | |
unsigned int | capacity () const |
The reserved capacity for this signaller. | |
sigslots::Error | connect (sigslots::SlotBase< Data > &slot) |
Connect the signal to the specified slot. | |
void | emit (Data data) const |
Signal slots with the specified data. | |
Signal () | |
Initialise the storage. | |
unsigned int | stored () const |
The current number of connections stored. | |
Private Attributes | |
sigslots::SlotBase< Data > * | slots [Capacity] |
A simple signal class.
This class, once instantiated and connected is a fixed entity. Memory reserved for slots is fixed and disconnects are not possible This allows us to avoid the use of new and in most low level control programs, such disconnects are rarely used anyway.
To reserve the capacity (i.e. no. of slots that can be attached) configure the second template parameter upon instantiation. Note that the default is 1.
void f(int i) { std::cout << i << std::endl; } int main() { Signal<int,1> signal; // Signal<int> provides a default of 1 connect(signal,f) signal.emit(3); // ...
Data | : the data type to emit. |
Capacity | : the number of slot connections to reserve. |
Definition at line 63 of file signal.hpp.
ecl::lite::Signal< Data, Capacity >::Signal | ( | ) | [inline] |
Initialise the storage.
Definition at line 68 of file signal.hpp.
unsigned int ecl::lite::Signal< Data, Capacity >::capacity | ( | ) | const [inline] |
The reserved capacity for this signaller.
Definition at line 103 of file signal.hpp.
sigslots::Error ecl::lite::Signal< Data, Capacity >::connect | ( | sigslots::SlotBase< Data > & | slot | ) | [inline] |
Connect the signal to the specified slot.
This will attach the slot (note that it is a permanent attachment) so long as the reserved capacity isn't already fully utilised.
Valid return values:
slot | : the slot to connect. |
Definition at line 88 of file signal.hpp.
void ecl::lite::Signal< Data, Capacity >::emit | ( | Data | data | ) | const [inline] |
Signal slots with the specified data.
data | : the data to send to the slots. |
Definition at line 125 of file signal.hpp.
unsigned int ecl::lite::Signal< Data, Capacity >::stored | ( | ) | const [inline] |
The current number of connections stored.
Definition at line 109 of file signal.hpp.
sigslots::SlotBase<Data>* ecl::lite::Signal< Data, Capacity >::slots[Capacity] [private] |
Definition at line 136 of file signal.hpp.