]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - tools/create_templates.pl
Update all wiki links to point to the new wiki. This was done automatically with...
[user/henk/code/inspircd.git] / tools / create_templates.pl
1 #!/usr/bin/perl
2
3 #       +------------------------------------+
4 #       | Inspire Internet Relay Chat Daemon |
5 #       +------------------------------------+
6 #
7 #  InspIRCd: (C) 2002-2009 InspIRCd Development Team
8 # See: http://wiki.inspircd.org/Credits
9 #
10 #  This program is free but copyrighted software; see
11 #          the file COPYING for details.
12 #
13 # ---------------------------------------------------
14
15 use strict;
16 use warnings;
17
18 my $maxparams = shift;
19
20 die "You must supply a number of parameters to generate headers allowing for!" unless(defined $maxparams);
21 die "You must request a non-negative parameter limit!" unless($maxparams >= 0);
22
23 print STDERR "Generating headerfile for a maximium of $maxparams parameters\n";
24
25 # First generate the HanderBase family
26
27 my @templatetypes = ('ReturnType');
28 for(my $i = 0; $i <= $maxparams; $i++)
29 {
30         push @templatetypes, "Param" . $i if($i > 0);
31         print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport HandlerBase" . $i . "\n";
32         print "{\n";
33         print " public:\n";
34         print " virtual ReturnType Call(" . join(', ', @templatetypes[1..$#templatetypes]) . ") = 0;\n";
35         print " virtual ~HandlerBase" . $i . "() { }\n";
36         print "};\n\n";
37 }
38
39 # And now the caller family
40
41 print "template <typename HandlerType> class CoreExport caller\n";
42 print "{\n";
43 print " public:\n";
44 print " HandlerType* target;\n\n";
45 print " caller(HandlerType* initial)\n";
46 print " : target(initial)\n";
47 print " { }\n\n";
48 print " virtual ~caller() { }\n\n";
49 print " caller& operator=(HandlerType* newtarget)\n";
50 print " {\n";
51 print "         target = newtarget;\n";
52 print "         return *this;\n";
53 print " }\n";
54 print "};\n\n";
55
56
57
58
59 @templatetypes = ('ReturnType');
60 for(my $i = 0; $i <= $maxparams; $i++)
61 {
62         push @templatetypes, "Param" . $i if($i > 0);
63         
64         my $handlertype = "HandlerBase" . $i . "<" . join(', ', @templatetypes) . ">";
65         my @templatetypepairs = map { $_ . " " . lc($_) }  @templatetypes;
66         my @lctemplatetypes = map(lc, @templatetypes);
67         
68         print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport caller" . $i . " : public caller< " . $handlertype . " >\n";
69         print "{\n";
70         print " public:\n";
71         print " caller" . $i . "(" . $handlertype . "* initial)\n";
72         print " : caller< " . $handlertype. " >::caller(initial)\n";
73         print " { }\n\n";
74         print " virtual ReturnType operator() (" . join(', ', @templatetypepairs[1..$#templatetypepairs]) . ")\n";
75         print " {\n";
76         print "         return this->target->Call(" . join(', ', @lctemplatetypes[1..$#lctemplatetypes]) . ");\n";
77         print " }\n";
78         print "};\n\n";
79 }
80