ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.h
Revision: 1.11
Committed: Sun Dec 2 00:54:52 2007 UTC (16 years, 5 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.10: +214 -357 lines
Log Message:
update callback.pl to use the same trick as libev uses

File Contents

# User Rev Content
1 pcg 1.7 // 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 pcg 1.2
5 pcg 1.1 /*
6     callback.h -- C++ callback mechanism
7 pcg 1.11 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
8 pcg 1.1
9 pcg 1.5 This file is part of GVPE.
10    
11     GVPE is free software; you can redistribute it and/or modify
12 pcg 1.1 it under the terms of the GNU General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15    
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     GNU General Public License for more details.
20    
21     You should have received a copy of the GNU General Public License
22 pcg 1.5 along with gvpe; if not, write to the Free Software
23 pcg 1.6 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 pcg 1.1 */
25    
26 pcg 1.4 #ifndef CALLBACK_H__
27     #define CALLBACK_H__
28 pcg 1.1
29 pcg 1.11 #define CALLBACK_H_VERSION 3
30 pcg 1.10
31     template<class signature>
32     struct callback_funtype_trait;
33    
34     template<int arity, class signature>
35     struct callback_get_impl;
36    
37 pcg 1.2 template<class R>
38 pcg 1.10 class callback0
39     {
40 pcg 1.11 struct klass; // it is vital that this is never defined
41 pcg 1.2
42 pcg 1.11 typedef R (klass::*ptr_type)();
43 pcg 1.10
44 pcg 1.11 klass *o;
45     R (klass::*m)();
46 pcg 1.2
47     public:
48     template<class O1, class O2>
49 pcg 1.9 explicit callback0 (O1 *object, R (O2::*method)())
50 pcg 1.11 {
51     o = reinterpret_cast<klass *>(object);
52     m = reinterpret_cast<R (klass::*)()>(method);
53     }
54    
55     // this works because a standards-compliant C++ compiler
56     // basically can't help it: it doesn't have the knowledge
57     // required to miscompile (klass is not defined anywhere
58     // and nothing is known about the constructor arguments) :)
59 pcg 1.2 R call() const
60 pcg 1.11 {
61     return (o->*m) ();
62     }
63 pcg 1.2
64     R operator ()() const
65 pcg 1.11 {
66     return call ();
67     }
68 pcg 1.2 };
69    
70 pcg 1.10 template<class R>
71     struct callback_funtype_trait0
72     {
73     static const int arity = 0;
74     typedef R type (void);
75     typedef R result_type;
76    
77     };
78    
79     template<class R>
80     struct callback_funtype_trait<R ()> : callback_funtype_trait0<R>
81     {
82     };
83    
84     template<class signature>
85     struct callback_get_impl<0, signature>
86     {
87     typedef callback_funtype_trait<signature> T;
88     typedef callback0<typename T::result_type> type;
89     };
90    
91 pcg 1.2 template<class R, class A1>
92 pcg 1.10 class callback1
93     {
94 pcg 1.11 struct klass; // it is vital that this is never defined
95 pcg 1.1
96 pcg 1.11 typedef R (klass::*ptr_type)(A1);
97 pcg 1.1
98 pcg 1.11 klass *o;
99     R (klass::*m)(A1);
100 pcg 1.1
101     public:
102     template<class O1, class O2>
103 pcg 1.9 explicit callback1 (O1 *object, R (O2::*method)(A1))
104 pcg 1.11 {
105     o = reinterpret_cast<klass *>(object);
106     m = reinterpret_cast<R (klass::*)(A1)>(method);
107     }
108    
109     // this works because a standards-compliant C++ compiler
110     // basically can't help it: it doesn't have the knowledge
111     // required to miscompile (klass is not defined anywhere
112     // and nothing is known about the constructor arguments) :)
113 pcg 1.2 R call(A1 a1) const
114 pcg 1.11 {
115     return (o->*m) (a1);
116     }
117 pcg 1.1
118 pcg 1.2 R operator ()(A1 a1) const
119 pcg 1.11 {
120     return call (a1);
121     }
122 pcg 1.2 };
123    
124 pcg 1.10 template<class R, class A1>
125     struct callback_funtype_trait1
126     {
127     static const int arity = 1;
128     typedef R type (A1);
129     typedef R result_type;
130     typedef A1 arg1_type;
131     };
132    
133     template<class R, class A1>
134     struct callback_funtype_trait<R (A1)> : callback_funtype_trait1<R, A1>
135     {
136     };
137    
138     template<class signature>
139     struct callback_get_impl<1, signature>
140     {
141     typedef callback_funtype_trait<signature> T;
142     typedef callback1<typename T::result_type, typename T::arg1_type> type;
143     };
144    
145 pcg 1.2 template<class R, class A1, class A2>
146 pcg 1.10 class callback2
147     {
148 pcg 1.11 struct klass; // it is vital that this is never defined
149 pcg 1.10
150 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2);
151 pcg 1.2
152 pcg 1.11 klass *o;
153     R (klass::*m)(A1, A2);
154 pcg 1.2
155     public:
156     template<class O1, class O2>
157 pcg 1.9 explicit callback2 (O1 *object, R (O2::*method)(A1, A2))
158 pcg 1.11 {
159     o = reinterpret_cast<klass *>(object);
160     m = reinterpret_cast<R (klass::*)(A1, A2)>(method);
161     }
162    
163     // this works because a standards-compliant C++ compiler
164     // basically can't help it: it doesn't have the knowledge
165     // required to miscompile (klass is not defined anywhere
166     // and nothing is known about the constructor arguments) :)
167 pcg 1.2 R call(A1 a1, A2 a2) const
168 pcg 1.11 {
169     return (o->*m) (a1, a2);
170     }
171 pcg 1.2
172     R operator ()(A1 a1, A2 a2) const
173 pcg 1.11 {
174     return call (a1, a2);
175     }
176 pcg 1.2 };
177    
178 pcg 1.10 template<class R, class A1, class A2>
179     struct callback_funtype_trait2
180     {
181     static const int arity = 2;
182     typedef R type (A1, A2);
183     typedef R result_type;
184     typedef A1 arg1_type; typedef A2 arg2_type;
185     };
186    
187     template<class R, class A1, class A2>
188     struct callback_funtype_trait<R (A1, A2)> : callback_funtype_trait2<R, A1, A2>
189     {
190     };
191    
192     template<class signature>
193     struct callback_get_impl<2, signature>
194     {
195     typedef callback_funtype_trait<signature> T;
196     typedef callback2<typename T::result_type, typename T::arg1_type, typename T::arg2_type> type;
197     };
198    
199 pcg 1.2 template<class R, class A1, class A2, class A3>
200 pcg 1.10 class callback3
201     {
202 pcg 1.11 struct klass; // it is vital that this is never defined
203 pcg 1.2
204 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3);
205 pcg 1.10
206 pcg 1.11 klass *o;
207     R (klass::*m)(A1, A2, A3);
208 pcg 1.2
209     public:
210     template<class O1, class O2>
211 pcg 1.9 explicit callback3 (O1 *object, R (O2::*method)(A1, A2, A3))
212 pcg 1.11 {
213     o = reinterpret_cast<klass *>(object);
214     m = reinterpret_cast<R (klass::*)(A1, A2, A3)>(method);
215     }
216    
217     // this works because a standards-compliant C++ compiler
218     // basically can't help it: it doesn't have the knowledge
219     // required to miscompile (klass is not defined anywhere
220     // and nothing is known about the constructor arguments) :)
221 pcg 1.2 R call(A1 a1, A2 a2, A3 a3) const
222 pcg 1.11 {
223     return (o->*m) (a1, a2, a3);
224     }
225 pcg 1.2
226     R operator ()(A1 a1, A2 a2, A3 a3) const
227 pcg 1.11 {
228     return call (a1, a2, a3);
229     }
230 pcg 1.2 };
231    
232 pcg 1.10 template<class R, class A1, class A2, class A3>
233     struct callback_funtype_trait3
234     {
235     static const int arity = 3;
236     typedef R type (A1, A2, A3);
237     typedef R result_type;
238     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type;
239     };
240    
241     template<class R, class A1, class A2, class A3>
242     struct callback_funtype_trait<R (A1, A2, A3)> : callback_funtype_trait3<R, A1, A2, A3>
243     {
244     };
245    
246     template<class signature>
247     struct callback_get_impl<3, signature>
248     {
249     typedef callback_funtype_trait<signature> T;
250     typedef callback3<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type> type;
251     };
252    
253 pcg 1.2 template<class R, class A1, class A2, class A3, class A4>
254 pcg 1.10 class callback4
255     {
256 pcg 1.11 struct klass; // it is vital that this is never defined
257 pcg 1.10
258 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4);
259 pcg 1.2
260 pcg 1.11 klass *o;
261     R (klass::*m)(A1, A2, A3, A4);
262 pcg 1.2
263     public:
264     template<class O1, class O2>
265 pcg 1.9 explicit callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4))
266 pcg 1.11 {
267     o = reinterpret_cast<klass *>(object);
268     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4)>(method);
269     }
270    
271     // this works because a standards-compliant C++ compiler
272     // basically can't help it: it doesn't have the knowledge
273     // required to miscompile (klass is not defined anywhere
274     // and nothing is known about the constructor arguments) :)
275 pcg 1.2 R call(A1 a1, A2 a2, A3 a3, A4 a4) const
276 pcg 1.11 {
277     return (o->*m) (a1, a2, a3, a4);
278     }
279 pcg 1.2
280     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
281 pcg 1.11 {
282     return call (a1, a2, a3, a4);
283     }
284 pcg 1.2 };
285    
286 pcg 1.10 template<class R, class A1, class A2, class A3, class A4>
287     struct callback_funtype_trait4
288     {
289     static const int arity = 4;
290     typedef R type (A1, A2, A3, A4);
291     typedef R result_type;
292     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type;
293     };
294    
295     template<class R, class A1, class A2, class A3, class A4>
296     struct callback_funtype_trait<R (A1, A2, A3, A4)> : callback_funtype_trait4<R, A1, A2, A3, A4>
297     {
298     };
299    
300     template<class signature>
301     struct callback_get_impl<4, signature>
302     {
303     typedef callback_funtype_trait<signature> T;
304     typedef callback4<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type> type;
305     };
306    
307 pcg 1.2 template<class R, class A1, class A2, class A3, class A4, class A5>
308 pcg 1.10 class callback5
309     {
310 pcg 1.11 struct klass; // it is vital that this is never defined
311 pcg 1.2
312 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5);
313 pcg 1.2
314 pcg 1.11 klass *o;
315     R (klass::*m)(A1, A2, A3, A4, A5);
316 pcg 1.2
317     public:
318     template<class O1, class O2>
319 pcg 1.9 explicit callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5))
320 pcg 1.11 {
321     o = reinterpret_cast<klass *>(object);
322     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5)>(method);
323     }
324    
325     // this works because a standards-compliant C++ compiler
326     // basically can't help it: it doesn't have the knowledge
327     // required to miscompile (klass is not defined anywhere
328     // and nothing is known about the constructor arguments) :)
329 pcg 1.2 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
330 pcg 1.11 {
331     return (o->*m) (a1, a2, a3, a4, a5);
332     }
333 pcg 1.2
334     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
335 pcg 1.11 {
336     return call (a1, a2, a3, a4, a5);
337     }
338 pcg 1.2 };
339    
340 pcg 1.10 template<class R, class A1, class A2, class A3, class A4, class A5>
341     struct callback_funtype_trait5
342     {
343     static const int arity = 5;
344     typedef R type (A1, A2, A3, A4, A5);
345     typedef R result_type;
346     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type;
347     };
348    
349     template<class R, class A1, class A2, class A3, class A4, class A5>
350     struct callback_funtype_trait<R (A1, A2, A3, A4, A5)> : callback_funtype_trait5<R, A1, A2, A3, A4, A5>
351     {
352     };
353    
354     template<class signature>
355     struct callback_get_impl<5, signature>
356     {
357     typedef callback_funtype_trait<signature> T;
358     typedef callback5<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type> type;
359     };
360    
361 pcg 1.2 template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
362 pcg 1.10 class callback6
363     {
364 pcg 1.11 struct klass; // it is vital that this is never defined
365 pcg 1.10
366 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6);
367 pcg 1.2
368 pcg 1.11 klass *o;
369     R (klass::*m)(A1, A2, A3, A4, A5, A6);
370 pcg 1.2
371     public:
372     template<class O1, class O2>
373 pcg 1.9 explicit callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6))
374 pcg 1.11 {
375     o = reinterpret_cast<klass *>(object);
376     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6)>(method);
377     }
378    
379     // this works because a standards-compliant C++ compiler
380     // basically can't help it: it doesn't have the knowledge
381     // required to miscompile (klass is not defined anywhere
382     // and nothing is known about the constructor arguments) :)
383 pcg 1.2 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
384 pcg 1.11 {
385     return (o->*m) (a1, a2, a3, a4, a5, a6);
386     }
387 pcg 1.2
388     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
389 pcg 1.11 {
390     return call (a1, a2, a3, a4, a5, a6);
391     }
392 pcg 1.2 };
393    
394 pcg 1.10 template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
395     struct callback_funtype_trait6
396     {
397     static const int arity = 6;
398     typedef R type (A1, A2, A3, A4, A5, A6);
399     typedef R result_type;
400     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type;
401     };
402    
403     template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
404     struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6)> : callback_funtype_trait6<R, A1, A2, A3, A4, A5, A6>
405     {
406     };
407    
408     template<class signature>
409     struct callback_get_impl<6, signature>
410     {
411     typedef callback_funtype_trait<signature> T;
412     typedef callback6<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type> type;
413     };
414    
415 pcg 1.2 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
416 pcg 1.10 class callback7
417     {
418 pcg 1.11 struct klass; // it is vital that this is never defined
419 pcg 1.2
420 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7);
421 pcg 1.10
422 pcg 1.11 klass *o;
423     R (klass::*m)(A1, A2, A3, A4, A5, A6, A7);
424 pcg 1.2
425     public:
426     template<class O1, class O2>
427 pcg 1.9 explicit callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7))
428 pcg 1.11 {
429     o = reinterpret_cast<klass *>(object);
430     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7)>(method);
431     }
432    
433     // this works because a standards-compliant C++ compiler
434     // basically can't help it: it doesn't have the knowledge
435     // required to miscompile (klass is not defined anywhere
436     // and nothing is known about the constructor arguments) :)
437 pcg 1.2 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
438 pcg 1.11 {
439     return (o->*m) (a1, a2, a3, a4, a5, a6, a7);
440     }
441 pcg 1.2
442     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
443 pcg 1.11 {
444     return call (a1, a2, a3, a4, a5, a6, a7);
445     }
446 pcg 1.1 };
447    
448 pcg 1.10 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
449     struct callback_funtype_trait7
450     {
451     static const int arity = 7;
452     typedef R type (A1, A2, A3, A4, A5, A6, A7);
453     typedef R result_type;
454     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type;
455     };
456    
457     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
458     struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7)> : callback_funtype_trait7<R, A1, A2, A3, A4, A5, A6, A7>
459     {
460     };
461    
462     template<class signature>
463     struct callback_get_impl<7, signature>
464     {
465     typedef callback_funtype_trait<signature> T;
466     typedef callback7<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type> type;
467     };
468    
469     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
470     class callback8
471     {
472 pcg 1.11 struct klass; // it is vital that this is never defined
473 pcg 1.10
474 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8);
475 pcg 1.10
476 pcg 1.11 klass *o;
477     R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8);
478 pcg 1.10
479     public:
480     template<class O1, class O2>
481     explicit callback8 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8))
482 pcg 1.11 {
483     o = reinterpret_cast<klass *>(object);
484     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8)>(method);
485     }
486    
487     // this works because a standards-compliant C++ compiler
488     // basically can't help it: it doesn't have the knowledge
489     // required to miscompile (klass is not defined anywhere
490     // and nothing is known about the constructor arguments) :)
491 pcg 1.10 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
492 pcg 1.11 {
493     return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8);
494     }
495 pcg 1.10
496     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
497 pcg 1.11 {
498     return call (a1, a2, a3, a4, a5, a6, a7, a8);
499     }
500 pcg 1.10 };
501    
502     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
503     struct callback_funtype_trait8
504     {
505     static const int arity = 8;
506     typedef R type (A1, A2, A3, A4, A5, A6, A7, A8);
507     typedef R result_type;
508     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type; typedef A8 arg8_type;
509     };
510    
511     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
512     struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7, A8)> : callback_funtype_trait8<R, A1, A2, A3, A4, A5, A6, A7, A8>
513     {
514     };
515    
516     template<class signature>
517     struct callback_get_impl<8, signature>
518     {
519     typedef callback_funtype_trait<signature> T;
520     typedef callback8<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type, typename T::arg8_type> type;
521     };
522    
523     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
524     class callback9
525     {
526 pcg 1.11 struct klass; // it is vital that this is never defined
527 pcg 1.10
528 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
529 pcg 1.10
530 pcg 1.11 klass *o;
531     R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
532 pcg 1.10
533     public:
534     template<class O1, class O2>
535     explicit callback9 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9))
536 pcg 1.11 {
537     o = reinterpret_cast<klass *>(object);
538     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>(method);
539     }
540    
541     // this works because a standards-compliant C++ compiler
542     // basically can't help it: it doesn't have the knowledge
543     // required to miscompile (klass is not defined anywhere
544     // and nothing is known about the constructor arguments) :)
545 pcg 1.10 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
546 pcg 1.11 {
547     return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
548     }
549 pcg 1.10
550     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
551 pcg 1.11 {
552     return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
553     }
554 pcg 1.10 };
555    
556     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
557     struct callback_funtype_trait9
558     {
559     static const int arity = 9;
560     typedef R type (A1, A2, A3, A4, A5, A6, A7, A8, A9);
561     typedef R result_type;
562     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type; typedef A8 arg8_type; typedef A9 arg9_type;
563     };
564    
565     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
566     struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)> : callback_funtype_trait9<R, A1, A2, A3, A4, A5, A6, A7, A8, A9>
567     {
568     };
569    
570     template<class signature>
571     struct callback_get_impl<9, signature>
572     {
573     typedef callback_funtype_trait<signature> T;
574     typedef callback9<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type, typename T::arg8_type, typename T::arg9_type> type;
575     };
576    
577     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
578     class callback10
579     {
580 pcg 1.11 struct klass; // it is vital that this is never defined
581 pcg 1.10
582 pcg 1.11 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
583 pcg 1.10
584 pcg 1.11 klass *o;
585     R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
586 pcg 1.10
587     public:
588     template<class O1, class O2>
589     explicit callback10 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10))
590 pcg 1.11 {
591     o = reinterpret_cast<klass *>(object);
592     m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>(method);
593     }
594    
595     // this works because a standards-compliant C++ compiler
596     // basically can't help it: it doesn't have the knowledge
597     // required to miscompile (klass is not defined anywhere
598     // and nothing is known about the constructor arguments) :)
599 pcg 1.10 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
600 pcg 1.11 {
601     return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
602     }
603 pcg 1.10
604     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
605 pcg 1.11 {
606     return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
607     }
608 pcg 1.10 };
609    
610     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
611     struct callback_funtype_trait10
612     {
613     static const int arity = 10;
614     typedef R type (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
615     typedef R result_type;
616     typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type; typedef A8 arg8_type; typedef A9 arg9_type; typedef A10 arg10_type;
617     };
618    
619     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
620     struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : callback_funtype_trait10<R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>
621     {
622     };
623    
624     template<class signature>
625     struct callback_get_impl<10, signature>
626     {
627     typedef callback_funtype_trait<signature> T;
628     typedef callback10<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type, typename T::arg8_type, typename T::arg9_type, typename T::arg10_type> type;
629     };
630    
631    
632     template<class signature>
633     struct callback : callback_get_impl<callback_funtype_trait<signature>::arity, signature>::type
634     {
635     typedef typename callback_get_impl<callback_funtype_trait<signature>::arity, signature>::type base_type;
636    
637     template<class O, class M>
638     explicit callback (O object, M method)
639 pcg 1.11 : base_type (object, method)
640     {
641     }
642 pcg 1.10 };
643    
644 pcg 1.1 #endif