ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.h
Revision: 1.15
Committed: Thu Aug 7 17:54:26 2008 UTC (15 years, 10 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_0, rel-2_2, rel-2_21, rel-2_22, rel-2_25
Changes since 1.14: +28 -18 lines
Log Message:
update to gplv3, finally

File Contents

# Content
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
3 // THIS IS A GENERATED FILE: distribution.
4
5 /*
6 * callback.h -- C++ callback mechanism
7 * Copyright (C) 2003-2008 Marc Lehmann <pcg@goof.com>
8 *
9 * This file is part of GVPE.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 3 of the License, or (at your
14 * option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, see <http://www.gnu.org/licenses/>.
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.
34 */
35
36 #ifndef CALLBACK_H__
37 #define CALLBACK_H__
38
39 #define CALLBACK_H_VERSION 3
40
41 template<typename signature>
42 struct callback;
43
44 template<class R>
45 struct callback<R ()>
46 {
47 typedef R (*ptr_type)(void *self);
48
49 template<class K, R (K::*method)()>
50 void set (K *object)
51 {
52 self = object;
53 func = thunk<K, method>;
54 }
55
56 R call () const
57 {
58 return func (self);
59 }
60
61 R operator ()() const
62 {
63 return call ();
64 }
65
66 private:
67
68 void *self;
69 ptr_type func;
70
71 template<class klass, R (klass::*method)()>
72 static R thunk (void *self)
73 {
74 klass *obj = static_cast<klass *>(self);
75 return (obj->*method) ();
76 }
77 };
78
79 template<class R, class A1>
80 struct callback<R (A1)>
81 {
82 typedef R (*ptr_type)(void *self, A1);
83
84 template<class K, R (K::*method)(A1)>
85 void set (K *object)
86 {
87 self = object;
88 func = thunk<K, method>;
89 }
90
91 R call (A1 a1) const
92 {
93 return func (self, a1);
94 }
95
96 R operator ()(A1 a1) const
97 {
98 return call (a1);
99 }
100
101 private:
102
103 void *self;
104 ptr_type func;
105
106 template<class klass, R (klass::*method)(A1)>
107 static R thunk (void *self, A1 a1)
108 {
109 klass *obj = static_cast<klass *>(self);
110 return (obj->*method) (a1);
111 }
112 };
113
114 template<class R, class A1, class A2>
115 struct callback<R (A1, A2)>
116 {
117 typedef R (*ptr_type)(void *self, A1, A2);
118
119 template<class K, R (K::*method)(A1, A2)>
120 void set (K *object)
121 {
122 self = object;
123 func = thunk<K, method>;
124 }
125
126 R call (A1 a1, A2 a2) const
127 {
128 return func (self, a1, a2);
129 }
130
131 R operator ()(A1 a1, A2 a2) const
132 {
133 return call (a1, a2);
134 }
135
136 private:
137
138 void *self;
139 ptr_type func;
140
141 template<class klass, R (klass::*method)(A1, A2)>
142 static R thunk (void *self, A1 a1, A2 a2)
143 {
144 klass *obj = static_cast<klass *>(self);
145 return (obj->*method) (a1, a2);
146 }
147 };
148
149 template<class R, class A1, class A2, class A3>
150 struct callback<R (A1, A2, A3)>
151 {
152 typedef R (*ptr_type)(void *self, A1, A2, A3);
153
154 template<class K, R (K::*method)(A1, A2, A3)>
155 void set (K *object)
156 {
157 self = object;
158 func = thunk<K, method>;
159 }
160
161 R call (A1 a1, A2 a2, A3 a3) const
162 {
163 return func (self, a1, a2, a3);
164 }
165
166 R operator ()(A1 a1, A2 a2, A3 a3) const
167 {
168 return call (a1, a2, a3);
169 }
170
171 private:
172
173 void *self;
174 ptr_type func;
175
176 template<class klass, R (klass::*method)(A1, A2, A3)>
177 static R thunk (void *self, A1 a1, A2 a2, A3 a3)
178 {
179 klass *obj = static_cast<klass *>(self);
180 return (obj->*method) (a1, a2, a3);
181 }
182 };
183
184 template<class R, class A1, class A2, class A3, class A4>
185 struct callback<R (A1, A2, A3, A4)>
186 {
187 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
188
189 template<class K, R (K::*method)(A1, A2, A3, A4)>
190 void set (K *object)
191 {
192 self = object;
193 func = thunk<K, method>;
194 }
195
196 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
197 {
198 return func (self, a1, a2, a3, a4);
199 }
200
201 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
202 {
203 return call (a1, a2, a3, a4);
204 }
205
206 private:
207
208 void *self;
209 ptr_type func;
210
211 template<class klass, R (klass::*method)(A1, A2, A3, A4)>
212 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4)
213 {
214 klass *obj = static_cast<klass *>(self);
215 return (obj->*method) (a1, a2, a3, a4);
216 }
217 };
218
219 template<class R, class A1, class A2, class A3, class A4, class A5>
220 struct callback<R (A1, A2, A3, A4, A5)>
221 {
222 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
223
224 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
225 void set (K *object)
226 {
227 self = object;
228 func = thunk<K, method>;
229 }
230
231 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
232 {
233 return func (self, a1, a2, a3, a4, a5);
234 }
235
236 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
237 {
238 return call (a1, a2, a3, a4, a5);
239 }
240
241 private:
242
243 void *self;
244 ptr_type func;
245
246 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5)>
247 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
248 {
249 klass *obj = static_cast<klass *>(self);
250 return (obj->*method) (a1, a2, a3, a4, a5);
251 }
252 };
253
254 template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
255 struct callback<R (A1, A2, A3, A4, A5, A6)>
256 {
257 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
258
259 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
260 void set (K *object)
261 {
262 self = object;
263 func = thunk<K, method>;
264 }
265
266 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
267 {
268 return func (self, a1, a2, a3, a4, a5, a6);
269 }
270
271 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
272 {
273 return call (a1, a2, a3, a4, a5, a6);
274 }
275
276 private:
277
278 void *self;
279 ptr_type func;
280
281 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6)>
282 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
283 {
284 klass *obj = static_cast<klass *>(self);
285 return (obj->*method) (a1, a2, a3, a4, a5, a6);
286 }
287 };
288
289 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
290 struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
291 {
292 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
293
294 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
295 void set (K *object)
296 {
297 self = object;
298 func = thunk<K, method>;
299 }
300
301 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
302 {
303 return func (self, a1, a2, a3, a4, a5, a6, a7);
304 }
305
306 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
307 {
308 return call (a1, a2, a3, a4, a5, a6, a7);
309 }
310
311 private:
312
313 void *self;
314 ptr_type func;
315
316 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7)>
317 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
318 {
319 klass *obj = static_cast<klass *>(self);
320 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7);
321 }
322 };
323
324 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
325 struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
326 {
327 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
328
329 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
330 void set (K *object)
331 {
332 self = object;
333 func = thunk<K, method>;
334 }
335
336 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
337 {
338 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
339 }
340
341 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
342 {
343 return call (a1, a2, a3, a4, a5, a6, a7, a8);
344 }
345
346 private:
347
348 void *self;
349 ptr_type func;
350
351 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
352 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
353 {
354 klass *obj = static_cast<klass *>(self);
355 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8);
356 }
357 };
358
359 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
360 struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
361 {
362 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
363
364 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
365 void set (K *object)
366 {
367 self = object;
368 func = thunk<K, method>;
369 }
370
371 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
372 {
373 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
374 }
375
376 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
377 {
378 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
379 }
380
381 private:
382
383 void *self;
384 ptr_type func;
385
386 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
387 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
388 {
389 klass *obj = static_cast<klass *>(self);
390 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
391 }
392 };
393
394 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
395 struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
396 {
397 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
398
399 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
400 void set (K *object)
401 {
402 self = object;
403 func = thunk<K, method>;
404 }
405
406 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
407 {
408 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
409 }
410
411 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
412 {
413 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
414 }
415
416 private:
417
418 void *self;
419 ptr_type func;
420
421 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
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)
423 {
424 klass *obj = static_cast<klass *>(self);
425 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
426 }
427 };
428
429
430 #endif