X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fcaller.h;h=47f896ef612dafb5dbfe47574cf68ab032ea10ae;hb=a7a0f69c6bf32b63c3314a097929c533296b1c86;hp=05049df8bfdb2783be67fd46abbabfd21386d2f9;hpb=b6a3477a44dd7c47a9b29cbfe07e3a7886a97141;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/caller.h b/include/caller.h index 05049df8b..47f896ef6 100644 --- a/include/caller.h +++ b/include/caller.h @@ -3,6 +3,7 @@ * * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2007 Craig Edwards + * Copyright (C) 2012 Adam * * 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 @@ -18,8 +19,79 @@ */ -#ifndef CALLER_H -#define CALLER_H +#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 @@ -117,7 +189,7 @@ template class CoreExport caller +template class caller { public: HandlerType* target; @@ -129,7 +201,7 @@ template class CoreExport caller virtual ~caller() { } }; -template class CoreExport caller0 : public caller< HandlerBase0 > +template class caller0 : public caller< HandlerBase0 > { public: caller0(HandlerBase0* initial) @@ -142,7 +214,7 @@ template class CoreExport caller0 : public caller< Handler } }; -template class CoreExport caller1 : public caller< HandlerBase1 > +template class caller1 : public caller< HandlerBase1 > { public: caller1(HandlerBase1* initial) @@ -155,7 +227,7 @@ template class CoreExport caller1 : publi } }; -template class CoreExport caller2 : public caller< HandlerBase2 > +template class caller2 : public caller< HandlerBase2 > { public: caller2(HandlerBase2* initial) @@ -168,7 +240,7 @@ template class CoreExpor } }; -template class CoreExport caller3 : public caller< HandlerBase3 > +template class caller3 : public caller< HandlerBase3 > { public: caller3(HandlerBase3* initial) @@ -181,7 +253,7 @@ template class CoreExport caller4 : public caller< HandlerBase4 > +template class caller4 : public caller< HandlerBase4 > { public: caller4(HandlerBase4* initial) @@ -194,7 +266,7 @@ template class CoreExport caller5 : public caller< HandlerBase5 > +template class caller5 : public caller< HandlerBase5 > { public: caller5(HandlerBase5* initial) @@ -207,7 +279,7 @@ template class CoreExport caller6 : public caller< HandlerBase6 > +template class caller6 : public caller< HandlerBase6 > { public: caller6(HandlerBase6* initial) @@ -220,7 +292,7 @@ template class CoreExport caller7 : public caller< HandlerBase7 > +template class caller7 : public caller< HandlerBase7 > { public: caller7(HandlerBase7* initial) @@ -233,7 +305,7 @@ template class CoreExport caller8 : public caller< HandlerBase8 > +template class caller8 : public caller< HandlerBase8 > { public: caller8(HandlerBase8* initial)