tango.core.Signal

The signal module provides a basic implementation of the listener pattern using the "Signals and Slots" model from Qt.

License:

BSD style: see license.txt

Author:

Sean Kelly
struct Signal(Args...)
A signal is an event which contains a collection of listeners (called slots). When a signal is called, that call will be propagated to each attached slot in a synchronous manner. It is legal for a slot to call a signal's attach and detach methods when it is signaled. When this occurs, attach events will be queued and processed after the signal has propagated to all slots, but detach events are processed immediately. This ensures that it is safe for slots to be deleted at any time, even within a slot routine.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Button
{
    Signal!(Button) press;
}

void wasPressed( Button b )
{
    printf( "Button was pressed.\n" );
}

Button b = new Button;

b.press.attach( &wasPressed );
b.press( b );

Please note that this implementation does not use weak pointers to store references to slots. This design was chosen because weak pointers are inherently unsafe when combined with non-deterministic destruction, with many of the same limitations as destructors in the same situation. It is still possible to obtain weak-pointer behavior, but this must be done through a proxy object instead.
alias void delegate(Args) SlotDg
alias void function(Args) SlotFn
alias opCall call
Alias to simplify chained calling.
void opCall(Args args)
The signal procedure. When called, each of the attached slots will be called synchronously.

Parameters:

argsThe signal arguments.
void attach(SlotDg dg)
Attaches a delegate to this signal. A delegate may be either attached or detached, so successive calls to attach for the same delegate will have no effect.

Parameters:

dgThe delegate to attach.
void attach(SlotFn fn)
Attaches a function to this signal. A function may be either attached or detached, so successive calls to attach for the same function will have no effect.

Parameters:

fnThe function to attach.
void detach(SlotDg dg)
Detaches a delegate from this signal.

Parameters:

dgThe delegate to detach.
void detach(SlotFn fn)
Detaches a function from this signal.

Parameters:

fnThe function to detach.