ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.pl
Revision: 1.5
Committed: Tue Apr 26 00:55:55 2005 UTC (19 years, 1 month ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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