|
|
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 | |
1 | /* |
5 | /* |
2 | callback.h -- C++ callback mechanism |
6 | * callback.h -- C++ callback mechanism |
3 | |
7 | * Copyright (C) 2003-2008 Marc Lehmann <pcg@goof.com> |
|
|
8 | * |
|
|
9 | * This file is part of GVPE. |
|
|
10 | * |
4 | This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify it |
5 | 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 |
6 | the Free Software Foundation; either version 2 of the License, or |
13 | * Free Software Foundation; either version 3 of the License, or (at your |
7 | (at your option) any later version. |
14 | * option) any later version. |
8 | |
15 | * |
9 | 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 |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
12 | GNU General Public License for more details. |
19 | * Public License for more details. |
13 | |
20 | * |
14 | 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 |
15 | along with this program; if not, write to the Free Software |
22 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 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. |
17 | */ |
34 | */ |
18 | |
35 | |
19 | #ifndef VPE_CALLBACK_H__ |
36 | #ifndef CALLBACK_H__ |
20 | #define VPE_CALLBACK_H__ |
37 | #define CALLBACK_H__ |
21 | |
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 | |
22 | template<class R, class A> |
79 | template<class R, class A1> |
23 | class callback { |
80 | struct callback<R (A1)> |
24 | struct object { }; |
81 | { |
|
|
82 | typedef R (*ptr_type)(void *self, A1); |
25 | |
83 | |
26 | void *obj; |
84 | template<class K, R (K::*method)(A1)> |
27 | R (object::*meth)(A arg); |
85 | void set (K *object) |
28 | |
86 | { |
29 | // a proxy is a kind of recipe on how to call a specific class method |
87 | self = object; |
30 | struct proxy_base { |
88 | func = thunk<K, method>; |
31 | virtual R call (void *obj, R (object::*meth)(A), A arg) = 0; |
|
|
32 | }; |
89 | } |
33 | template<class O1, class O2> |
|
|
34 | struct proxy : proxy_base { |
|
|
35 | virtual R call (void *obj, R (object::*meth)(A), A arg) |
|
|
36 | { |
|
|
37 | ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A)>(meth))) |
|
|
38 | (arg); |
|
|
39 | } |
|
|
40 | }; |
|
|
41 | |
90 | |
42 | proxy_base *prxy; |
|
|
43 | |
|
|
44 | public: |
|
|
45 | template<class O1, class O2> |
|
|
46 | callback (O1 *object, R (O2::*method)(A)) |
|
|
47 | { |
|
|
48 | static proxy<O1,O2> p; |
|
|
49 | obj = reinterpret_cast<void *>(object); |
|
|
50 | meth = reinterpret_cast<R (object::*)(A)>(method); |
|
|
51 | prxy = &p; |
|
|
52 | } |
|
|
53 | |
|
|
54 | R call(A arg) const |
91 | R call (A1 a1) const |
55 | { |
92 | { |
56 | return prxy->call (obj, meth, arg); |
93 | return func (self, a1); |
57 | } |
94 | } |
58 | |
95 | |
59 | R operator ()(A arg) const |
96 | R operator ()(A1 a1) const |
60 | { |
97 | { |
61 | return call (arg); |
98 | return call (a1); |
62 | } |
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 | } |
63 | }; |
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 | |
64 | |
429 | |
65 | #endif |
430 | #endif |
66 | |
|
|