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.6 by pcg, Tue Apr 26 00:55:55 2005 UTC vs.
Revision 1.11 by pcg, Sun Dec 2 00:54:52 2007 UTC

1// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it 1// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it
2// 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, RUN callback.pl to regenerate it 3// THIS IS A GENERATED FILE: distribution.
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 4
8/* 5/*
9 callback.h -- C++ callback mechanism 6 callback.h -- C++ callback mechanism
10 Copyright (C) 2003-2005 Marc Lehmann <gvpe@schmorp.de> 7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
11 8
12 This file is part of GVPE. 9 This file is part of GVPE.
13 10
14 GVPE is free software; you can redistribute it and/or modify 11 GVPE is free software; you can redistribute it and/or modify
15 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
27*/ 24*/
28 25
29#ifndef CALLBACK_H__ 26#ifndef CALLBACK_H__
30#define CALLBACK_H__ 27#define CALLBACK_H__
31 28
29#define CALLBACK_H_VERSION 3
30
31template<class signature>
32struct callback_funtype_trait;
33
34template<int arity, class signature>
35struct callback_get_impl;
36
32template<class R> 37template<class R>
33class callback0 { 38class callback0
34 struct object { }; 39{
40 struct klass; // it is vital that this is never defined
35 41
36 void *obj; 42 typedef R (klass::*ptr_type)();
37 R (object::*meth)();
38 43
39 /* a proxy is a kind of recipe on how to call a specific class method */ 44 klass *o;
40 struct proxy_base { 45 R (klass::*m)();
41 virtual R call (void *obj, R (object::*meth)()) = 0;
42 };
43 template<class O1, class O2>
44 struct proxy : proxy_base {
45 virtual R call (void *obj, R (object::*meth)())
46 {
47 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)()>(meth)))
48 ();
49 }
50 };
51 46
52 proxy_base *prxy;
53
54public: 47public:
55 template<class O1, class O2> 48 template<class O1, class O2>
56 callback0 (O1 *object, R (O2::*method)()) 49 explicit callback0 (O1 *object, R (O2::*method)())
57 { 50 {
58 static proxy<O1,O2> p;
59 obj = reinterpret_cast<void *>(object); 51 o = reinterpret_cast<klass *>(object);
60 meth = reinterpret_cast<R (object::*)()>(method); 52 m = reinterpret_cast<R (klass::*)()>(method);
61 prxy = &p;
62 } 53 }
63 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) :)
64 R call() const 59 R call() const
65 { 60 {
66 return prxy->call (obj, meth); 61 return (o->*m) ();
67 } 62 }
68 63
69 R operator ()() const 64 R operator ()() const
70 { 65 {
71 return call (); 66 return call ();
72 } 67 }
73}; 68};
74 69
70template<class R>
71struct callback_funtype_trait0
72{
73 static const int arity = 0;
74 typedef R type (void);
75 typedef R result_type;
76
77};
78
79template<class R>
80struct callback_funtype_trait<R ()> : callback_funtype_trait0<R>
81{
82};
83
84template<class signature>
85struct callback_get_impl<0, signature>
86{
87 typedef callback_funtype_trait<signature> T;
88 typedef callback0<typename T::result_type> type;
89};
90
75template<class R, class A1> 91template<class R, class A1>
76class callback1 { 92class callback1
77 struct object { }; 93{
94 struct klass; // it is vital that this is never defined
78 95
79 void *obj; 96 typedef R (klass::*ptr_type)(A1);
80 R (object::*meth)(A1);
81 97
82 /* a proxy is a kind of recipe on how to call a specific class method */ 98 klass *o;
83 struct proxy_base { 99 R (klass::*m)(A1);
84 virtual R call (void *obj, R (object::*meth)(A1), A1 a1) = 0;
85 };
86 template<class O1, class O2>
87 struct proxy : proxy_base {
88 virtual R call (void *obj, R (object::*meth)(A1), A1 a1)
89 {
90 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1)>(meth)))
91 (a1);
92 }
93 };
94 100
95 proxy_base *prxy;
96
97public: 101public:
98 template<class O1, class O2> 102 template<class O1, class O2>
99 callback1 (O1 *object, R (O2::*method)(A1)) 103 explicit callback1 (O1 *object, R (O2::*method)(A1))
100 { 104 {
101 static proxy<O1,O2> p;
102 obj = reinterpret_cast<void *>(object); 105 o = reinterpret_cast<klass *>(object);
103 meth = reinterpret_cast<R (object::*)(A1)>(method); 106 m = reinterpret_cast<R (klass::*)(A1)>(method);
104 prxy = &p;
105 } 107 }
106 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) :)
107 R call(A1 a1) const 113 R call(A1 a1) const
108 { 114 {
109 return prxy->call (obj, meth, a1); 115 return (o->*m) (a1);
110 } 116 }
111 117
112 R operator ()(A1 a1) const 118 R operator ()(A1 a1) const
113 { 119 {
114 return call (a1); 120 return call (a1);
115 } 121 }
116}; 122};
117 123
124template<class R, class A1>
125struct 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
133template<class R, class A1>
134struct callback_funtype_trait<R (A1)> : callback_funtype_trait1<R, A1>
135{
136};
137
138template<class signature>
139struct 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
118template<class R, class A1, class A2> 145template<class R, class A1, class A2>
119class callback2 { 146class callback2
120 struct object { }; 147{
148 struct klass; // it is vital that this is never defined
121 149
122 void *obj; 150 typedef R (klass::*ptr_type)(A1, A2);
123 R (object::*meth)(A1, A2);
124 151
125 /* a proxy is a kind of recipe on how to call a specific class method */ 152 klass *o;
126 struct proxy_base { 153 R (klass::*m)(A1, A2);
127 virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) = 0;
128 };
129 template<class O1, class O2>
130 struct proxy : proxy_base {
131 virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2)
132 {
133 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2)>(meth)))
134 (a1, a2);
135 }
136 };
137 154
138 proxy_base *prxy;
139
140public: 155public:
141 template<class O1, class O2> 156 template<class O1, class O2>
142 callback2 (O1 *object, R (O2::*method)(A1, A2)) 157 explicit callback2 (O1 *object, R (O2::*method)(A1, A2))
143 { 158 {
144 static proxy<O1,O2> p;
145 obj = reinterpret_cast<void *>(object); 159 o = reinterpret_cast<klass *>(object);
146 meth = reinterpret_cast<R (object::*)(A1, A2)>(method); 160 m = reinterpret_cast<R (klass::*)(A1, A2)>(method);
147 prxy = &p;
148 } 161 }
149 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) :)
150 R call(A1 a1, A2 a2) const 167 R call(A1 a1, A2 a2) const
151 { 168 {
152 return prxy->call (obj, meth, a1, a2); 169 return (o->*m) (a1, a2);
153 } 170 }
154 171
155 R operator ()(A1 a1, A2 a2) const 172 R operator ()(A1 a1, A2 a2) const
156 { 173 {
157 return call (a1, a2); 174 return call (a1, a2);
158 } 175 }
159}; 176};
160 177
178template<class R, class A1, class A2>
179struct 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
187template<class R, class A1, class A2>
188struct callback_funtype_trait<R (A1, A2)> : callback_funtype_trait2<R, A1, A2>
189{
190};
191
192template<class signature>
193struct 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
161template<class R, class A1, class A2, class A3> 199template<class R, class A1, class A2, class A3>
162class callback3 { 200class callback3
163 struct object { }; 201{
202 struct klass; // it is vital that this is never defined
164 203
165 void *obj; 204 typedef R (klass::*ptr_type)(A1, A2, A3);
205
206 klass *o;
166 R (object::*meth)(A1, A2, A3); 207 R (klass::*m)(A1, A2, A3);
167 208
168 /* a proxy is a kind of recipe on how to call a specific class method */
169 struct proxy_base {
170 virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) = 0;
171 };
172 template<class O1, class O2>
173 struct proxy : proxy_base {
174 virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3)
175 {
176 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3)>(meth)))
177 (a1, a2, a3);
178 }
179 };
180
181 proxy_base *prxy;
182
183public: 209public:
184 template<class O1, class O2> 210 template<class O1, class O2>
185 callback3 (O1 *object, R (O2::*method)(A1, A2, A3)) 211 explicit callback3 (O1 *object, R (O2::*method)(A1, A2, A3))
186 { 212 {
187 static proxy<O1,O2> p;
188 obj = reinterpret_cast<void *>(object); 213 o = reinterpret_cast<klass *>(object);
189 meth = reinterpret_cast<R (object::*)(A1, A2, A3)>(method); 214 m = reinterpret_cast<R (klass::*)(A1, A2, A3)>(method);
190 prxy = &p;
191 } 215 }
192 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) :)
193 R call(A1 a1, A2 a2, A3 a3) const 221 R call(A1 a1, A2 a2, A3 a3) const
194 { 222 {
195 return prxy->call (obj, meth, a1, a2, a3); 223 return (o->*m) (a1, a2, a3);
196 } 224 }
197 225
198 R operator ()(A1 a1, A2 a2, A3 a3) const 226 R operator ()(A1 a1, A2 a2, A3 a3) const
199 { 227 {
200 return call (a1, a2, a3); 228 return call (a1, a2, a3);
201 } 229 }
202}; 230};
203 231
232template<class R, class A1, class A2, class A3>
233struct 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
241template<class R, class A1, class A2, class A3>
242struct callback_funtype_trait<R (A1, A2, A3)> : callback_funtype_trait3<R, A1, A2, A3>
243{
244};
245
246template<class signature>
247struct 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
204template<class R, class A1, class A2, class A3, class A4> 253template<class R, class A1, class A2, class A3, class A4>
205class callback4 { 254class callback4
206 struct object { }; 255{
256 struct klass; // it is vital that this is never defined
207 257
208 void *obj; 258 typedef R (klass::*ptr_type)(A1, A2, A3, A4);
259
260 klass *o;
209 R (object::*meth)(A1, A2, A3, A4); 261 R (klass::*m)(A1, A2, A3, A4);
210 262
211 /* a proxy is a kind of recipe on how to call a specific class method */
212 struct proxy_base {
213 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) = 0;
214 };
215 template<class O1, class O2>
216 struct proxy : proxy_base {
217 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4)
218 {
219 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4)>(meth)))
220 (a1, a2, a3, a4);
221 }
222 };
223
224 proxy_base *prxy;
225
226public: 263public:
227 template<class O1, class O2> 264 template<class O1, class O2>
228 callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4)) 265 explicit callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4))
229 { 266 {
230 static proxy<O1,O2> p;
231 obj = reinterpret_cast<void *>(object); 267 o = reinterpret_cast<klass *>(object);
232 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4)>(method); 268 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4)>(method);
233 prxy = &p;
234 } 269 }
235 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) :)
236 R call(A1 a1, A2 a2, A3 a3, A4 a4) const 275 R call(A1 a1, A2 a2, A3 a3, A4 a4) const
237 { 276 {
238 return prxy->call (obj, meth, a1, a2, a3, a4); 277 return (o->*m) (a1, a2, a3, a4);
239 } 278 }
240 279
241 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const 280 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
242 { 281 {
243 return call (a1, a2, a3, a4); 282 return call (a1, a2, a3, a4);
244 } 283 }
245}; 284};
246 285
286template<class R, class A1, class A2, class A3, class A4>
287struct 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
295template<class R, class A1, class A2, class A3, class A4>
296struct callback_funtype_trait<R (A1, A2, A3, A4)> : callback_funtype_trait4<R, A1, A2, A3, A4>
297{
298};
299
300template<class signature>
301struct 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
247template<class R, class A1, class A2, class A3, class A4, class A5> 307template<class R, class A1, class A2, class A3, class A4, class A5>
248class callback5 { 308class callback5
249 struct object { }; 309{
310 struct klass; // it is vital that this is never defined
250 311
251 void *obj; 312 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5);
313
314 klass *o;
252 R (object::*meth)(A1, A2, A3, A4, A5); 315 R (klass::*m)(A1, A2, A3, A4, A5);
253 316
254 /* a proxy is a kind of recipe on how to call a specific class method */
255 struct proxy_base {
256 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) = 0;
257 };
258 template<class O1, class O2>
259 struct proxy : proxy_base {
260 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
261 {
262 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5)>(meth)))
263 (a1, a2, a3, a4, a5);
264 }
265 };
266
267 proxy_base *prxy;
268
269public: 317public:
270 template<class O1, class O2> 318 template<class O1, class O2>
271 callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5)) 319 explicit callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5))
272 { 320 {
273 static proxy<O1,O2> p;
274 obj = reinterpret_cast<void *>(object); 321 o = reinterpret_cast<klass *>(object);
275 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5)>(method); 322 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5)>(method);
276 prxy = &p;
277 } 323 }
278 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) :)
279 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 329 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
280 { 330 {
281 return prxy->call (obj, meth, a1, a2, a3, a4, a5); 331 return (o->*m) (a1, a2, a3, a4, a5);
282 } 332 }
283 333
284 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 334 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
285 { 335 {
286 return call (a1, a2, a3, a4, a5); 336 return call (a1, a2, a3, a4, a5);
287 } 337 }
288}; 338};
289 339
340template<class R, class A1, class A2, class A3, class A4, class A5>
341struct 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
349template<class R, class A1, class A2, class A3, class A4, class A5>
350struct callback_funtype_trait<R (A1, A2, A3, A4, A5)> : callback_funtype_trait5<R, A1, A2, A3, A4, A5>
351{
352};
353
354template<class signature>
355struct 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
290template<class R, class A1, class A2, class A3, class A4, class A5, class A6> 361template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
291class callback6 { 362class callback6
292 struct object { }; 363{
364 struct klass; // it is vital that this is never defined
293 365
294 void *obj; 366 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6);
367
368 klass *o;
295 R (object::*meth)(A1, A2, A3, A4, A5, A6); 369 R (klass::*m)(A1, A2, A3, A4, A5, A6);
296 370
297 /* a proxy is a kind of recipe on how to call a specific class method */
298 struct proxy_base {
299 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;
300 };
301 template<class O1, class O2>
302 struct proxy : proxy_base {
303 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)
304 {
305 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6)>(meth)))
306 (a1, a2, a3, a4, a5, a6);
307 }
308 };
309
310 proxy_base *prxy;
311
312public: 371public:
313 template<class O1, class O2> 372 template<class O1, class O2>
314 callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6)) 373 explicit callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6))
315 { 374 {
316 static proxy<O1,O2> p;
317 obj = reinterpret_cast<void *>(object); 375 o = reinterpret_cast<klass *>(object);
318 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6)>(method); 376 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6)>(method);
319 prxy = &p;
320 } 377 }
321 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) :)
322 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 383 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
323 { 384 {
324 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6); 385 return (o->*m) (a1, a2, a3, a4, a5, a6);
325 } 386 }
326 387
327 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 388 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
328 { 389 {
329 return call (a1, a2, a3, a4, a5, a6); 390 return call (a1, a2, a3, a4, a5, a6);
330 } 391 }
331}; 392};
332 393
394template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
395struct 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
403template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
404struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6)> : callback_funtype_trait6<R, A1, A2, A3, A4, A5, A6>
405{
406};
407
408template<class signature>
409struct 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
333template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> 415template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
334class callback7 { 416class callback7
335 struct object { }; 417{
418 struct klass; // it is vital that this is never defined
336 419
337 void *obj; 420 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7);
421
422 klass *o;
338 R (object::*meth)(A1, A2, A3, A4, A5, A6, A7); 423 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7);
339 424
340 /* a proxy is a kind of recipe on how to call a specific class method */
341 struct proxy_base {
342 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;
343 };
344 template<class O1, class O2>
345 struct proxy : proxy_base {
346 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)
347 {
348 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7)>(meth)))
349 (a1, a2, a3, a4, a5, a6, a7);
350 }
351 };
352
353 proxy_base *prxy;
354
355public: 425public:
356 template<class O1, class O2> 426 template<class O1, class O2>
357 callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7)) 427 explicit callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7))
358 { 428 {
359 static proxy<O1,O2> p;
360 obj = reinterpret_cast<void *>(object); 429 o = reinterpret_cast<klass *>(object);
361 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7)>(method); 430 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7)>(method);
362 prxy = &p;
363 } 431 }
364 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) :)
365 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 437 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
366 { 438 {
367 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7); 439 return (o->*m) (a1, a2, a3, a4, a5, a6, a7);
368 } 440 }
369 441
370 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 442 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
371 { 443 {
372 return call (a1, a2, a3, a4, a5, a6, a7); 444 return call (a1, a2, a3, a4, a5, a6, a7);
373 } 445 }
446};
447
448template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
449struct 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
457template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
458struct 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
462template<class signature>
463struct 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
469template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
470class callback8
471{
472 struct klass; // it is vital that this is never defined
473
474 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8);
475
476 klass *o;
477 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8);
478
479public:
480 template<class O1, class O2>
481 explicit callback8 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8))
482 {
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 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
492 {
493 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8);
494 }
495
496 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
497 {
498 return call (a1, a2, a3, a4, a5, a6, a7, a8);
499 }
500};
501
502template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
503struct 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
511template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
512struct 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
516template<class signature>
517struct 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
523template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
524class callback9
525{
526 struct klass; // it is vital that this is never defined
527
528 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
529
530 klass *o;
531 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
532
533public:
534 template<class O1, class O2>
535 explicit callback9 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9))
536 {
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 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
546 {
547 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
548 }
549
550 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
551 {
552 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
553 }
554};
555
556template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
557struct 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
565template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
566struct 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
570template<class signature>
571struct 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
577template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
578class callback10
579{
580 struct klass; // it is vital that this is never defined
581
582 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
583
584 klass *o;
585 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
586
587public:
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 {
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 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
600 {
601 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
602 }
603
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 {
606 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
607 }
608};
609
610template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
611struct 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
619template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
620struct 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
624template<class signature>
625struct 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
632template<class signature>
633struct 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 : base_type (object, method)
640 {
641 }
374}; 642};
375 643
376#endif 644#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines