summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/caller.h76
-rwxr-xr-xtools/create_templates.pl87
2 files changed, 76 insertions, 87 deletions
diff --git a/include/caller.h b/include/caller.h
index 64b37611f..563577ac2 100644
--- a/include/caller.h
+++ b/include/caller.h
@@ -3,6 +3,7 @@
*
* Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
* Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
+ * Copyright (C) 2012 Adam <Adam@anope.org>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
@@ -21,6 +22,79 @@
#ifndef CALLER_H
#define CALLER_H
+/* Pending some sort of C++11 support */
+#if 0
+
+template<typename ReturnType, typename... Args> class CoreExport Handler : public classbase
+{
+ public:
+ virtual ~Handler() { }
+ virtual ReturnType Call(Args...) = 0;
+};
+
+template<typename ReturnType, typename... Args> class CoreExport Caller
+{
+ public:
+ Handler<ReturnType, Args...>* target;
+
+ Caller(Handler<ReturnType, Args...>* initial) : target(initial) { }
+ virtual ~Caller() { }
+
+ virtual ReturnType operator()(const Args&... params)
+ {
+ return this->target->Call(params...);
+ }
+};
+
+/* Below here is compat with the old API */
+#define HandlerBase0 Handler
+#define HandlerBase1 Handler
+#define HandlerBase2 Handler
+#define HandlerBase3 Handler
+#define HandlerBase4 Handler
+#define HandlerBase5 Handler
+#define HandlerBase6 Handler
+#define HandlerBase7 Handler
+#define HandlerBase8 Handler
+
+#define caller1 Caller
+#define caller2 Caller
+#define caller3 Caller
+#define caller4 Caller
+#define caller5 Caller
+#define caller6 Caller
+#define caller7 Caller
+#define caller8 Caller
+
+#define DEFINE_HANDLER0(NAME, RETURN) \
+ class CoreExport NAME : public Handler<RETURN> { public: NAME() { } virtual RETURN Call(); }
+
+#define DEFINE_HANDLER1(NAME, RETURN, V1) \
+ class CoreExport NAME : public Handler<RETURN, V1> { public: NAME() { } virtual RETURN Call(V1); }
+
+#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2> { public: NAME() { } virtual RETURN Call(V1, V2); }
+
+#define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3> { public: NAME() { } virtual RETURN Call(V1, V2, V3); }
+
+#define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
+
+#define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
+
+#define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6); }
+
+#define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6, V7> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7); }
+
+#define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6, V7, V8> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); }
+
+#else
+
/** The templates below can be auto generated by tools/create_templates.pl.
* They are used to represent a functor with a given number of parameters and
* a specific return type. To prevent passing the wrong number of parameters
@@ -281,3 +355,5 @@ template <typename ReturnType, typename Param1, typename Param2, typename Param3
class CoreExport NAME : public HandlerBase8<RETURN, V1, V2, V3, V4, V5, V6, V7, V8> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); }
#endif
+
+#endif
diff --git a/tools/create_templates.pl b/tools/create_templates.pl
deleted file mode 100755
index dfdaa29d1..000000000
--- a/tools/create_templates.pl
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/perl
-
-#
-# InspIRCd -- Internet Relay Chat Daemon
-#
-# Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
-#
-# This file is part of InspIRCd. InspIRCd is free software: you can
-# redistribute it and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation, version 2.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-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";
-}
-