ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.pl
Revision: 1.6
Committed: Tue Nov 29 19:21:09 2005 UTC (18 years, 5 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_0
Changes since 1.5: +4 -7 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 #!/usr/bin/perl
2    
3     print <<EOF;
4 pcg 1.6 // 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 pcg 1.1
8     /*
9     callback.h -- C++ callback mechanism
10 pcg 1.6 Copyright (C) 2003-2005 Marc Lehmann <pcg\@goof.com>
11 pcg 1.1
12 pcg 1.4 This file is part of GVPE.
13    
14     GVPE is free software; you can redistribute it and/or modify
15 pcg 1.1 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 pcg 1.4 along with gvpe; if not, write to the Free Software
26 pcg 1.5 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 pcg 1.1 */
28    
29 pcg 1.3 #ifndef CALLBACK_H__
30     #define CALLBACK_H__
31 pcg 1.1
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