itpp::Signal< DataType > Class Template Reference

Signals and slots. More...

`#include <itpp/protocol/signals_slots.h>`

## Public Member Functions

| Signal (const std::string signal_name="Unamed Signal", const bool single_shot=false, const bool enable_debug=false)
| Default constructor.
| ~Signal ()
| Destructor.
void | connect (Base_Slot< DataType > *slot)
| Connect a slot to the signal.
void | disconnect (Base_Slot< DataType > *slot=NULL)
| Disconnect the slot from the signal.
Base_Event * | operator() (DataType signal, const Ttype delta_time=0)
| Issue a signal.
void | cancel ()
| cancel signal
void | set_name (const std::string &signal_name)
| set name of signal
void | set_debug (const bool enable_debug=true)
| Set debug mode. If true all signals are printed to stdout.
void | trigger (DataType u)
| ADD DOCUMENTATION HERE.

## Protected Types

typedef std::list< Base_Slot< DataType > *, std::allocator< Base_Slot< DataType > * > >::iterator | Base_Slot_Iterator
| ADD DOCUMENTATION HERE.

## Protected Member Functions

void | _disconnect (Base_Slot< DataType > *slot)
| ADD DOCUMENTATION HERE.

## Protected Attributes

std::list< Base_Slot< DataType > *, std::allocator< Base_Slot< DataType > * > > | connected_slots
| ADD DOCUMENTATION HERE.
std::string | name
| ADD DOCUMENTATION HERE.

## Friends

class | Base_Slot< DataType >

## Detailed Description

template<class DataType>
class itpp::Signal< DataType >

Signals and slots.

A simple example where to objects A and B are communicating through signals and slots. Each object has one signal and one slot. The A_signal is used to send a signal to the B_slot and vice versa. When a signal is received by the B_slot it is forwarded to the function forward(). The class definition includes the definition of the signals, slots and forward functions including a name and the type of data to transmit.

#include "signals_slots.h"
class A;
class B;
class A {
public:
A(){
A_slot.forward(this, &A::member);
A_signal.set_name("A_signal");
A_signal.set_debug(true);
A_slot.set_name("A_slot");
N = 10;
}
Signal<int> A_signal;
Slot<A, double> A_slot;
private:
int N;
void member(const double x) {
if(N)
A_signal.arm(3.4, N--);
}
};
class B {
public:
B(){
B_slot.forward(this, &B::member);
B_signal.set_name("B_signal");
B_signal.set_debug();
B_slot.set_name("B_slot");
}
Signal<double> B_signal;
Slot<B, int> B_slot;
private:
void member(const int k){ B_signal.arm(23.2, M_PI); }
};
int main(){
A a; // class A does not know anything about class B.
B b; // class B does not know anything about class A.
a.A_signal.connect(&b.B_slot); // Connect a to b.
b.B_signal.connect(&a.A_slot); // Connect b to a.
a.A_signal.arm(56.2, 3); // First event in 56.2 seconds carrying data = 3
Event_Queue::start(); // start the event-based simulation
}
itpp::Event_Queue::start
static void start()
Start executing events.
Definition events.cpp:67
itpp::Signal
Signals and slots.
Definition signals_slots.h:125
itpp::Signal::set_name
void set_name(const std::string &signal_name)
set name of signal
Definition signals_slots.h:419
itpp::Slot
Slot Class.
Definition signals_slots.h:221
signals_slots.h
Definitions of Signals and Slots classes.

Definition at line 124 of file signals_slots.h.

## Member Typedef Documentation

## Base_Slot_Iterator

template<class DataType>

typedef std::list<Base_Slot<DataType>*,std::allocator<Base_Slot<DataType>*>>::iterator itpp::Signal< DataType >::Base_Slot_Iterator

protected

ADD DOCUMENTATION HERE.

Definition at line 163 of file signals_slots.h.

## Constructor & Destructor Documentation

## Signal()

template<class DataType>

itpp::Signal< DataType >::Signal | ( | const std::string | signal_name = "Unamed Signal< DataType >",
|  | const bool | single_shot = false,
|  | const bool | enable_debug = false )

Default constructor.

Definition at line 392 of file signals_slots.h.

References set_debug(), and set_name().

## ~Signal()

template<class DataType>

itpp::Signal< DataType >::~Signal | ( |  | ) |

Destructor.

Definition at line 402 of file signals_slots.h.

References connected_slots.

## Member Function Documentation

## connect()

template<class DataType>

void itpp::Signal< DataType >::connect | ( | Base_Slot< DataType > * | slot | ) |

Connect a slot to the signal.

Definition at line 431 of file signals_slots.h.

References itpp::Base_Slot< DataType >::_connect(), connected_slots, itpp::Base_Slot< DataType >::name, and name.

## disconnect()

template<class DataType>

void itpp::Signal< DataType >::disconnect | ( | Base_Slot< DataType > * | slot = NULL | ) |

Disconnect the slot from the signal.

Definition at line 454 of file signals_slots.h.

References connected_slots.

## operator()()

template<class DataType>

Base_Event * itpp::Signal< DataType >::operator() | ( | DataType | signal,
|  | const Ttype | delta_time = 0 )

Issue a signal.

Definition at line 470 of file signals_slots.h.

References itpp::Event_Queue::add(), cancel(), name, operator()(), and trigger().

Referenced by operator()().

## cancel()

template<class DataType>

void itpp::Signal< DataType >::cancel | ( |  | ) |

cancel signal

Definition at line 495 of file signals_slots.h.

Referenced by operator()().

## set_name()

template<class DataType>

void itpp::Signal< DataType >::set_name | ( | const std::string & | signal_name | ) |

set name of signal

Definition at line 419 of file signals_slots.h.

References name.

Referenced by Signal().

## set_debug()

template<class DataType>

void itpp::Signal< DataType >::set_debug | ( | const bool | enable_debug = true | ) |

Set debug mode. If true all signals are printed to stdout.

Definition at line 425 of file signals_slots.h.

Referenced by Signal().

## trigger()

template<class DataType>

void itpp::Signal< DataType >::trigger | ( | DataType | u | ) |

ADD DOCUMENTATION HERE.

Definition at line 506 of file signals_slots.h.

References connected_slots, name, and itpp::Event_Queue::now().

Referenced by operator()().

## _disconnect()

template<class DataType>

void itpp::Signal< DataType >::_disconnect | ( | Base_Slot< DataType > * | slot | ) |

protected

ADD DOCUMENTATION HERE.

Definition at line 523 of file signals_slots.h.

References connected_slots.

## Friends And Related Symbol Documentation

## Base_Slot< DataType >

template<class DataType>

friend class Base_Slot< DataType >

friend

Definition at line 611 of file signals_slots.h.

## Member Data Documentation

## connected_slots

template<class DataType>

std::list<Base_Slot<DataType>*, std::allocator<Base_Slot<DataType>* > > itpp::Signal< DataType >::connected_slots

protected

ADD DOCUMENTATION HERE.

Definition at line 167 of file signals_slots.h.

Referenced by _disconnect(), connect(), disconnect(), trigger(), and ~Signal().

## name

template<class DataType>

std::string itpp::Signal< DataType >::name

protected

ADD DOCUMENTATION HERE.

Definition at line 169 of file signals_slots.h.

Referenced by connect(), operator()(), set_name(), and trigger().

The documentation for this class was generated from the following file:

- itpp/protocol/signals_slots.h

Generated on for IT++ by Doxygen 1.15.0