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.11 by pcg, Sun Dec 2 00:54:52 2007 UTC vs.
Revision 1.13 by pcg, Tue Dec 4 17:17:19 2007 UTC

26#ifndef CALLBACK_H__ 26#ifndef CALLBACK_H__
27#define CALLBACK_H__ 27#define CALLBACK_H__
28 28
29#define CALLBACK_H_VERSION 3 29#define CALLBACK_H_VERSION 3
30 30
31template<class signature> 31template<typename signature>
32struct callback_funtype_trait;
33
34template<int arity, class signature>
35struct callback_get_impl; 32struct callback;
36 33
37template<class R> 34template<class R>
38class callback0 35struct callback<R ()>
39{ 36{
40 struct klass; // it is vital that this is never defined
41
42 typedef R (klass::*ptr_type)(); 37 typedef R (*ptr_type)(void *self);
43 38
44 klass *o; 39private:
45 R (klass::*m)();
46 40
47public: 41 void *self;
42 ptr_type func;
43
44protected:
45
46 template<typename method>
47 struct thunktype;
48
48 template<class O1, class O2> 49 template<class klass>
49 explicit callback0 (O1 *object, R (O2::*method)()) 50 struct thunktype<R (klass::*)>
50 { 51 {
51 o = reinterpret_cast<klass *>(object); 52 typedef klass K;
52 m = reinterpret_cast<R (klass::*)()>(method);
53 } 53 };
54 54
55 // this works because a standards-compliant C++ compiler 55 template<class klass, R (klass::*method)()>
56 // basically can't help it: it doesn't have the knowledge 56 static R thunk (void *self)
57 // required to miscompile (klass is not defined anywhere 57 {
58 // and nothing is known about the constructor arguments) :) 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
59 R call() const 70 R call () const
60 { 71 {
61 return (o->*m) (); 72 return func (self);
62 } 73 }
63 74
64 R operator ()() const 75 R operator ()() const
65 { 76 {
66 return call (); 77 return call ();
67 } 78 }
68}; 79};
69 80
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
91template<class R, class A1> 81template<class R, class A1>
92class callback1 82struct callback<R (A1)>
93{ 83{
94 struct klass; // it is vital that this is never defined 84 typedef R (*ptr_type)(void *self, A1);
95 85
96 typedef R (klass::*ptr_type)(A1); 86private:
97 87
98 klass *o; 88 void *self;
99 R (klass::*m)(A1); 89 ptr_type func;
100 90
101public: 91protected:
92
93 template<typename method>
94 struct thunktype;
95
102 template<class O1, class O2> 96 template<class klass>
103 explicit callback1 (O1 *object, R (O2::*method)(A1)) 97 struct thunktype<R (klass::*)>
104 { 98 {
105 o = reinterpret_cast<klass *>(object); 99 typedef klass K;
106 m = reinterpret_cast<R (klass::*)(A1)>(method);
107 } 100 };
108 101
109 // this works because a standards-compliant C++ compiler 102 template<class klass, R (klass::*method)(A1)>
110 // basically can't help it: it doesn't have the knowledge 103 static R thunk (void *self, A1 a1)
111 // required to miscompile (klass is not defined anywhere 104 {
112 // and nothing is known about the constructor arguments) :) 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
113 R call(A1 a1) const 117 R call (A1 a1) const
114 { 118 {
115 return (o->*m) (a1); 119 return func (self, a1);
116 } 120 }
117 121
118 R operator ()(A1 a1) const 122 R operator ()(A1 a1) const
119 { 123 {
120 return call (a1); 124 return call (a1);
121 } 125 }
122}; 126};
123 127
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
145template<class R, class A1, class A2> 128template<class R, class A1, class A2>
146class callback2 129struct callback<R (A1, A2)>
147{ 130{
148 struct klass; // it is vital that this is never defined
149
150 typedef R (klass::*ptr_type)(A1, A2); 131 typedef R (*ptr_type)(void *self, A1, A2);
151 132
152 klass *o; 133private:
153 R (klass::*m)(A1, A2);
154 134
155public: 135 void *self;
136 ptr_type func;
137
138protected:
139
140 template<typename method>
141 struct thunktype;
142
156 template<class O1, class O2> 143 template<class klass>
157 explicit callback2 (O1 *object, R (O2::*method)(A1, A2)) 144 struct thunktype<R (klass::*)>
158 { 145 {
159 o = reinterpret_cast<klass *>(object); 146 typedef klass K;
160 m = reinterpret_cast<R (klass::*)(A1, A2)>(method);
161 } 147 };
162 148
163 // this works because a standards-compliant C++ compiler 149 template<class klass, R (klass::*method)(A1, A2)>
164 // basically can't help it: it doesn't have the knowledge 150 static R thunk (void *self, A1 a1, A2 a2)
165 // required to miscompile (klass is not defined anywhere 151 {
166 // and nothing is known about the constructor arguments) :) 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
167 R call(A1 a1, A2 a2) const 164 R call (A1 a1, A2 a2) const
168 { 165 {
169 return (o->*m) (a1, a2); 166 return func (self, a1, a2);
170 } 167 }
171 168
172 R operator ()(A1 a1, A2 a2) const 169 R operator ()(A1 a1, A2 a2) const
173 { 170 {
174 return call (a1, a2); 171 return call (a1, a2);
175 } 172 }
176}; 173};
177 174
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
199template<class R, class A1, class A2, class A3> 175template<class R, class A1, class A2, class A3>
200class callback3 176struct callback<R (A1, A2, A3)>
201{ 177{
202 struct klass; // it is vital that this is never defined
203
204 typedef R (klass::*ptr_type)(A1, A2, A3); 178 typedef R (*ptr_type)(void *self, A1, A2, A3);
205 179
206 klass *o; 180private:
207 R (klass::*m)(A1, A2, A3);
208 181
209public: 182 void *self;
183 ptr_type func;
184
185protected:
186
187 template<typename method>
188 struct thunktype;
189
210 template<class O1, class O2> 190 template<class klass>
211 explicit callback3 (O1 *object, R (O2::*method)(A1, A2, A3)) 191 struct thunktype<R (klass::*)>
212 { 192 {
213 o = reinterpret_cast<klass *>(object); 193 typedef klass K;
214 m = reinterpret_cast<R (klass::*)(A1, A2, A3)>(method);
215 } 194 };
216 195
217 // this works because a standards-compliant C++ compiler 196 template<class klass, R (klass::*method)(A1, A2, A3)>
218 // basically can't help it: it doesn't have the knowledge 197 static R thunk (void *self, A1 a1, A2 a2, A3 a3)
219 // required to miscompile (klass is not defined anywhere 198 {
220 // and nothing is known about the constructor arguments) :) 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
221 R call(A1 a1, A2 a2, A3 a3) const 211 R call (A1 a1, A2 a2, A3 a3) const
222 { 212 {
223 return (o->*m) (a1, a2, a3); 213 return func (self, a1, a2, a3);
224 } 214 }
225 215
226 R operator ()(A1 a1, A2 a2, A3 a3) const 216 R operator ()(A1 a1, A2 a2, A3 a3) const
227 { 217 {
228 return call (a1, a2, a3); 218 return call (a1, a2, a3);
229 } 219 }
230}; 220};
231 221
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
253template<class R, class A1, class A2, class A3, class A4> 222template<class R, class A1, class A2, class A3, class A4>
254class callback4 223struct callback<R (A1, A2, A3, A4)>
255{ 224{
256 struct klass; // it is vital that this is never defined
257
258 typedef R (klass::*ptr_type)(A1, A2, A3, A4); 225 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
259 226
260 klass *o; 227private:
261 R (klass::*m)(A1, A2, A3, A4);
262 228
263public: 229 void *self;
230 ptr_type func;
231
232protected:
233
234 template<typename method>
235 struct thunktype;
236
264 template<class O1, class O2> 237 template<class klass>
265 explicit callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4)) 238 struct thunktype<R (klass::*)>
266 { 239 {
267 o = reinterpret_cast<klass *>(object); 240 typedef klass K;
268 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4)>(method);
269 } 241 };
270 242
271 // this works because a standards-compliant C++ compiler 243 template<class klass, R (klass::*method)(A1, A2, A3, A4)>
272 // basically can't help it: it doesn't have the knowledge 244 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4)
273 // required to miscompile (klass is not defined anywhere 245 {
274 // and nothing is known about the constructor arguments) :) 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
275 R call(A1 a1, A2 a2, A3 a3, A4 a4) const 258 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
276 { 259 {
277 return (o->*m) (a1, a2, a3, a4); 260 return func (self, a1, a2, a3, a4);
278 } 261 }
279 262
280 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const 263 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
281 { 264 {
282 return call (a1, a2, a3, a4); 265 return call (a1, a2, a3, a4);
283 } 266 }
284}; 267};
285 268
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
307template<class R, class A1, class A2, class A3, class A4, class A5> 269template<class R, class A1, class A2, class A3, class A4, class A5>
308class callback5 270struct callback<R (A1, A2, A3, A4, A5)>
309{ 271{
310 struct klass; // it is vital that this is never defined
311
312 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5); 272 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
313 273
314 klass *o; 274private:
315 R (klass::*m)(A1, A2, A3, A4, A5);
316 275
317public: 276 void *self;
277 ptr_type func;
278
279protected:
280
281 template<typename method>
282 struct thunktype;
283
318 template<class O1, class O2> 284 template<class klass>
319 explicit callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5)) 285 struct thunktype<R (klass::*)>
320 { 286 {
321 o = reinterpret_cast<klass *>(object); 287 typedef klass K;
322 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5)>(method);
323 } 288 };
324 289
325 // this works because a standards-compliant C++ compiler 290 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5)>
326 // basically can't help it: it doesn't have the knowledge 291 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
327 // required to miscompile (klass is not defined anywhere 292 {
328 // and nothing is known about the constructor arguments) :) 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
329 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 305 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
330 { 306 {
331 return (o->*m) (a1, a2, a3, a4, a5); 307 return func (self, a1, a2, a3, a4, a5);
332 } 308 }
333 309
334 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 310 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
335 { 311 {
336 return call (a1, a2, a3, a4, a5); 312 return call (a1, a2, a3, a4, a5);
337 } 313 }
338}; 314};
339 315
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
361template<class R, class A1, class A2, class A3, class A4, class A5, class A6> 316template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
362class callback6 317struct callback<R (A1, A2, A3, A4, A5, A6)>
363{ 318{
364 struct klass; // it is vital that this is never defined
365
366 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6); 319 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
367 320
368 klass *o; 321private:
369 R (klass::*m)(A1, A2, A3, A4, A5, A6);
370 322
371public: 323 void *self;
324 ptr_type func;
325
326protected:
327
328 template<typename method>
329 struct thunktype;
330
372 template<class O1, class O2> 331 template<class klass>
373 explicit callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6)) 332 struct thunktype<R (klass::*)>
374 { 333 {
375 o = reinterpret_cast<klass *>(object); 334 typedef klass K;
376 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6)>(method);
377 } 335 };
378 336
379 // this works because a standards-compliant C++ compiler 337 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6)>
380 // basically can't help it: it doesn't have the knowledge 338 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
381 // required to miscompile (klass is not defined anywhere 339 {
382 // and nothing is known about the constructor arguments) :) 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
383 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 352 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
384 { 353 {
385 return (o->*m) (a1, a2, a3, a4, a5, a6); 354 return func (self, a1, a2, a3, a4, a5, a6);
386 } 355 }
387 356
388 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 357 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
389 { 358 {
390 return call (a1, a2, a3, a4, a5, a6); 359 return call (a1, a2, a3, a4, a5, a6);
391 } 360 }
392}; 361};
393 362
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
415template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> 363template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
416class callback7 364struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
417{ 365{
418 struct klass; // it is vital that this is never defined
419
420 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6, A7); 366 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
421 367
422 klass *o; 368private:
423 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7);
424 369
425public: 370 void *self;
371 ptr_type func;
372
373protected:
374
375 template<typename method>
376 struct thunktype;
377
426 template<class O1, class O2> 378 template<class klass>
427 explicit callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7)) 379 struct thunktype<R (klass::*)>
428 { 380 {
429 o = reinterpret_cast<klass *>(object); 381 typedef klass K;
430 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7)>(method);
431 } 382 };
432 383
433 // this works because a standards-compliant C++ compiler 384 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7)>
434 // basically can't help it: it doesn't have the knowledge 385 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
435 // required to miscompile (klass is not defined anywhere 386 {
436 // and nothing is known about the constructor arguments) :) 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
437 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 399 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
438 { 400 {
439 return (o->*m) (a1, a2, a3, a4, a5, a6, a7); 401 return func (self, a1, a2, a3, a4, a5, a6, a7);
440 } 402 }
441 403
442 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 404 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
443 { 405 {
444 return call (a1, a2, a3, a4, a5, a6, a7); 406 return call (a1, a2, a3, a4, a5, a6, a7);
445 } 407 }
446}; 408};
447 409
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> 410template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
470class callback8 411struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
471{ 412{
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); 413 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
475 414
476 klass *o; 415private:
477 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8);
478 416
479public: 417 void *self;
418 ptr_type func;
419
420protected:
421
422 template<typename method>
423 struct thunktype;
424
480 template<class O1, class O2> 425 template<class klass>
481 explicit callback8 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8)) 426 struct thunktype<R (klass::*)>
482 { 427 {
483 o = reinterpret_cast<klass *>(object); 428 typedef klass K;
484 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8)>(method);
485 } 429 };
486 430
487 // this works because a standards-compliant C++ compiler 431 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
488 // basically can't help it: it doesn't have the knowledge 432 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
489 // required to miscompile (klass is not defined anywhere 433 {
490 // and nothing is known about the constructor arguments) :) 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
491 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 446 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
492 { 447 {
493 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8); 448 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
494 } 449 }
495 450
496 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 451 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
497 { 452 {
498 return call (a1, a2, a3, a4, a5, a6, a7, a8); 453 return call (a1, a2, a3, a4, a5, a6, a7, a8);
499 } 454 }
500}; 455};
501 456
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> 457template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
524class callback9 458struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
525{ 459{
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); 460 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
529 461
530 klass *o; 462private:
531 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
532 463
533public: 464 void *self;
465 ptr_type func;
466
467protected:
468
469 template<typename method>
470 struct thunktype;
471
534 template<class O1, class O2> 472 template<class klass>
535 explicit callback9 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) 473 struct thunktype<R (klass::*)>
536 { 474 {
537 o = reinterpret_cast<klass *>(object); 475 typedef klass K;
538 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>(method);
539 } 476 };
540 477
541 // this works because a standards-compliant C++ compiler 478 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
542 // basically can't help it: it doesn't have the knowledge 479 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
543 // required to miscompile (klass is not defined anywhere 480 {
544 // and nothing is known about the constructor arguments) :) 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
545 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 493 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
546 { 494 {
547 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9); 495 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
548 } 496 }
549 497
550 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 498 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
551 { 499 {
552 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9); 500 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
553 } 501 }
554}; 502};
555 503
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> 504template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
578class callback10 505struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
579{ 506{
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); 507 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
583 508
584 klass *o; 509private:
585 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
586 510
587public: 511 void *self;
512 ptr_type func;
513
514protected:
515
516 template<typename method>
517 struct thunktype;
518
588 template<class O1, class O2> 519 template<class klass>
589 explicit callback10 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) 520 struct thunktype<R (klass::*)>
590 { 521 {
591 o = reinterpret_cast<klass *>(object); 522 typedef klass K;
592 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>(method);
593 } 523 };
594 524
595 // this works because a standards-compliant C++ compiler 525 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
596 // basically can't help it: it doesn't have the knowledge 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)
597 // required to miscompile (klass is not defined anywhere 527 {
598 // and nothing is known about the constructor arguments) :) 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
599 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 540 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
600 { 541 {
601 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 542 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
602 } 543 }
603 544
604 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 545 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
605 { 546 {
606 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 547 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
607 } 548 }
608}; 549};
609 550
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 }
642};
643 551
644#endif 552#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines