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.14 by root, Thu May 22 18:54:32 2014 UTC

2// THIS IS A GENERATED FILE: callback.pl is part of the GVPE 2// THIS IS A GENERATED FILE: callback.pl is part of the GVPE
3// THIS IS A GENERATED FILE: distribution. 3// THIS IS A GENERATED FILE: distribution.
4 4
5/* 5/*
6 callback.h -- C++ callback mechanism 6 callback.h -- C++ callback mechanism
7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com> 7 Copyright (C) 2003-2007 Marc Lehmann <schmorp@schmorp.de>
8 8
9 This file is part of GVPE. 9 This file is part of GVPE.
10 10
11 GVPE is free software; you can redistribute it and/or modify 11 GVPE is free software; you can redistribute it and/or modify
12 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
13 the Free Software Foundation; either version 2 of the License, or 13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version. 14 (at your option) any later version.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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; 39 template<class K, R (K::*method)()>
45 R (klass::*m)(); 40 void set (K *object)
46
47public:
48 template<class O1, class O2>
49 explicit callback0 (O1 *object, R (O2::*method)())
50 { 41 {
51 o = reinterpret_cast<klass *>(object); 42 self = object;
52 m = reinterpret_cast<R (klass::*)()>(method); 43 func = thunk<K, method>;
53 } 44 }
54 45
55 // this works because a standards-compliant C++ compiler
56 // basically can't help it: it doesn't have the knowledge
57 // required to miscompile (klass is not defined anywhere
58 // and nothing is known about the constructor arguments) :)
59 R call() const 46 R call () const
60 { 47 {
61 return (o->*m) (); 48 return func (self);
62 } 49 }
63 50
64 R operator ()() const 51 R operator ()() const
65 { 52 {
66 return call (); 53 return call ();
67 } 54 }
68};
69 55
70template<class R> 56private:
71struct callback_funtype_trait0 57
72{ 58 void *self;
73 static const int arity = 0; 59 ptr_type func;
74 typedef R type (void); 60
75 typedef R result_type; 61 template<class klass, R (klass::*method)()>
62 static R thunk (void *self)
76 63 {
64 klass *obj = static_cast<klass *>(self);
65 return (obj->*method) ();
66 }
77}; 67};
78 68
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> 69template<class R, class A1>
92class callback1 70struct callback<R (A1)>
93{ 71{
94 struct klass; // it is vital that this is never defined 72 typedef R (*ptr_type)(void *self, A1);
95 73
96 typedef R (klass::*ptr_type)(A1); 74 template<class K, R (K::*method)(A1)>
97 75 void set (K *object)
98 klass *o;
99 R (klass::*m)(A1);
100
101public:
102 template<class O1, class O2>
103 explicit callback1 (O1 *object, R (O2::*method)(A1))
104 { 76 {
105 o = reinterpret_cast<klass *>(object); 77 self = object;
106 m = reinterpret_cast<R (klass::*)(A1)>(method); 78 func = thunk<K, method>;
107 } 79 }
108 80
109 // this works because a standards-compliant C++ compiler
110 // basically can't help it: it doesn't have the knowledge
111 // required to miscompile (klass is not defined anywhere
112 // and nothing is known about the constructor arguments) :)
113 R call(A1 a1) const 81 R call (A1 a1) const
114 { 82 {
115 return (o->*m) (a1); 83 return func (self, a1);
116 } 84 }
117 85
118 R operator ()(A1 a1) const 86 R operator ()(A1 a1) const
119 { 87 {
120 return call (a1); 88 return call (a1);
121 } 89 }
122};
123 90
124template<class R, class A1> 91private:
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 92
133template<class R, class A1> 93 void *self;
134struct callback_funtype_trait<R (A1)> : callback_funtype_trait1<R, A1> 94 ptr_type func;
135{
136};
137 95
138template<class signature> 96 template<class klass, R (klass::*method)(A1)>
139struct callback_get_impl<1, signature> 97 static R thunk (void *self, A1 a1)
140{ 98 {
141 typedef callback_funtype_trait<signature> T; 99 klass *obj = static_cast<klass *>(self);
142 typedef callback1<typename T::result_type, typename T::arg1_type> type; 100 return (obj->*method) (a1);
101 }
143}; 102};
144 103
145template<class R, class A1, class A2> 104template<class R, class A1, class A2>
146class callback2 105struct callback<R (A1, A2)>
147{ 106{
148 struct klass; // it is vital that this is never defined
149
150 typedef R (klass::*ptr_type)(A1, A2); 107 typedef R (*ptr_type)(void *self, A1, A2);
151 108
152 klass *o; 109 template<class K, R (K::*method)(A1, A2)>
153 R (klass::*m)(A1, A2); 110 void set (K *object)
154
155public:
156 template<class O1, class O2>
157 explicit callback2 (O1 *object, R (O2::*method)(A1, A2))
158 { 111 {
159 o = reinterpret_cast<klass *>(object); 112 self = object;
160 m = reinterpret_cast<R (klass::*)(A1, A2)>(method); 113 func = thunk<K, method>;
161 } 114 }
162 115
163 // this works because a standards-compliant C++ compiler
164 // basically can't help it: it doesn't have the knowledge
165 // required to miscompile (klass is not defined anywhere
166 // and nothing is known about the constructor arguments) :)
167 R call(A1 a1, A2 a2) const 116 R call (A1 a1, A2 a2) const
168 { 117 {
169 return (o->*m) (a1, a2); 118 return func (self, a1, a2);
170 } 119 }
171 120
172 R operator ()(A1 a1, A2 a2) const 121 R operator ()(A1 a1, A2 a2) const
173 { 122 {
174 return call (a1, a2); 123 return call (a1, a2);
175 } 124 }
176};
177 125
178template<class R, class A1, class A2> 126private:
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 127
187template<class R, class A1, class A2> 128 void *self;
188struct callback_funtype_trait<R (A1, A2)> : callback_funtype_trait2<R, A1, A2> 129 ptr_type func;
189{
190};
191 130
192template<class signature> 131 template<class klass, R (klass::*method)(A1, A2)>
193struct callback_get_impl<2, signature> 132 static R thunk (void *self, A1 a1, A2 a2)
194{ 133 {
195 typedef callback_funtype_trait<signature> T; 134 klass *obj = static_cast<klass *>(self);
196 typedef callback2<typename T::result_type, typename T::arg1_type, typename T::arg2_type> type; 135 return (obj->*method) (a1, a2);
136 }
197}; 137};
198 138
199template<class R, class A1, class A2, class A3> 139template<class R, class A1, class A2, class A3>
200class callback3 140struct callback<R (A1, A2, A3)>
201{ 141{
202 struct klass; // it is vital that this is never defined
203
204 typedef R (klass::*ptr_type)(A1, A2, A3); 142 typedef R (*ptr_type)(void *self, A1, A2, A3);
205 143
206 klass *o; 144 template<class K, R (K::*method)(A1, A2, A3)>
207 R (klass::*m)(A1, A2, A3); 145 void set (K *object)
208
209public:
210 template<class O1, class O2>
211 explicit callback3 (O1 *object, R (O2::*method)(A1, A2, A3))
212 { 146 {
213 o = reinterpret_cast<klass *>(object); 147 self = object;
214 m = reinterpret_cast<R (klass::*)(A1, A2, A3)>(method); 148 func = thunk<K, method>;
215 } 149 }
216 150
217 // this works because a standards-compliant C++ compiler
218 // basically can't help it: it doesn't have the knowledge
219 // required to miscompile (klass is not defined anywhere
220 // and nothing is known about the constructor arguments) :)
221 R call(A1 a1, A2 a2, A3 a3) const 151 R call (A1 a1, A2 a2, A3 a3) const
222 { 152 {
223 return (o->*m) (a1, a2, a3); 153 return func (self, a1, a2, a3);
224 } 154 }
225 155
226 R operator ()(A1 a1, A2 a2, A3 a3) const 156 R operator ()(A1 a1, A2 a2, A3 a3) const
227 { 157 {
228 return call (a1, a2, a3); 158 return call (a1, a2, a3);
229 } 159 }
230};
231 160
232template<class R, class A1, class A2, class A3> 161private:
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 162
241template<class R, class A1, class A2, class A3> 163 void *self;
242struct callback_funtype_trait<R (A1, A2, A3)> : callback_funtype_trait3<R, A1, A2, A3> 164 ptr_type func;
243{
244};
245 165
246template<class signature> 166 template<class klass, R (klass::*method)(A1, A2, A3)>
247struct callback_get_impl<3, signature> 167 static R thunk (void *self, A1 a1, A2 a2, A3 a3)
248{ 168 {
249 typedef callback_funtype_trait<signature> T; 169 klass *obj = static_cast<klass *>(self);
250 typedef callback3<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type> type; 170 return (obj->*method) (a1, a2, a3);
171 }
251}; 172};
252 173
253template<class R, class A1, class A2, class A3, class A4> 174template<class R, class A1, class A2, class A3, class A4>
254class callback4 175struct callback<R (A1, A2, A3, A4)>
255{ 176{
256 struct klass; // it is vital that this is never defined
257
258 typedef R (klass::*ptr_type)(A1, A2, A3, A4); 177 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
259 178
260 klass *o; 179 template<class K, R (K::*method)(A1, A2, A3, A4)>
261 R (klass::*m)(A1, A2, A3, A4); 180 void set (K *object)
262
263public:
264 template<class O1, class O2>
265 explicit callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4))
266 { 181 {
267 o = reinterpret_cast<klass *>(object); 182 self = object;
268 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4)>(method); 183 func = thunk<K, method>;
269 } 184 }
270 185
271 // this works because a standards-compliant C++ compiler
272 // basically can't help it: it doesn't have the knowledge
273 // required to miscompile (klass is not defined anywhere
274 // and nothing is known about the constructor arguments) :)
275 R call(A1 a1, A2 a2, A3 a3, A4 a4) const 186 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
276 { 187 {
277 return (o->*m) (a1, a2, a3, a4); 188 return func (self, a1, a2, a3, a4);
278 } 189 }
279 190
280 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const 191 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
281 { 192 {
282 return call (a1, a2, a3, a4); 193 return call (a1, a2, a3, a4);
283 } 194 }
284};
285 195
286template<class R, class A1, class A2, class A3, class A4> 196private:
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 197
295template<class R, class A1, class A2, class A3, class A4> 198 void *self;
296struct callback_funtype_trait<R (A1, A2, A3, A4)> : callback_funtype_trait4<R, A1, A2, A3, A4> 199 ptr_type func;
297{
298};
299 200
300template<class signature> 201 template<class klass, R (klass::*method)(A1, A2, A3, A4)>
301struct callback_get_impl<4, signature> 202 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4)
302{ 203 {
303 typedef callback_funtype_trait<signature> T; 204 klass *obj = static_cast<klass *>(self);
304 typedef callback4<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type> type; 205 return (obj->*method) (a1, a2, a3, a4);
206 }
305}; 207};
306 208
307template<class R, class A1, class A2, class A3, class A4, class A5> 209template<class R, class A1, class A2, class A3, class A4, class A5>
308class callback5 210struct callback<R (A1, A2, A3, A4, A5)>
309{ 211{
310 struct klass; // it is vital that this is never defined
311
312 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5); 212 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
313 213
314 klass *o; 214 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
315 R (klass::*m)(A1, A2, A3, A4, A5); 215 void set (K *object)
316
317public:
318 template<class O1, class O2>
319 explicit callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5))
320 { 216 {
321 o = reinterpret_cast<klass *>(object); 217 self = object;
322 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5)>(method); 218 func = thunk<K, method>;
323 } 219 }
324 220
325 // this works because a standards-compliant C++ compiler
326 // basically can't help it: it doesn't have the knowledge
327 // required to miscompile (klass is not defined anywhere
328 // and nothing is known about the constructor arguments) :)
329 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 221 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
330 { 222 {
331 return (o->*m) (a1, a2, a3, a4, a5); 223 return func (self, a1, a2, a3, a4, a5);
332 } 224 }
333 225
334 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 226 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
335 { 227 {
336 return call (a1, a2, a3, a4, a5); 228 return call (a1, a2, a3, a4, a5);
337 } 229 }
338};
339 230
340template<class R, class A1, class A2, class A3, class A4, class A5> 231private:
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 232
349template<class R, class A1, class A2, class A3, class A4, class A5> 233 void *self;
350struct callback_funtype_trait<R (A1, A2, A3, A4, A5)> : callback_funtype_trait5<R, A1, A2, A3, A4, A5> 234 ptr_type func;
351{
352};
353 235
354template<class signature> 236 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5)>
355struct callback_get_impl<5, signature> 237 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
356{ 238 {
357 typedef callback_funtype_trait<signature> T; 239 klass *obj = static_cast<klass *>(self);
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; 240 return (obj->*method) (a1, a2, a3, a4, a5);
241 }
359}; 242};
360 243
361template<class R, class A1, class A2, class A3, class A4, class A5, class A6> 244template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
362class callback6 245struct callback<R (A1, A2, A3, A4, A5, A6)>
363{ 246{
364 struct klass; // it is vital that this is never defined
365
366 typedef R (klass::*ptr_type)(A1, A2, A3, A4, A5, A6); 247 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
367 248
368 klass *o; 249 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
369 R (klass::*m)(A1, A2, A3, A4, A5, A6); 250 void set (K *object)
370
371public:
372 template<class O1, class O2>
373 explicit callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6))
374 { 251 {
375 o = reinterpret_cast<klass *>(object); 252 self = object;
376 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6)>(method); 253 func = thunk<K, method>;
377 } 254 }
378 255
379 // this works because a standards-compliant C++ compiler
380 // basically can't help it: it doesn't have the knowledge
381 // required to miscompile (klass is not defined anywhere
382 // and nothing is known about the constructor arguments) :)
383 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 256 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
384 { 257 {
385 return (o->*m) (a1, a2, a3, a4, a5, a6); 258 return func (self, a1, a2, a3, a4, a5, a6);
386 } 259 }
387 260
388 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 261 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
389 { 262 {
390 return call (a1, a2, a3, a4, a5, a6); 263 return call (a1, a2, a3, a4, a5, a6);
391 } 264 }
392};
393 265
394template<class R, class A1, class A2, class A3, class A4, class A5, class A6> 266private:
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 267
403template<class R, class A1, class A2, class A3, class A4, class A5, class A6> 268 void *self;
404struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6)> : callback_funtype_trait6<R, A1, A2, A3, A4, A5, A6> 269 ptr_type func;
405{
406};
407 270
408template<class signature> 271 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6)>
409struct callback_get_impl<6, signature> 272 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
410{ 273 {
411 typedef callback_funtype_trait<signature> T; 274 klass *obj = static_cast<klass *>(self);
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; 275 return (obj->*method) (a1, a2, a3, a4, a5, a6);
276 }
413}; 277};
414 278
415template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> 279template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
416class callback7 280struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
417{ 281{
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); 282 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
421 283
422 klass *o; 284 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
423 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7); 285 void set (K *object)
424
425public:
426 template<class O1, class O2>
427 explicit callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7))
428 { 286 {
429 o = reinterpret_cast<klass *>(object); 287 self = object;
430 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7)>(method); 288 func = thunk<K, method>;
431 } 289 }
432 290
433 // this works because a standards-compliant C++ compiler
434 // basically can't help it: it doesn't have the knowledge
435 // required to miscompile (klass is not defined anywhere
436 // and nothing is known about the constructor arguments) :)
437 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 291 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
438 { 292 {
439 return (o->*m) (a1, a2, a3, a4, a5, a6, a7); 293 return func (self, a1, a2, a3, a4, a5, a6, a7);
440 } 294 }
441 295
442 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 296 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
443 { 297 {
444 return call (a1, a2, a3, a4, a5, a6, a7); 298 return call (a1, a2, a3, a4, a5, a6, a7);
445 } 299 }
446};
447 300
448template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> 301private:
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 302
457template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> 303 void *self;
458struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7)> : callback_funtype_trait7<R, A1, A2, A3, A4, A5, A6, A7> 304 ptr_type func;
459{
460};
461 305
462template<class signature> 306 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7)>
463struct callback_get_impl<7, signature> 307 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
464{ 308 {
465 typedef callback_funtype_trait<signature> T; 309 klass *obj = static_cast<klass *>(self);
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; 310 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7);
311 }
467}; 312};
468 313
469template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 314template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
470class callback8 315struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
471{ 316{
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); 317 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
475 318
476 klass *o; 319 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
477 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8); 320 void set (K *object)
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 { 321 {
483 o = reinterpret_cast<klass *>(object); 322 self = object;
484 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8)>(method); 323 func = thunk<K, method>;
485 } 324 }
486 325
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 326 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
492 { 327 {
493 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8); 328 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
494 } 329 }
495 330
496 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 331 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
497 { 332 {
498 return call (a1, a2, a3, a4, a5, a6, a7, a8); 333 return call (a1, a2, a3, a4, a5, a6, a7, a8);
499 } 334 }
500};
501 335
502template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 336private:
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 337
511template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 338 void *self;
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> 339 ptr_type func;
513{
514};
515 340
516template<class signature> 341 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
517struct callback_get_impl<8, signature> 342 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
518{ 343 {
519 typedef callback_funtype_trait<signature> T; 344 klass *obj = static_cast<klass *>(self);
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; 345 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8);
346 }
521}; 347};
522 348
523template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 349template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
524class callback9 350struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
525{ 351{
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); 352 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
529 353
530 klass *o;
531 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9); 354 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
532 355 void set (K *object)
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 { 356 {
537 o = reinterpret_cast<klass *>(object); 357 self = object;
538 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>(method); 358 func = thunk<K, method>;
539 } 359 }
540 360
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 361 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
546 { 362 {
547 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9); 363 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
548 } 364 }
549 365
550 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 366 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
551 { 367 {
552 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9); 368 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
553 } 369 }
554};
555 370
556template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 371private:
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 372
565template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 373 void *self;
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> 374 ptr_type func;
567{
568};
569 375
570template<class signature> 376 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
571struct callback_get_impl<9, signature> 377 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
572{ 378 {
573 typedef callback_funtype_trait<signature> T; 379 klass *obj = static_cast<klass *>(self);
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; 380 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
381 }
575}; 382};
576 383
577template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 384template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
578class callback10 385struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
579{ 386{
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); 387 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
583 388
584 klass *o;
585 R (klass::*m)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); 389 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
586 390 void set (K *object)
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 { 391 {
591 o = reinterpret_cast<klass *>(object); 392 self = object;
592 m = reinterpret_cast<R (klass::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>(method); 393 func = thunk<K, method>;
593 } 394 }
594 395
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 396 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
600 { 397 {
601 return (o->*m) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 398 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
602 } 399 }
603 400
604 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 401 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
605 { 402 {
606 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 403 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
607 } 404 }
608};
609 405
610template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 406private:
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 407
619template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 408 void *self;
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> 409 ptr_type func;
621{
622};
623 410
624template<class signature> 411 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
625struct callback_get_impl<10, signature> 412 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)
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 { 413 {
414 klass *obj = static_cast<klass *>(self);
415 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
641 } 416 }
642}; 417};
418
643 419
644#endif 420#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines