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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines