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/signaler.h>
class A {
public:
gum::Signaler2<int,char> onF;
'Signaler2' is used.
void f(int i,char ch) {
}
};
@
#define GUM_EMIT2(signal, arg1, arg2)
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 ?
#include <agrum/core/signal/Listener.h>
public:
void whenF(const void *src,int i, char ch) {
std::cout<<"object "<<src<<" run f on "<<i<<" and "<<ch<<std::endl;
}
};
public:
void dummy(void *src,int i,char ch) {
std::cout<<"dummy on "<<i<<" and "<<ch<<std::endl;
}
};
Every class who would catch signal from signaler should derive from Listener.
Now we have to connect
int main(void) {
A a;
B b1;
B b2;
a.f(3,'a');
{
C c;
a.f(4,'x');
}
a.f(5,'y');
}
#define GUM_CONNECT(sender, signal, receiver, target)