ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.h
(Generate patch)

Comparing gvpe/src/callback.h (file contents):
Revision 1.2 by pcg, Wed Apr 2 05:14:59 2003 UTC vs.
Revision 1.16 by root, Sun Nov 18 00:02:56 2018 UTC

1// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it
2// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it
3// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it
4// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it
5// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it
6// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it
7
8/* 1/*
9 callback.h -- C++ callback mechanism 2 * callback.h -- C++ callback mechanism
10 3 * Copyright (C) 2003-2018 Marc Lehmann <pcg@goof.com>
4 *
5 * This file is part of GVPE.
6 *
11 This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify it
12 it under the terms of the GNU General Public License as published by 8 * under the terms of the GNU General Public License as published by the
13 the Free Software Foundation; either version 2 of the License, or 9 * Free Software Foundation; either version 3 of the License, or (at your
14 (at your option) any later version. 10 * option) any later version.
15 11 *
16 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful, but
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 GNU General Public License for more details. 15 * Public License for more details.
20 16 *
21 You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License along
22 along with this program; if not, write to the Free Software 18 * with this program; if not, see <http://www.gnu.org/licenses/>.
23 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 *
20 * Additional permission under GNU GPL version 3 section 7
21 *
22 * If you modify this Program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a modified
24 * version of that library), containing parts covered by the terms of the
25 * OpenSSL or SSLeay licenses, the licensors of this Program grant you
26 * additional permission to convey the resulting work. Corresponding
27 * Source for a non-source form of such a combination shall include the
28 * source code for the parts of OpenSSL used as well as that of the
29 * covered work.
24*/ 30*/
25 31
26#ifndef VPE_CALLBACK_H__ 32#ifndef CALLBACK_H__
27#define VPE_CALLBACK_H__ 33#define CALLBACK_H__
28 34
29template<class R> 35#define CALLBACK_H_VERSION 4
30class callback0 {
31 struct object { };
32 36
33 void *obj; 37template<typename signature>
34 R (object::*meth)(); 38struct callback;
35 39
36 /* a proxy is a kind of recipe on how to call a specific class method */
37 struct proxy_base {
38 virtual R call (void *obj, R (object::*meth)()) = 0;
39 };
40 template<class O1, class O2> 40template<class R, class ...Args>
41 struct proxy : proxy_base { 41struct callback<R (Args...)>
42 virtual R call (void *obj, R (object::*meth)()) 42{
43 { 43 typedef R (*ptr_type)(void *self, Args...);
44 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)()>(meth)))
45 ();
46 }
47 };
48 44
49 proxy_base *prxy; 45 template<class K, R (K::*method)(Args...)>
46 void set (K *object)
47 {
48 self = object;
49 func = thunk<K, method>;
50 }
50 51
51public: 52 R call (Args... args) const
52 template<class O1, class O2>
53 callback0 (O1 *object, R (O2::*method)())
54 { 53 {
55 static proxy<O1,O2> p; 54 return func (self, args...);
56 obj = reinterpret_cast<void *>(object);
57 meth = reinterpret_cast<R (object::*)()>(method);
58 prxy = &p;
59 } 55 }
60 56
61 R call() const 57 R operator ()(Args... args) const
62 { 58 {
63 return prxy->call (obj, meth); 59 return call (args...);
64 } 60 }
65 61
66 R operator ()() const 62private:
67 {
68 return call ();
69 }
70};
71 63
72template<class R, class A1> 64 void *self;
73class callback1 { 65 ptr_type func;
74 struct object { };
75 66
76 void *obj; 67 template<class klass, R (klass::*method)(Args...)>
77 R (object::*meth)(A1); 68 static R thunk (void *self, Args... args)
78 69 {
79 /* a proxy is a kind of recipe on how to call a specific class method */ 70 klass *obj = static_cast<klass *>(self);
80 struct proxy_base { 71 return (obj->*method) (args...);
81 virtual R call (void *obj, R (object::*meth)(A1), A1 a1) = 0;
82 }; 72 }
83 template<class O1, class O2>
84 struct proxy : proxy_base {
85 virtual R call (void *obj, R (object::*meth)(A1), A1 a1)
86 {
87 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1)>(meth)))
88 (a1);
89 }
90 };
91
92 proxy_base *prxy;
93
94public:
95 template<class O1, class O2>
96 callback1 (O1 *object, R (O2::*method)(A1))
97 {
98 static proxy<O1,O2> p;
99 obj = reinterpret_cast<void *>(object);
100 meth = reinterpret_cast<R (object::*)(A1)>(method);
101 prxy = &p;
102 }
103
104 R call(A1 a1) const
105 {
106 return prxy->call (obj, meth, a1);
107 }
108
109 R operator ()(A1 a1) const
110 {
111 return call (a1);
112 }
113};
114
115template<class R, class A1, class A2>
116class callback2 {
117 struct object { };
118
119 void *obj;
120 R (object::*meth)(A1, A2);
121
122 /* a proxy is a kind of recipe on how to call a specific class method */
123 struct proxy_base {
124 virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) = 0;
125 };
126 template<class O1, class O2>
127 struct proxy : proxy_base {
128 virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2)
129 {
130 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2)>(meth)))
131 (a1, a2);
132 }
133 };
134
135 proxy_base *prxy;
136
137public:
138 template<class O1, class O2>
139 callback2 (O1 *object, R (O2::*method)(A1, A2))
140 {
141 static proxy<O1,O2> p;
142 obj = reinterpret_cast<void *>(object);
143 meth = reinterpret_cast<R (object::*)(A1, A2)>(method);
144 prxy = &p;
145 }
146
147 R call(A1 a1, A2 a2) const
148 {
149 return prxy->call (obj, meth, a1, a2);
150 }
151
152 R operator ()(A1 a1, A2 a2) const
153 {
154 return call (a1, a2);
155 }
156};
157
158template<class R, class A1, class A2, class A3>
159class callback3 {
160 struct object { };
161
162 void *obj;
163 R (object::*meth)(A1, A2, A3);
164
165 /* a proxy is a kind of recipe on how to call a specific class method */
166 struct proxy_base {
167 virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) = 0;
168 };
169 template<class O1, class O2>
170 struct proxy : proxy_base {
171 virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3)
172 {
173 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3)>(meth)))
174 (a1, a2, a3);
175 }
176 };
177
178 proxy_base *prxy;
179
180public:
181 template<class O1, class O2>
182 callback3 (O1 *object, R (O2::*method)(A1, A2, A3))
183 {
184 static proxy<O1,O2> p;
185 obj = reinterpret_cast<void *>(object);
186 meth = reinterpret_cast<R (object::*)(A1, A2, A3)>(method);
187 prxy = &p;
188 }
189
190 R call(A1 a1, A2 a2, A3 a3) const
191 {
192 return prxy->call (obj, meth, a1, a2, a3);
193 }
194
195 R operator ()(A1 a1, A2 a2, A3 a3) const
196 {
197 return call (a1, a2, a3);
198 }
199};
200
201template<class R, class A1, class A2, class A3, class A4>
202class callback4 {
203 struct object { };
204
205 void *obj;
206 R (object::*meth)(A1, A2, A3, A4);
207
208 /* a proxy is a kind of recipe on how to call a specific class method */
209 struct proxy_base {
210 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) = 0;
211 };
212 template<class O1, class O2>
213 struct proxy : proxy_base {
214 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4)
215 {
216 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4)>(meth)))
217 (a1, a2, a3, a4);
218 }
219 };
220
221 proxy_base *prxy;
222
223public:
224 template<class O1, class O2>
225 callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4))
226 {
227 static proxy<O1,O2> p;
228 obj = reinterpret_cast<void *>(object);
229 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4)>(method);
230 prxy = &p;
231 }
232
233 R call(A1 a1, A2 a2, A3 a3, A4 a4) const
234 {
235 return prxy->call (obj, meth, a1, a2, a3, a4);
236 }
237
238 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
239 {
240 return call (a1, a2, a3, a4);
241 }
242};
243
244template<class R, class A1, class A2, class A3, class A4, class A5>
245class callback5 {
246 struct object { };
247
248 void *obj;
249 R (object::*meth)(A1, A2, A3, A4, A5);
250
251 /* a proxy is a kind of recipe on how to call a specific class method */
252 struct proxy_base {
253 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) = 0;
254 };
255 template<class O1, class O2>
256 struct proxy : proxy_base {
257 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
258 {
259 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5)>(meth)))
260 (a1, a2, a3, a4, a5);
261 }
262 };
263
264 proxy_base *prxy;
265
266public:
267 template<class O1, class O2>
268 callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5))
269 {
270 static proxy<O1,O2> p;
271 obj = reinterpret_cast<void *>(object);
272 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5)>(method);
273 prxy = &p;
274 }
275
276 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
277 {
278 return prxy->call (obj, meth, a1, a2, a3, a4, a5);
279 }
280
281 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
282 {
283 return call (a1, a2, a3, a4, a5);
284 }
285};
286
287template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
288class callback6 {
289 struct object { };
290
291 void *obj;
292 R (object::*meth)(A1, A2, A3, A4, A5, A6);
293
294 /* a proxy is a kind of recipe on how to call a specific class method */
295 struct proxy_base {
296 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) = 0;
297 };
298 template<class O1, class O2>
299 struct proxy : proxy_base {
300 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
301 {
302 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6)>(meth)))
303 (a1, a2, a3, a4, a5, a6);
304 }
305 };
306
307 proxy_base *prxy;
308
309public:
310 template<class O1, class O2>
311 callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6))
312 {
313 static proxy<O1,O2> p;
314 obj = reinterpret_cast<void *>(object);
315 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6)>(method);
316 prxy = &p;
317 }
318
319 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
320 {
321 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6);
322 }
323
324 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
325 {
326 return call (a1, a2, a3, a4, a5, a6);
327 }
328};
329
330template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
331class callback7 {
332 struct object { };
333
334 void *obj;
335 R (object::*meth)(A1, A2, A3, A4, A5, A6, A7);
336
337 /* a proxy is a kind of recipe on how to call a specific class method */
338 struct proxy_base {
339 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) = 0;
340 };
341 template<class O1, class O2>
342 struct proxy : proxy_base {
343 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
344 {
345 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7)>(meth)))
346 (a1, a2, a3, a4, a5, a6, a7);
347 }
348 };
349
350 proxy_base *prxy;
351
352public:
353 template<class O1, class O2>
354 callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7))
355 {
356 static proxy<O1,O2> p;
357 obj = reinterpret_cast<void *>(object);
358 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7)>(method);
359 prxy = &p;
360 }
361
362 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
363 {
364 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7);
365 }
366
367 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
368 {
369 return call (a1, a2, a3, a4, a5, a6, a7);
370 }
371}; 73};
372 74
373#endif 75#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines