X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fcaller.h;h=c3a29e8c2c0333d57412c7ccf0b053ddb18b797b;hb=01ac5148e948de53cd708bb28d0fd237263a0fbf;hp=9f251d16c6c281f34a384ec3527ab97ae1d685d8;hpb=914534be62976d97dd387fa3412e7b0cda002c7e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/caller.h b/include/caller.h index 9f251d16c..c3a29e8c2 100644 --- a/include/caller.h +++ b/include/caller.h @@ -1,30 +1,109 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2007 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007 Craig Edwards + * Copyright (C) 2012 Adam * - * This program is free but copyrighted software; see - * the file COPYING for details. + * 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 . */ -#ifndef __CALLER__H__ -#define __CALLER__H__ -/* The templates below can be auto generated by tools/create_templates.pl. +#pragma once + +#if defined HAS_CXX11_VARIADIC_TEMPLATES + +template class CoreExport Handler : public classbase +{ + public: + virtual ~Handler() { } + virtual ReturnType Call(Args...) = 0; +}; + +template class CoreExport Caller +{ + public: + Handler* target; + + Caller(Handler* 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 { public: NAME() { } virtual RETURN Call(); } + +#define DEFINE_HANDLER1(NAME, RETURN, V1) \ + class CoreExport NAME : public Handler { public: NAME() { } virtual RETURN Call(V1); } + +#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \ + class CoreExport NAME : public Handler { public: NAME() { } virtual RETURN Call(V1, V2); } + +#define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \ + class CoreExport NAME : public Handler { public: NAME() { } virtual RETURN Call(V1, V2, V3); } + +#define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \ + class CoreExport NAME : public Handler { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4); } + +#define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \ + class CoreExport NAME : public Handler { 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 { 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 { 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 { 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 * and have the compiler detect this error at build-time, each class is numbered * according to the number of parameters it takes, e.g. caller0, caller1, caller2. * These have been generated from zero parameters to eight. * - * If you want to declare a functor which takes two parameters, a userrec and a chanrec, + * If you want to declare a functor which takes two parameters, a User and a Channel, * and returns bool, simply create it like this: * - * caller2 MyFunction; + * caller2 MyFunction; * * and initialize it correctly, when placed into a class you will be able to call it: * @@ -32,70 +111,78 @@ * * These functor templates work this way so that you can simply and easily allow * for these class methods to be overridden from within a module, e.g. have a module - * which completely replaces the code for IsNick, etc. This is a very powerful feature - * which should be considered 'advanced' and not for beginners. If you do not - * understand these templates, STAY AWAY from playing with this until you do, as if - * you get this wrong, this can generate some pretty long winded and confusing error - * messages at compile time. + * which completely replaces the code for IsNick, etc. For example, with the example + * above: + * + * MyNewFunction replaceme(ServerInstance); + * + * someclass->MyFunction = \&replaceme; + * + * After this point, calls to someclass->MyFunction will call the new code in your + * replacement functor. + * + * This is a very powerful feature which should be considered 'advanced' and not for + * beginners. If you do not understand these templates, STAY AWAY from playing with + * this until you do, as if you get this wrong, this can generate some pretty long + * winded and confusing error messages at compile time. */ - -template class CoreExport HandlerBase0 +template class CoreExport HandlerBase0 : public classbase { public: virtual ReturnType Call() = 0; virtual ~HandlerBase0() { } }; -template class CoreExport HandlerBase1 +template class CoreExport HandlerBase1 : public classbase { public: virtual ReturnType Call(Param1) = 0; virtual ~HandlerBase1() { } }; -template class CoreExport HandlerBase2 +template class CoreExport HandlerBase2 : public classbase { public: virtual ReturnType Call(Param1, Param2) = 0; virtual ~HandlerBase2() { } }; -template class CoreExport HandlerBase3 +template class CoreExport HandlerBase3 : public classbase { public: virtual ReturnType Call(Param1, Param2, Param3) = 0; virtual ~HandlerBase3() { } }; -template class CoreExport HandlerBase4 +template class CoreExport HandlerBase4 : public classbase { public: virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0; virtual ~HandlerBase4() { } }; -template class CoreExport HandlerBase5 +template class CoreExport HandlerBase5 : public classbase { public: virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0; virtual ~HandlerBase5() { } }; -template class CoreExport HandlerBase6 +template class CoreExport HandlerBase6 : public classbase { public: virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0; virtual ~HandlerBase6() { } }; -template class CoreExport HandlerBase7 +template class CoreExport HandlerBase7 : public classbase { public: virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0; virtual ~HandlerBase7() { } }; -template class CoreExport HandlerBase8 +template class CoreExport HandlerBase8 : public classbase { public: virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0; @@ -112,12 +199,6 @@ template class CoreExport caller { } virtual ~caller() { } - - caller& operator=(HandlerType* newtarget) - { - target = newtarget; - return *this; - } }; template class CoreExport caller0 : public caller< HandlerBase0 > @@ -137,7 +218,7 @@ template class CoreExport caller1 : publi { public: caller1(HandlerBase1* initial) - : caller< HandlerBase1 >::caller(initial) + : caller< HandlerBase1 >(initial) { } virtual ReturnType operator() (Param1 param1) @@ -150,7 +231,7 @@ template class CoreExpor { public: caller2(HandlerBase2* initial) - : caller< HandlerBase2 >::caller(initial) + : caller< HandlerBase2 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2) @@ -163,7 +244,7 @@ template * initial) - : caller< HandlerBase3 >::caller(initial) + : caller< HandlerBase3 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3) @@ -176,7 +257,7 @@ template * initial) - : caller< HandlerBase4 >::caller(initial) + : caller< HandlerBase4 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4) @@ -189,7 +270,7 @@ template * initial) - : caller< HandlerBase5 >::caller(initial) + : caller< HandlerBase5 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5) @@ -202,7 +283,7 @@ template * initial) - : caller< HandlerBase6 >::caller(initial) + : caller< HandlerBase6 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6) @@ -215,7 +296,7 @@ template * initial) - : caller< HandlerBase7 >::caller(initial) + : caller< HandlerBase7 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7) @@ -228,7 +309,7 @@ template * initial) - : caller< HandlerBase8 >::caller(initial) + : caller< HandlerBase8 >(initial) { } virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7, Param8 param8) @@ -237,5 +318,38 @@ template { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(); } + +#define DEFINE_HANDLER1(NAME, RETURN, V1) \ + class CoreExport NAME : public HandlerBase1 { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1); } + +#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \ + class CoreExport NAME : public HandlerBase2 { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2); } + +#define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \ + class CoreExport NAME : public HandlerBase3 { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3); } + +#define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \ + class CoreExport NAME : public HandlerBase4 { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4); } +#define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \ + class CoreExport NAME : public HandlerBase5 { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); } + +#define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \ + class CoreExport NAME : public HandlerBase6 { public: NAME() { } virtual ~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 HandlerBase7 { public: NAME() { } virtual ~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 HandlerBase8 { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); } + +#endif