# dlangui.core.signals

DLANGUI library.
This module contains definition of signals / listeners.
Similar to std.signals.
Unlike std.signals, supports any types of delegates, and as well interfaces with single method.
Unlike std.signals, can support return types for slots.
Caution:
unlike std.signals, does not disconnect signal from slots belonging to destroyed objects.
Listener here stand for holder of single delegate (slot). Signal is the same but supports multiple slots.
Can be declared either using list of result value and argument types, or by interface name with single method.
Synopsis:

    import dlangui.core.signals;

    interface SomeInterface {
        bool someMethod(string s, int n);
    }
    class Foo : SomeInterface {
    	override bool someMethod(string s, int n) {
    		writeln("someMethod called ", s, ", ", n);
    		return n > 10; // can return value
    	}
    }

    // Listener! can hold arbitrary number of connected slots

    // declare using list of return value and parameter types
    Listener!(bool, string, n) signal1;

    Foo f = new Foo();
    // when signal is defined as type list, you can use delegate
    signal1 = bool delegate(string s, int n) { writeln("inside delegate - ", s, n); return false; }
    // or method reference
    signal1 = &f.someMethod;

    // declare using interface with single method
    Listener!SomeInterface signal2;
    // you still can use any delegate
    signal2 = bool delegate(string s, int n) { writeln("inside delegate - ", s, n); return false; }
    // but for class method which overrides interface method, you can use simple syntax
    signal2 = f; // it will automatically take &f.someMethod

    // call listener(s) either by opcall or explicit emit
    signal1("text", 1);
    signal1.emit("text", 2);
    signal2.emit("text", 3);

    // check if any slit is connected
    if (signal1.assigned)
    	writeln("has listeners");

    // Signal! can hold arbitrary number of connected slots

    // declare using list of return value and parameter types
    Signal!(bool, string, n) signal3;

    // add listeners via connect call
    signal3.connect(bool delegate(string, int) { return false; });
    // or via ~= operator
    signal3 ~= bool delegate(string, int) { return false; };

    // declare using interface with single method
    Signal!SomeInterface signal4;

    // you can connect several slots to signal
    signal4 ~= f;
    signal4 ~= bool delegate(string, int) { return true; }

    // calling of listeners of Signal! is similar to Listener!
    // using opCall
    bool res = signal4("blah", 5);
    // call listeners using emit
    bool res = signal4.emit("blah", 5);

    // you can disconnect individual slots
    // using disconnect()
    signal4.disconnect(f);
    // or -= operator
    signal4 -= f;

License:
Boost License 1.0
Authors:
Vadim Lopatin, coolreader.org@gmail.com

struct Listener(T1) if (is(T1 == interface) && __traits(allMembers, T1).length == 1);
  Single listener; parameter is interface with single method
  bool assigned();
    returns true if listener is assigned
  void opAssign(slot_t listenerDelegate);
    assign delegate
  void opAssign(T1 listenerObject);
    assign object implementing interface
struct Listener(RETURN_T, T1...);
  Single listener; implicitly specified return and parameter types
  bool assigned();
    returns true if listener is assigned
struct Signal(T1) if (is(T1 == interface) && __traits(allMembers, T1).length == 1);
  Multiple listeners; implicitly specified return and parameter types
  bool assigned();
    returns true if listener is assigned
  void opAssign(slot_t listener);
    replace all previously assigned listeners with new one (if null passed, remove all listeners)
  void opAssign(T1 listener);
    replace all previously assigned listeners with new one (if null passed, remove all listeners)
  return_t opCall(params_t params);
    call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero
  return_t emit(params_t params);
    call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero
  void connect(slot_t listener);
    add listener
  void disconnect(slot_t listener);
    remove listener
  void connect(T1 listener);
    add listener - as interface member
  void disconnect(T1 listener);
    add listener - as interface member
struct Signal(RETURN_T, T1...);
  Multiple listeners; implicitly specified return and parameter types
  bool assigned();
    returns true if listener is assigned
  void opAssign(slot_t listener);
    replace all previously assigned listeners with new one (if null passed, remove all listeners)
  RETURN_T opCall(T1 params);
    call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero
  RETURN_T emit(T1 params);
    call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero
  void connect(slot_t listener);
    add listener
  void disconnect(slot_t listener);
    remove listener

Page generated by Ddoc. Vadim Lopatin, 2014