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.1 by pcg, Wed Apr 2 03:06:22 2003 UTC vs.
Revision 1.13 by pcg, Tue Dec 4 17:17:19 2007 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
1/* 5/*
2 callback.h -- C++ callback mechanism 6 callback.h -- C++ callback mechanism
7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
3 8
9 This file is part of GVPE.
10
4 This program is free software; you can redistribute it and/or modify 11 GVPE is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or 13 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version. 14 (at your option) any later version.
8 15
9 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 19 GNU General Public License for more details.
13 20
14 You should have received a copy of the GNU General Public License 21 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 22 along with gvpe; if not, write to the Free Software
16 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/ 24*/
18 25
19#ifndef VPE_CALLBACK_H__ 26#ifndef CALLBACK_H__
20#define VPE_CALLBACK_H__ 27#define CALLBACK_H__
21 28
29#define CALLBACK_H_VERSION 3
30
31template<typename signature>
32struct callback;
33
34template<class R>
35struct callback<R ()>
36{
37 typedef R (*ptr_type)(void *self);
38
39private:
40
41 void *self;
42 ptr_type func;
43
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)()>
56 static R thunk (void *self)
57 {
58 klass *obj = static_cast<klass *>(self);
59 return (obj->*method) ();
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 }
79};
80
22template<class R, class A> 81template<class R, class A1>
23class callback { 82struct callback<R (A1)>
24 struct object { }; 83{
84 typedef R (*ptr_type)(void *self, A1);
25 85
26 void *obj; 86private:
27 R (object::*meth)(A arg);
28 87
29 // a proxy is a kind of recipe on how to call a specific class method 88 void *self;
30 struct proxy_base { 89 ptr_type func;
31 virtual R call (void *obj, R (object::*meth)(A), A arg) = 0; 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);
32 }; 107 }
33 template<class O1, class O2> 108
34 struct proxy : proxy_base { 109public:
35 virtual R call (void *obj, R (object::*meth)(A), A arg) 110 template<class K, R (K::*method)(A1)>
36 { 111 void set (K *object)
37 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A)>(meth))) 112 {
38 (arg); 113 self = object;
39 } 114 func = thunk<K, method>;
40 }; 115 }
41 116
42 proxy_base *prxy;
43
44public:
45 template<class O1, class O2>
46 callback (O1 *object, R (O2::*method)(A))
47 {
48 static proxy<O1,O2> p;
49 obj = reinterpret_cast<void *>(object);
50 meth = reinterpret_cast<R (object::*)(A)>(method);
51 prxy = &p;
52 }
53
54 R call(A arg) const 117 R call (A1 a1) const
55 { 118 {
56 return prxy->call (obj, meth, arg); 119 return func (self, a1);
57 } 120 }
58 121
59 R operator ()(A arg) const 122 R operator ()(A1 a1) const
60 { 123 {
61 return call (arg); 124 return call (a1);
62 } 125 }
63}; 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
64 551
65#endif 552#endif
66

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines