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.15 by pcg, Thu Aug 7 17:54:26 2008 UTC vs.
Revision 1.16 by root, Sun Nov 18 00:02:56 2018 UTC

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/* 1/*
6 * callback.h -- C++ callback mechanism 2 * callback.h -- C++ callback mechanism
7 * Copyright (C) 2003-2008 Marc Lehmann <pcg@goof.com> 3 * Copyright (C) 2003-2018 Marc Lehmann <pcg@goof.com>
8 * 4 *
9 * This file is part of GVPE. 5 * This file is part of GVPE.
10 * 6 *
11 * This program is free software; you can redistribute it and/or modify it 7 * 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 8 * under the terms of the GNU General Public License as published by the
34*/ 30*/
35 31
36#ifndef CALLBACK_H__ 32#ifndef CALLBACK_H__
37#define CALLBACK_H__ 33#define CALLBACK_H__
38 34
39#define CALLBACK_H_VERSION 3 35#define CALLBACK_H_VERSION 4
40 36
41template<typename signature> 37template<typename signature>
42struct callback; 38struct callback;
43 39
44template<class R> 40template<class R, class ...Args>
45struct callback<R ()> 41struct callback<R (Args...)>
46{ 42{
47 typedef R (*ptr_type)(void *self); 43 typedef R (*ptr_type)(void *self, Args...);
48 44
49 template<class K, R (K::*method)()> 45 template<class K, R (K::*method)(Args...)>
50 void set (K *object) 46 void set (K *object)
51 { 47 {
52 self = object; 48 self = object;
53 func = thunk<K, method>; 49 func = thunk<K, method>;
54 } 50 }
55 51
56 R call () const 52 R call (Args... args) const
57 { 53 {
58 return func (self); 54 return func (self, args...);
59 } 55 }
60 56
61 R operator ()() const 57 R operator ()(Args... args) const
62 { 58 {
63 return call (); 59 return call (args...);
64 } 60 }
65 61
66private: 62private:
67 63
68 void *self; 64 void *self;
69 ptr_type func; 65 ptr_type func;
70 66
71 template<class klass, R (klass::*method)()> 67 template<class klass, R (klass::*method)(Args...)>
72 static R thunk (void *self) 68 static R thunk (void *self, Args... args)
73 { 69 {
74 klass *obj = static_cast<klass *>(self); 70 klass *obj = static_cast<klass *>(self);
75 return (obj->*method) (); 71 return (obj->*method) (args...);
76 } 72 }
77}; 73};
78 74
79template<class R, class A1>
80struct 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
101private:
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
114template<class R, class A1, class A2>
115struct 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
136private:
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
149template<class R, class A1, class A2, class A3>
150struct 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
171private:
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
184template<class R, class A1, class A2, class A3, class A4>
185struct 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
206private:
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
219template<class R, class A1, class A2, class A3, class A4, class A5>
220struct 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
241private:
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
254template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
255struct 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
276private:
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
289template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
290struct 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
311private:
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
324template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
325struct 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
346private:
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
359template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
360struct 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
381private:
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
394template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
395struct 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
416private:
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 75#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines