ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.pl
Revision: 1.15
Committed: Sun Nov 18 00:02:56 2018 UTC (5 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +0 -0 lines
State: FILE REMOVED
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 #!/usr/bin/perl
2    
3 pcg 1.10 use strict;
4    
5 pcg 1.1 print <<EOF;
6 pcg 1.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 pcg 1.1
10     /*
11 pcg 1.14 * 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 pcg 1.1 */
40    
41 pcg 1.3 #ifndef CALLBACK_H__
42     #define CALLBACK_H__
43 pcg 1.1
44 pcg 1.10 #define CALLBACK_H_VERSION 3
45 pcg 1.9
46 pcg 1.11 template<typename signature>
47     struct callback;
48 pcg 1.9
49 pcg 1.1 EOF
50    
51 pcg 1.9 for my $a (0..10) {
52 pcg 1.1 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 pcg 1.9 my $TYPEDEFS = join " ", map "typedef A$_ arg$_\_type;", 1..$a;
57     my $TYPEvoid = $TYPE ? $TYPE : "void";
58 pcg 1.11 my $_ARG = $ARG ? ", $ARG" : "";
59 pcg 1.9 my $_TYPE = $TYPE ? ", $TYPE" : "";
60 pcg 1.11 my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : "";
61 pcg 1.9 my $_TTYPE = $a ? join "", map ", typename T::arg$_\_type", 1..$a : "";
62 pcg 1.1
63     print <<EOF;
64     template<class R$CLASS>
65 pcg 1.11 struct callback<R ($TYPE)>
66 pcg 1.9 {
67 pcg 1.11 typedef R (*ptr_type)(void *self$_TYPE);
68 pcg 1.9
69 pcg 1.11 template<class K, R (K::*method)($TYPE)>
70     void set (K *object)
71 pcg 1.10 {
72 pcg 1.11 self = object;
73     func = thunk<K, method>;
74 pcg 1.10 }
75    
76 pcg 1.11 R call ($TYPEARG) const
77 pcg 1.10 {
78 pcg 1.11 return func (self$_ARG);
79 pcg 1.10 }
80 pcg 1.1
81     R operator ()($TYPEARG) const
82 pcg 1.10 {
83     return call ($ARG);
84     }
85 pcg 1.13
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 pcg 1.1 };
98    
99     EOF
100     }
101    
102     print <<EOF
103 pcg 1.9
104 pcg 1.1 #endif
105     EOF
106