diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-25 17:01:18 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-25 17:01:18 +0000 |
commit | d49e33b22c2cbb22bad71fb07ce8003dec8270cf (patch) | |
tree | 9e4c1d8eebe3a4383f9c5c48e662748a51382757 /tools | |
parent | f827df84032bafa4384acb21957456e3809bc3be (diff) |
Add template creation tool for caller classes
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7565 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/create_templates.pl | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tools/create_templates.pl b/tools/create_templates.pl new file mode 100755 index 000000000..e205cd050 --- /dev/null +++ b/tools/create_templates.pl @@ -0,0 +1,80 @@ +#!/usr/bin/perl + +# +------------------------------------+ +# | Inspire Internet Relay Chat Daemon | +# +------------------------------------+ +# +# InspIRCd: (C) 2002-2007 InspIRCd Development Team +# See: http://www.inspircd.org/wiki/index.php/Credits +# +# This program is free but copyrighted software; see +# the file COPYING for details. +# +# --------------------------------------------------- + +use strict; +use warnings; + +my $maxparams = shift; + +die "You must supply a number of parameters to generate headers allowing for!" unless(defined $maxparams); +die "You must request a non-negative parameter limit!" unless($maxparams >= 0); + +print STDERR "Generating headerfile for a maximium of $maxparams parameters\n"; + +# First generate the HanderBase family + +my @templatetypes = ('ReturnType'); +for(my $i = 0; $i <= $maxparams; $i++) +{ + push @templatetypes, "Param" . $i if($i > 0); + print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport HandlerBase" . $i . "\n"; + print "{\n"; + print " public:\n"; + print " virtual ReturnType Call(" . join(', ', @templatetypes[1..$#templatetypes]) . ") = 0;\n"; + print " virtual ~HandlerBase" . $i . "() { }\n"; + print "};\n\n"; +} + +# And now the caller family + +print "template <typename HandlerType> class CoreExport caller\n"; +print "{\n"; +print " public:\n"; +print " HandlerType* target;\n\n"; +print " caller(HandlerType* initial)\n"; +print " : target(initial)\n"; +print " { }\n\n"; +print " virtual ~caller() { }\n\n"; +print " caller& operator=(HandlerType* newtarget)\n"; +print " {\n"; +print " target = newtarget;\n"; +print " return *this;\n"; +print " }\n"; +print "};\n\n"; + + + + +@templatetypes = ('ReturnType'); +for(my $i = 0; $i <= $maxparams; $i++) +{ + push @templatetypes, "Param" . $i if($i > 0); + + my $handlertype = "HandlerBase" . $i . "<" . join(', ', @templatetypes) . ">"; + my @templatetypepairs = map { $_ . " " . lc($_) } @templatetypes; + my @lctemplatetypes = map(lc, @templatetypes); + + print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport caller" . $i . " : public caller< " . $handlertype . " >\n"; + print "{\n"; + print " public:\n"; + print " caller" . $i . "(" . $handlertype . "* initial)\n"; + print " : caller< " . $handlertype. " >::caller(initial)\n"; + print " { }\n\n"; + print " virtual ReturnType operator() (" . join(', ', @templatetypepairs[1..$#templatetypepairs]) . ")\n"; + print " {\n"; + print " return this->target->Call(" . join(', ', @lctemplatetypes[1..$#lctemplatetypes]) . ");\n"; + print " }\n"; + print "};\n\n"; +} + |