IT++ Logo
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
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_Eventoperator() (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;
}
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
}
General array class.
Definition array.h:105
static void start()
Start executing events.
Definition events.cpp:67
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 SignalDataType >",
const bool  single_shot = false,
const bool  enable_debug = false 
)

Default constructor.

Definition at line 392 of file signals_slots.h.

◆ ~Signal()

template<class DataType >
itpp::Signal< DataType >::~Signal ( )

Destructor.

Definition at line 402 of file signals_slots.h.

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.

Referenced by itpp::TTimer< THandler >::TTimer().

◆ 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.

◆ 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(), and itpp::Array< T >::operator()().

◆ cancel()

template<class DataType >
void itpp::Signal< DataType >::cancel ( )

◆ 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.

Referenced by itpp::TCP_Server_Application::TCP_Server_Application().

◆ 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 itpp::TCP_Server_Application::TCP_Server_Application(), and itpp::TTimer< THandler >::TTimer().

◆ trigger()

template<class DataType >
void itpp::Signal< DataType >::trigger ( DataType  u)

ADD DOCUMENTATION HERE.

Definition at line 506 of file signals_slots.h.

References itpp::Event_Queue::now().

◆ _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.

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.

◆ name

template<class DataType >
std::string itpp::Signal< DataType >::name
protected

ADD DOCUMENTATION HERE.

Definition at line 169 of file signals_slots.h.


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

Generated on Mon Jun 10 2024 11:49:40 for IT++ by Doxygen 1.9.8