1 |
#!/usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
|
5 |
print <<EOF; |
6 |
// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it |
7 |
// THIS IS A GENERATED FILE: callback.pl is part of the GVPE |
8 |
// THIS IS A GENERATED FILE: distribution. |
9 |
|
10 |
/* |
11 |
* callback.h -- C++ callback mechanism |
12 |
* Copyright (C) 2003-2008 Marc Lehmann <pcg\@goof.com> |
13 |
* |
14 |
* This file is part of GVPE. |
15 |
* |
16 |
* This program is free software; you can redistribute it and/or modify it |
17 |
* under the terms of the GNU General Public License as published by the |
18 |
* Free Software Foundation; either version 3 of the License, or (at your |
19 |
* option) any later version. |
20 |
* |
21 |
* This program is distributed in the hope that it will be useful, but |
22 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
24 |
* Public License for more details. |
25 |
* |
26 |
* You should have received a copy of the GNU General Public License along |
27 |
* with this program; if not, see <http://www.gnu.org/licenses/>. |
28 |
* |
29 |
* Additional permission under GNU GPL version 3 section 7 |
30 |
* |
31 |
* If you modify this Program, or any covered work, by linking or |
32 |
* combining it with the OpenSSL project's OpenSSL library (or a modified |
33 |
* version of that library), containing parts covered by the terms of the |
34 |
* OpenSSL or SSLeay licenses, the licensors of this Program grant you |
35 |
* additional permission to convey the resulting work. Corresponding |
36 |
* Source for a non-source form of such a combination shall include the |
37 |
* source code for the parts of OpenSSL used as well as that of the |
38 |
* covered work. |
39 |
*/ |
40 |
|
41 |
#ifndef CALLBACK_H__ |
42 |
#define CALLBACK_H__ |
43 |
|
44 |
#define CALLBACK_H_VERSION 3 |
45 |
|
46 |
template<typename signature> |
47 |
struct callback; |
48 |
|
49 |
EOF |
50 |
|
51 |
for my $a (0..10) { |
52 |
my $CLASS = join "", map ", class A$_", 1..$a; |
53 |
my $TYPE = join ", ", map "A$_", 1..$a; |
54 |
my $ARG = join ", ", map "a$_", 1..$a; |
55 |
my $TYPEARG = join ", ", map "A$_ a$_", 1..$a; |
56 |
my $TYPEDEFS = join " ", map "typedef A$_ arg$_\_type;", 1..$a; |
57 |
my $TYPEvoid = $TYPE ? $TYPE : "void"; |
58 |
my $_ARG = $ARG ? ", $ARG" : ""; |
59 |
my $_TYPE = $TYPE ? ", $TYPE" : ""; |
60 |
my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : ""; |
61 |
my $_TTYPE = $a ? join "", map ", typename T::arg$_\_type", 1..$a : ""; |
62 |
|
63 |
print <<EOF; |
64 |
template<class R$CLASS> |
65 |
struct callback<R ($TYPE)> |
66 |
{ |
67 |
typedef R (*ptr_type)(void *self$_TYPE); |
68 |
|
69 |
template<class K, R (K::*method)($TYPE)> |
70 |
void set (K *object) |
71 |
{ |
72 |
self = object; |
73 |
func = thunk<K, method>; |
74 |
} |
75 |
|
76 |
R call ($TYPEARG) const |
77 |
{ |
78 |
return func (self$_ARG); |
79 |
} |
80 |
|
81 |
R operator ()($TYPEARG) const |
82 |
{ |
83 |
return call ($ARG); |
84 |
} |
85 |
|
86 |
private: |
87 |
|
88 |
void *self; |
89 |
ptr_type func; |
90 |
|
91 |
template<class klass, R (klass::*method)($TYPE)> |
92 |
static R thunk (void *self$_TYPEARG) |
93 |
{ |
94 |
klass *obj = static_cast<klass *>(self); |
95 |
return (obj->*method) ($ARG); |
96 |
} |
97 |
}; |
98 |
|
99 |
EOF |
100 |
} |
101 |
|
102 |
print <<EOF |
103 |
|
104 |
#endif |
105 |
EOF |
106 |
|