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.15 by pcg, Thu Aug 7 17:54:26 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines