signals 2.0
This commit is contained in:
1 parent
b849d8c7ce
commit
ef1b465179
33 files changed
+537
No files matched your search
@@ -0,0 +1,71 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
#include "slot.h"
|
||||
#include "signal0.h"
|
||||
|
||||
class ParentFoo
|
||||
{
|
||||
public:
|
||||
virtual bool Bar()
|
||||
{
|
||||
printf("ParentFoo::Bar!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual ~ParentFoo()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
class Foo: public ParentFoo
|
||||
{
|
||||
public:
|
||||
bool Bar()
|
||||
{
|
||||
printf("Foo::Bar!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual ~Foo()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
Foo f;
|
||||
|
||||
bool somefunc()
|
||||
{
|
||||
printf("some func\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T_class, typename T_method>
|
||||
slot0_method<T_class,T_method>* make_slot(T_class* c, T_method m)
|
||||
{
|
||||
return new slot0_method<T_class,T_method>(c,m);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
slot0* s = make_slot(&f,&Foo::Bar);
|
||||
slot0* t = make_slot(&f,&ParentFoo::Bar);
|
||||
|
||||
slot0_function<bool> x( somefunc );
|
||||
slot0* u = &x;
|
||||
|
||||
if ( *s == *t )
|
||||
(*s)();
|
||||
|
||||
(*u)();
|
||||
|
||||
signal0 sig;
|
||||
sig.connect(&f,&Foo::Bar);
|
||||
sig();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user