]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - tools/create_templates.pl
Release v2.0.23
[user/henk/code/inspircd.git] / tools / create_templates.pl
1 #!/usr/bin/perl
2
3 #
4 # InspIRCd -- Internet Relay Chat Daemon
5 #
6 #   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
7 #
8 # This file is part of InspIRCd.  InspIRCd is free software: you can
9 # redistribute it and/or modify it under the terms of the GNU General Public
10 # License as published by the Free Software Foundation, version 2.
11 #
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15 # details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21
22 use strict;
23 use warnings;
24
25 my $maxparams = shift;
26
27 die "You must supply a number of parameters to generate headers allowing for!" unless(defined $maxparams);
28 die "You must request a non-negative parameter limit!" unless($maxparams >= 0);
29
30 print STDERR "Generating headerfile for a maximium of $maxparams parameters\n";
31
32 # First generate the HanderBase family
33
34 my @templatetypes = ('ReturnType');
35 for(my $i = 0; $i <= $maxparams; $i++)
36 {
37         push @templatetypes, "Param" . $i if($i > 0);
38         print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport HandlerBase" . $i . "\n";
39         print "{\n";
40         print " public:\n";
41         print " virtual ReturnType Call(" . join(', ', @templatetypes[1..$#templatetypes]) . ") = 0;\n";
42         print " virtual ~HandlerBase" . $i . "() { }\n";
43         print "};\n\n";
44 }
45
46 # And now the caller family
47
48 print "template <typename HandlerType> class caller\n";
49 print "{\n";
50 print " public:\n";
51 print " HandlerType* target;\n\n";
52 print " caller(HandlerType* initial)\n";
53 print " : target(initial)\n";
54 print " { }\n\n";
55 print " virtual ~caller() { }\n\n";
56 print " caller& operator=(HandlerType* newtarget)\n";
57 print " {\n";
58 print "         target = newtarget;\n";
59 print "         return *this;\n";
60 print " }\n";
61 print "};\n\n";
62
63
64
65
66 @templatetypes = ('ReturnType');
67 for(my $i = 0; $i <= $maxparams; $i++)
68 {
69         push @templatetypes, "Param" . $i if($i > 0);
70         
71         my $handlertype = "HandlerBase" . $i . "<" . join(', ', @templatetypes) . ">";
72         my @templatetypepairs = map { $_ . " " . lc($_) }  @templatetypes;
73         my @lctemplatetypes = map(lc, @templatetypes);
74         
75         print "template <typename " . join(', typename ', @templatetypes) . "> class caller" . $i . " : public caller< " . $handlertype . " >\n";
76         print "{\n";
77         print " public:\n";
78         print " caller" . $i . "(" . $handlertype . "* initial)\n";
79         print " : caller< " . $handlertype. " >::caller(initial)\n";
80         print " { }\n\n";
81         print " ReturnType operator() (" . join(', ', @templatetypepairs[1..$#templatetypepairs]) . ")\n";
82         print " {\n";
83         print "         return this->target->Call(" . join(', ', @lctemplatetypes[1..$#lctemplatetypes]) . ");\n";
84         print " }\n";
85         print "};\n\n";
86 }
87