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.12 by pcg, Tue Dec 4 15:01:12 2007 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: callback.pl is part of the GVPE
3// THIS IS A GENERATED FILE: distribution.
4
5/* 1/*
6 callback.h -- C++ callback mechanism 2 * callback.h -- C++ callback mechanism
7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com> 3 * Copyright (C) 2003-2018 Marc Lehmann <pcg@goof.com>
8 4 *
9 This file is part of GVPE. 5 * This file is part of GVPE.
10 6 *
11 GVPE 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 gvpe; if not, write to the Free Software 18 * with this program; if not, see <http://www.gnu.org/licenses/>.
23 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 CALLBACK_H__ 32#ifndef CALLBACK_H__
27#define CALLBACK_H__ 33#define CALLBACK_H__
28 34
29#define CALLBACK_H_VERSION 3 35#define CALLBACK_H_VERSION 4
30 36
31template<typename signature> 37template<typename signature>
32struct callback; 38struct callback;
33 39
34#define callback_set(callback,obj,klass,method) callback.set<klass, &klass::method> (obj) 40template<class R, class ...Args>
41struct callback<R (Args...)>
42{
43 typedef R (*ptr_type)(void *self, Args...);
35 44
36template<class R> 45 template<class K, R (K::*method)(Args...)>
37struct callback<R ()> 46 void set (K *object)
38{ 47 {
39 typedef R (*ptr_type)(void *self); 48 self = object;
49 func = thunk<K, method>;
50 }
51
52 R call (Args... args) const
53 {
54 return func (self, args...);
55 }
56
57 R operator ()(Args... args) const
58 {
59 return call (args...);
60 }
40 61
41private: 62private:
42 63
43 void *self; 64 void *self;
44 ptr_type func; 65 ptr_type func;
45 66
46protected:
47
48 template<typename method>
49 struct thunktype;
50
51 template<class klass>
52 struct thunktype<R (klass::*)>
53 {
54 typedef klass K;
55 };
56
57 template<class klass, R (klass::*method)()> 67 template<class klass, R (klass::*method)(Args...)>
58 static R thunk (void *self) 68 static R thunk (void *self, Args... args)
59 { 69 {
60 klass *obj = static_cast<klass *>(self); 70 klass *obj = static_cast<klass *>(self);
61 return (obj->*method) (); 71 return (obj->*method) (args...);
62 }
63
64public:
65 template<class K, R (K::*method)()>
66 void set (K *object)
67 {
68 self = object;
69 func = thunk<K, method>;
70 }
71
72 R call () const
73 {
74 return func (self);
75 }
76
77 R operator ()() const
78 {
79 return call ();
80 } 72 }
81}; 73};
82 74
83template<class R, class A1>
84struct callback<R (A1)>
85{
86 typedef R (*ptr_type)(void *self, A1);
87
88private:
89
90 void *self;
91 ptr_type func;
92
93protected:
94
95 template<typename method>
96 struct thunktype;
97
98 template<class klass>
99 struct thunktype<R (klass::*)>
100 {
101 typedef klass K;
102 };
103
104 template<class klass, R (klass::*method)(A1)>
105 static R thunk (void *self, A1 a1)
106 {
107 klass *obj = static_cast<klass *>(self);
108 return (obj->*method) (a1);
109 }
110
111public:
112 template<class K, R (K::*method)(A1)>
113 void set (K *object)
114 {
115 self = object;
116 func = thunk<K, method>;
117 }
118
119 R call (A1 a1) const
120 {
121 return func (self, a1);
122 }
123
124 R operator ()(A1 a1) const
125 {
126 return call (a1);
127 }
128};
129
130template<class R, class A1, class A2>
131struct callback<R (A1, A2)>
132{
133 typedef R (*ptr_type)(void *self, A1, A2);
134
135private:
136
137 void *self;
138 ptr_type func;
139
140protected:
141
142 template<typename method>
143 struct thunktype;
144
145 template<class klass>
146 struct thunktype<R (klass::*)>
147 {
148 typedef klass K;
149 };
150
151 template<class klass, R (klass::*method)(A1, A2)>
152 static R thunk (void *self, A1 a1, A2 a2)
153 {
154 klass *obj = static_cast<klass *>(self);
155 return (obj->*method) (a1, a2);
156 }
157
158public:
159 template<class K, R (K::*method)(A1, A2)>
160 void set (K *object)
161 {
162 self = object;
163 func = thunk<K, method>;
164 }
165
166 R call (A1 a1, A2 a2) const
167 {
168 return func (self, a1, a2);
169 }
170
171 R operator ()(A1 a1, A2 a2) const
172 {
173 return call (a1, a2);
174 }
175};
176
177template<class R, class A1, class A2, class A3>
178struct callback<R (A1, A2, A3)>
179{
180 typedef R (*ptr_type)(void *self, A1, A2, A3);
181
182private:
183
184 void *self;
185 ptr_type func;
186
187protected:
188
189 template<typename method>
190 struct thunktype;
191
192 template<class klass>
193 struct thunktype<R (klass::*)>
194 {
195 typedef klass K;
196 };
197
198 template<class klass, R (klass::*method)(A1, A2, A3)>
199 static R thunk (void *self, A1 a1, A2 a2, A3 a3)
200 {
201 klass *obj = static_cast<klass *>(self);
202 return (obj->*method) (a1, a2, a3);
203 }
204
205public:
206 template<class K, R (K::*method)(A1, A2, A3)>
207 void set (K *object)
208 {
209 self = object;
210 func = thunk<K, method>;
211 }
212
213 R call (A1 a1, A2 a2, A3 a3) const
214 {
215 return func (self, a1, a2, a3);
216 }
217
218 R operator ()(A1 a1, A2 a2, A3 a3) const
219 {
220 return call (a1, a2, a3);
221 }
222};
223
224template<class R, class A1, class A2, class A3, class A4>
225struct callback<R (A1, A2, A3, A4)>
226{
227 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
228
229private:
230
231 void *self;
232 ptr_type func;
233
234protected:
235
236 template<typename method>
237 struct thunktype;
238
239 template<class klass>
240 struct thunktype<R (klass::*)>
241 {
242 typedef klass K;
243 };
244
245 template<class klass, R (klass::*method)(A1, A2, A3, A4)>
246 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4)
247 {
248 klass *obj = static_cast<klass *>(self);
249 return (obj->*method) (a1, a2, a3, a4);
250 }
251
252public:
253 template<class K, R (K::*method)(A1, A2, A3, A4)>
254 void set (K *object)
255 {
256 self = object;
257 func = thunk<K, method>;
258 }
259
260 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
261 {
262 return func (self, a1, a2, a3, a4);
263 }
264
265 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
266 {
267 return call (a1, a2, a3, a4);
268 }
269};
270
271template<class R, class A1, class A2, class A3, class A4, class A5>
272struct callback<R (A1, A2, A3, A4, A5)>
273{
274 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
275
276private:
277
278 void *self;
279 ptr_type func;
280
281protected:
282
283 template<typename method>
284 struct thunktype;
285
286 template<class klass>
287 struct thunktype<R (klass::*)>
288 {
289 typedef klass K;
290 };
291
292 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5)>
293 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
294 {
295 klass *obj = static_cast<klass *>(self);
296 return (obj->*method) (a1, a2, a3, a4, a5);
297 }
298
299public:
300 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
301 void set (K *object)
302 {
303 self = object;
304 func = thunk<K, method>;
305 }
306
307 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
308 {
309 return func (self, a1, a2, a3, a4, a5);
310 }
311
312 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
313 {
314 return call (a1, a2, a3, a4, a5);
315 }
316};
317
318template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
319struct callback<R (A1, A2, A3, A4, A5, A6)>
320{
321 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
322
323private:
324
325 void *self;
326 ptr_type func;
327
328protected:
329
330 template<typename method>
331 struct thunktype;
332
333 template<class klass>
334 struct thunktype<R (klass::*)>
335 {
336 typedef klass K;
337 };
338
339 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6)>
340 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
341 {
342 klass *obj = static_cast<klass *>(self);
343 return (obj->*method) (a1, a2, a3, a4, a5, a6);
344 }
345
346public:
347 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
348 void set (K *object)
349 {
350 self = object;
351 func = thunk<K, method>;
352 }
353
354 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
355 {
356 return func (self, a1, a2, a3, a4, a5, a6);
357 }
358
359 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
360 {
361 return call (a1, a2, a3, a4, a5, a6);
362 }
363};
364
365template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
366struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
367{
368 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
369
370private:
371
372 void *self;
373 ptr_type func;
374
375protected:
376
377 template<typename method>
378 struct thunktype;
379
380 template<class klass>
381 struct thunktype<R (klass::*)>
382 {
383 typedef klass K;
384 };
385
386 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7)>
387 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
388 {
389 klass *obj = static_cast<klass *>(self);
390 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7);
391 }
392
393public:
394 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
395 void set (K *object)
396 {
397 self = object;
398 func = thunk<K, method>;
399 }
400
401 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
402 {
403 return func (self, a1, a2, a3, a4, a5, a6, a7);
404 }
405
406 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
407 {
408 return call (a1, a2, a3, a4, a5, a6, a7);
409 }
410};
411
412template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
413struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
414{
415 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
416
417private:
418
419 void *self;
420 ptr_type func;
421
422protected:
423
424 template<typename method>
425 struct thunktype;
426
427 template<class klass>
428 struct thunktype<R (klass::*)>
429 {
430 typedef klass K;
431 };
432
433 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
434 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
435 {
436 klass *obj = static_cast<klass *>(self);
437 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8);
438 }
439
440public:
441 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
442 void set (K *object)
443 {
444 self = object;
445 func = thunk<K, method>;
446 }
447
448 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
449 {
450 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
451 }
452
453 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
454 {
455 return call (a1, a2, a3, a4, a5, a6, a7, a8);
456 }
457};
458
459template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
460struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
461{
462 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
463
464private:
465
466 void *self;
467 ptr_type func;
468
469protected:
470
471 template<typename method>
472 struct thunktype;
473
474 template<class klass>
475 struct thunktype<R (klass::*)>
476 {
477 typedef klass K;
478 };
479
480 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
481 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
482 {
483 klass *obj = static_cast<klass *>(self);
484 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
485 }
486
487public:
488 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
489 void set (K *object)
490 {
491 self = object;
492 func = thunk<K, method>;
493 }
494
495 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
496 {
497 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
498 }
499
500 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
501 {
502 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
503 }
504};
505
506template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
507struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
508{
509 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
510
511private:
512
513 void *self;
514 ptr_type func;
515
516protected:
517
518 template<typename method>
519 struct thunktype;
520
521 template<class klass>
522 struct thunktype<R (klass::*)>
523 {
524 typedef klass K;
525 };
526
527 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
528 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
529 {
530 klass *obj = static_cast<klass *>(self);
531 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
532 }
533
534public:
535 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
536 void set (K *object)
537 {
538 self = object;
539 func = thunk<K, method>;
540 }
541
542 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
543 {
544 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
545 }
546
547 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
548 {
549 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
550 }
551};
552
553
554#endif 75#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines