Itasca C++ Interface
Loading...
Searching...
No Matches
callback.h
1#pragma once
2
3// Note - VS2010 does not support variadic templates :(
4// MOO NOTE: Do not use these in new codes, between lambdas and std::function
5// it really doesn't make sense. Remove in old code when you are messing around
6// with it anyway.
7
8template <class R>
9class Callback0 {
10public:
11 virtual ~Callback0() {}
12 virtual R execute()=0;
13};
14
15template <class R,class Arg1>
16class Callback1 {
17public:
18 virtual ~Callback1() {}
19 virtual R execute(Arg1 a)=0;
20};
21
22template <class R,class Arg1,class Arg2>
23class Callback2 {
24public:
25 virtual ~Callback2() {}
26 virtual R execute(Arg1 a,Arg2 b)=0;
27};
28
29template <class R,class Arg1,class Arg2,class Arg3>
30class Callback3 {
31public:
32 virtual ~Callback3() {}
33 virtual R execute(Arg1 a,Arg2 b,Arg3 c)=0;
34};
35
36template <class R,class Arg1,class Arg2,class Arg3,class Arg4>
37class Callback4 {
38public:
39 virtual ~Callback4() {}
40 virtual R execute(Arg1 a,Arg2 b,Arg3 c,Arg4 d)=0;
41};
42
43template <class R>
44class Callback0Static : public Callback0<R> {
45public:
46 typedef R (*type)();
47 Callback0Static(type t) : t_(t) { }
48 virtual R execute() { return t_(); }
49private:
50 type t_;
51};
52
53template <class R,class Arg1>
54class Callback1Static : public Callback1<R,Arg1> {
55public:
56 typedef R (*type)(Arg1 a);
57 Callback1Static(type t) : t_(t) { }
58 virtual R execute(Arg1 a) { return t_(a); }
59private:
60 type t_;
61};
62
63template <class R,class Arg1,class Arg2>
64class Callback2Static : public Callback2<R,Arg1,Arg2> {
65public:
66 typedef R (*type)(Arg1 a,Arg2 b);
67 Callback2Static(type t) : t_(t) { }
68 virtual R execute(Arg1 a,Arg2 b) { return t_(a,b); }
69private:
70 type t_;
71};
72
73template <class R,class Arg1,class Arg2,class Arg3>
74class Callback3Static : public Callback3<R,Arg1,Arg2,Arg3> {
75public:
76 typedef R (*type)(Arg1 a,Arg2 b,Arg3 c);
77 Callback3Static(type t) : t_(t) { }
78 virtual R execute(Arg1 a,Arg2 b,Arg3 c) { return t_(a,b,c); }
79private:
80 type t_;
81};
82
83template <class R,class Arg1,class Arg2,class Arg3,class Arg4>
84class Callback4Static : public Callback4<R,Arg1,Arg2,Arg3,Arg4> {
85public:
86 typedef R (*type)(Arg1 a,Arg2 b,Arg3 c,Arg4 d);
87 Callback4Static(type t) : t_(t) { }
88 R execute(Arg1 a,Arg2 b,Arg3 c,Arg4 d) override { return t_(a,b,c,d); }
89private:
90 type t_;
91};
92
93template <class R,class S,R (S::*MFP)()>
94class Callback0Method : public Callback0<R> {
95public:
96 Callback0Method(S *s) : s_(s) { }
97 virtual R execute() { return (s_->*MFP)(); }
98private:
99 S *s_;
100};
101
102template <class R,class Arg1,class S,R (S::*MFP)(Arg1)>
103class Callback1Method : public Callback1<R,Arg1> {
104public:
105 Callback1Method(S *s) : s_(s) { }
106 virtual R execute(Arg1 a) { return (s_->*MFP)(a); }
107private:
108 S *s_;
109};
110
111template <class R,class Arg1,class Arg2,class S,R (S::*MFP)(Arg1,Arg2)>
112class Callback2Method : public Callback2<R,Arg1,Arg2> {
113public:
114 Callback2Method(S *s) : s_(s) { }
115 virtual R execute(Arg1 a,Arg2 b) { return (s_->*MFP)(a,b); }
116private:
117 S *s_;
118};
119
120template <class R,class Arg1,class Arg2,class Arg3,class S,R (S::*MFP)(Arg1,Arg2,Arg3)>
121class Callback3Method : public Callback3<R,Arg1,Arg2,Arg3> {
122public:
123 Callback3Method(S *s) : s_(s) { }
124 R execute(Arg1 a,Arg2 b,Arg3 c) override { return (s_->*MFP)(a,b,c); }
125private:
126 S *s_;
127};
128
129template <class R,class Arg1,class Arg2,class Arg3,class Arg4,class S,R (S::*MFP)(Arg1,Arg2,Arg3,Arg4)>
130class Callback4Method : public Callback4<R,Arg1,Arg2,Arg3,Arg4> {
131public:
132 Callback4Method(S *s) : s_(s) { }
133 R execute(Arg1 a,Arg2 b,Arg3 c,Arg4 d) override { return (s_->*MFP)(a,b,c,d); }
134private:
135 S *s_;
136};
137
138// EoF
Definition callback.h:9
Definition callback.h:94
Definition callback.h:44
Definition callback.h:16
Definition callback.h:103
Definition callback.h:54
Definition callback.h:23
Definition callback.h:112
Definition callback.h:64
Definition callback.h:30
Definition callback.h:121
Definition callback.h:74
Definition callback.h:37
Definition callback.h:130
Definition callback.h:84