17 virtual ~GCaller() =
default;
18 virtual void operator()(GEvent&) = 0;
20 GCaller(GCaller
const&) =
delete;
21 GCaller(GObject
const&&) =
delete;
22 GCaller& operator=(GCaller
const&) =
delete;
23 GCaller& operator=(GCaller
const&&) =
delete;
29 class GCallerF0 :
public GCaller {
31 GCallerF0(GFunction
const& fun) : fun_(fun) {}
32 void operator()(GEvent&)
override {fun_();}
36 class GCallerF1 :
public GCaller {
38 GCallerF1(GEventFunction
const& fun) : fun_(fun) {}
39 void operator()(GEvent& e)
override {fun_(e);}
44 class GCallerM0 :
public GCaller {
46 GCallerM0(T* obj,
void (T::*fun)()) : obj_(obj), fun_(fun) {}
47 void operator()(GEvent&)
override {(obj_->*fun_)();}
53 class GCallerM1 :
public GCaller {
55 GCallerM1(T* obj,
void (T::*fun)(GEvent&)) : obj_(obj), fun_(fun) {}
56 void operator()(GEvent& e)
override {(obj_->*fun_)(e);}
58 void (T::*fun_)(GEvent&);
62 template <
class T,
class E>
63 class GCallerM2 :
public GCaller {
65 GCallerM2(T* obj,
void (T::*fun)(E&)) : obj_(obj), fun_(fun) {}
66 void operator()(GEvent& e)
override {
67 if (
auto* ee = dynamic_cast<E*>(&e)) (obj_->*fun_)(*ee);
68 else gerror(
"GCaller",
"Invalid event type");
75 inline GCaller& Call(GFunction
const& fun) {
76 return *
new GCallerF0(fun);
79 inline GCaller& Call(GEventFunction
const& fun) {
80 return *
new GCallerF1(fun);
84 inline GCaller& Call(T* obj,
void (T::*fun)()) {
85 return *
new GCallerM0<T>(obj, fun);
89 inline GCaller& Call(T* obj,
void (T::*fun)(GEvent& e)) {
90 return *
new GCallerM1<T>(obj, fun);
93 template <
class T,
class E>
94 inline GCaller& Call(T* obj,
void (T::*fun)(E& e)) {
95 return *
new GCallerM2<T,E>(obj, fun);
100 class GCallerThread :
public GCaller {
105 class GCallerThreadF0 :
public GCallerThread {
107 GCallerThreadF0(GFunction
const& fun) : fun_(fun) {}
108 void operator()(GEvent&)
override {fun_();}
113 class GCallerThreadM0 :
public GCallerThread {
115 GCallerThreadM0(T* obj,
void (T::*fun)()) : obj_(obj), fun_(fun) {}
116 void operator()(GEvent&)
override {(obj_->*fun_)();}
134 inline GCallerThread& CallThread(GFunction
const& fun) {
135 return *
new GCallerThreadF0(fun);
139 inline GCallerThread& CallThread(T* obj,
void (T::*fun)()) {
140 return *
new GCallerThreadM0<T>(obj, fun);
147 inline GCallerThread& CallWait(GTime ms_delay) {
148 return *
new GCallerThreadF0([ms_delay]{gsleep(ms_delay);});