IT++ Logo

itpp::Signal< DataType > Class Template Reference
[Protocols Module]

#include <itpp/protocol/signals_slots.h>

List of all members.


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
    }

Definition at line 113 of file 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 >

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

Generated on Sat Apr 19 10:59:26 2008 for IT++ by Doxygen 1.5.5