1 |
#!/usr/bin/perl |
2 |
|
3 |
print <<EOF; |
4 |
// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it |
5 |
// THIS IS A GENERATED FILE: callback.pl is part of the GVPE |
6 |
// THIS IS A GENERATED FILE: distribution. |
7 |
|
8 |
/* |
9 |
callback.h -- C++ callback mechanism |
10 |
Copyright (C) 2003-2005 Marc Lehmann <pcg\@goof.com> |
11 |
|
12 |
This file is part of GVPE. |
13 |
|
14 |
GVPE is free software; you can redistribute it and/or modify |
15 |
it under the terms of the GNU General Public License as published by |
16 |
the Free Software Foundation; either version 2 of the License, or |
17 |
(at your option) any later version. |
18 |
|
19 |
This program is distributed in the hope that it will be useful, |
20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 |
GNU General Public License for more details. |
23 |
|
24 |
You should have received a copy of the GNU General Public License |
25 |
along with gvpe; if not, write to the Free Software |
26 |
Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
27 |
*/ |
28 |
|
29 |
#ifndef CALLBACK_H__ |
30 |
#define CALLBACK_H__ |
31 |
|
32 |
EOF |
33 |
|
34 |
for my $a (0..7) { |
35 |
my $CLASS = join "", map ", class A$_", 1..$a; |
36 |
my $TYPE = join ", ", map "A$_", 1..$a; |
37 |
my $ARG = join ", ", map "a$_", 1..$a; |
38 |
my $TYPEARG = join ", ", map "A$_ a$_", 1..$a; |
39 |
my $_ARG = $ARG ? ", $ARG" : ""; |
40 |
my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : ""; |
41 |
|
42 |
print <<EOF; |
43 |
template<class R$CLASS> |
44 |
class callback$a { |
45 |
struct object { }; |
46 |
|
47 |
void *obj; |
48 |
R (object::*meth)($TYPE); |
49 |
|
50 |
/* a proxy is a kind of recipe on how to call a specific class method */ |
51 |
struct proxy_base { |
52 |
virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) = 0; |
53 |
}; |
54 |
template<class O1, class O2> |
55 |
struct proxy : proxy_base { |
56 |
virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) |
57 |
{ |
58 |
((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)($TYPE)>(meth))) |
59 |
($ARG); |
60 |
} |
61 |
}; |
62 |
|
63 |
proxy_base *prxy; |
64 |
|
65 |
public: |
66 |
template<class O1, class O2> |
67 |
callback$a (O1 *object, R (O2::*method)($TYPE)) |
68 |
{ |
69 |
static proxy<O1,O2> p; |
70 |
obj = reinterpret_cast<void *>(object); |
71 |
meth = reinterpret_cast<R (object::*)($TYPE)>(method); |
72 |
prxy = &p; |
73 |
} |
74 |
|
75 |
R call($TYPEARG) const |
76 |
{ |
77 |
return prxy->call (obj, meth$_ARG); |
78 |
} |
79 |
|
80 |
R operator ()($TYPEARG) const |
81 |
{ |
82 |
return call ($ARG); |
83 |
} |
84 |
}; |
85 |
|
86 |
EOF |
87 |
} |
88 |
|
89 |
print <<EOF |
90 |
#endif |
91 |
EOF |
92 |
|