aGrUM  0.13.2
How to use signaler/listener in aGrUM ?

aGrUM has its own implementation of signalers/listeners.

Let's say that class A has a method f(int i,char ch) and would like to give to everyone the right to know whenever f() is run.

#include <agrum/core/signal/signaler2.h> // Note the '2' because the signal we
will send 2 args (i and ch)
class A {
gum::signaler2<int,char> onF; // Note that onF is public !
void f(int i,char ch) {
//do something
GUM_EMIT2(onF,i,ch); // a signal (with 2 args i and ch) is emitted via onF.

Note that for class A, adding signaler is very light : a new public attribute and a GUM_EMITx when needed (where x is the number of args).

Now, how to listen to such a signal ?

class B : gum::listener {
void whenF(const void *src,int i, char ch) {std::cout<<"object "<<src<<"run f
"<<i<<" and "<<ch<<std::endl;}
A a;
B b1;
B b2;
GUM_CONNECT( a,onF,b1,B::whenF );
GUM_CONNECT( a,onF,b2,B::whenF );
// b1.whenF and b2.whenF has been executed.
class C : gum::listener {
void dummy(void *src,int i,char ch) {};
C c;
GUM_CONNECT( a,onF,c,C::dummy );
//c.dummy(), b1.whenF and b2.whenF has been executed.
} // c is destroyed...
//b1.whenF and b2.whenF has been executed.