4 # InspIRCd -- Internet Relay Chat Daemon
6 # Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
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.
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
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/>.
25 my $maxparams = shift;
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);
30 print STDERR "Generating headerfile for a maximium of $maxparams parameters\n";
32 # First generate the HanderBase family
34 my @templatetypes = ('ReturnType');
35 for(my $i = 0; $i <= $maxparams; $i++)
37 push @templatetypes, "Param" . $i if($i > 0);
38 print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport HandlerBase" . $i . "\n";
41 print " virtual ReturnType Call(" . join(', ', @templatetypes[1..$#templatetypes]) . ") = 0;\n";
42 print " virtual ~HandlerBase" . $i . "() { }\n";
46 # And now the caller family
48 print "template <typename HandlerType> class caller\n";
51 print " HandlerType* target;\n\n";
52 print " caller(HandlerType* initial)\n";
53 print " : target(initial)\n";
55 print " virtual ~caller() { }\n\n";
56 print " caller& operator=(HandlerType* newtarget)\n";
58 print " target = newtarget;\n";
59 print " return *this;\n";
66 @templatetypes = ('ReturnType');
67 for(my $i = 0; $i <= $maxparams; $i++)
69 push @templatetypes, "Param" . $i if($i > 0);
71 my $handlertype = "HandlerBase" . $i . "<" . join(', ', @templatetypes) . ">";
72 my @templatetypepairs = map { $_ . " " . lc($_) } @templatetypes;
73 my @lctemplatetypes = map(lc, @templatetypes);
75 print "template <typename " . join(', typename ', @templatetypes) . "> class caller" . $i . " : public caller< " . $handlertype . " >\n";
78 print " caller" . $i . "(" . $handlertype . "* initial)\n";
79 print " : caller< " . $handlertype. " >::caller(initial)\n";
81 print " ReturnType operator() (" . join(', ', @templatetypepairs[1..$#templatetypepairs]) . ")\n";
83 print " return this->target->Call(" . join(', ', @lctemplatetypes[1..$#lctemplatetypes]) . ");\n";