ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/callback.h
(Generate patch)

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines