From fa95bb4b0d5aed9204d469a36946a9839a7ffaa2 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 25 Nov 2017 13:01:53 +0000 Subject: [PATCH] Convert the remaining things away from the caller/handler API. --- include/caller.h | 355 ----------------------------- include/compat.h | 18 -- include/cull_list.h | 12 +- include/inspircd.h | 1 - src/coremods/core_reloadmodule.cpp | 2 +- src/modules.cpp | 2 +- 6 files changed, 12 insertions(+), 378 deletions(-) delete mode 100644 include/caller.h diff --git a/include/caller.h b/include/caller.h deleted file mode 100644 index dfa6ccebb..000000000 --- a/include/caller.h +++ /dev/null @@ -1,355 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * 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 - * 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 . - */ - - -#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: RETURN Call() CXX11_OVERRIDE; } - -#define DEFINE_HANDLER1(NAME, RETURN, V1) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2, V3) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2, V3, V4) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2, V3, V4, V5) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2, V3, V4, V5, V6) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2, V3, V4, V5, V6, V7) CXX11_OVERRIDE; } - -#define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \ - class CoreExport NAME : public Handler { public: RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8) CXX11_OVERRIDE; } - -#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 User and a Channel, - * and returns bool, simply create it like this: - * - * caller2 MyFunction; - * - * and initialize it correctly, when placed into a class you will be able to call it: - * - * bool n = someclass->MyFunction(someuser, somechan); - * - * 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. 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 : public classbase -{ - public: - virtual ReturnType Call() = 0; - virtual ~HandlerBase0() { } -}; - -template class CoreExport HandlerBase1 : public classbase -{ - public: - virtual ReturnType Call(Param1) = 0; - virtual ~HandlerBase1() { } -}; - -template class CoreExport HandlerBase2 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2) = 0; - virtual ~HandlerBase2() { } -}; - -template class CoreExport HandlerBase3 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2, Param3) = 0; - virtual ~HandlerBase3() { } -}; - -template class CoreExport HandlerBase4 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0; - virtual ~HandlerBase4() { } -}; - -template class CoreExport HandlerBase5 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0; - virtual ~HandlerBase5() { } -}; - -template class CoreExport HandlerBase6 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0; - virtual ~HandlerBase6() { } -}; - -template class CoreExport HandlerBase7 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0; - virtual ~HandlerBase7() { } -}; - -template class CoreExport HandlerBase8 : public classbase -{ - public: - virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0; - virtual ~HandlerBase8() { } -}; - -template class caller -{ - public: - HandlerType* target; - - caller(HandlerType* initial) - : target(initial) - { } - - virtual ~caller() { } -}; - -template class caller0 : public caller< HandlerBase0 > -{ - public: - caller0(HandlerBase0* initial) - : caller< HandlerBase0 >::caller(initial) - { } - - ReturnType operator() () - { - return this->target->Call(); - } -}; - -template class caller1 : public caller< HandlerBase1 > -{ - public: - caller1(HandlerBase1* initial) - : caller< HandlerBase1 >(initial) - { } - - ReturnType operator() (Param1 param1) - { - return this->target->Call(param1); - } -}; - -template class caller2 : public caller< HandlerBase2 > -{ - public: - caller2(HandlerBase2* initial) - : caller< HandlerBase2 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2) - { - return this->target->Call(param1, param2); - } -}; - -template class caller3 : public caller< HandlerBase3 > -{ - public: - caller3(HandlerBase3* initial) - : caller< HandlerBase3 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2, Param3 param3) - { - return this->target->Call(param1, param2, param3); - } -}; - -template class caller4 : public caller< HandlerBase4 > -{ - public: - caller4(HandlerBase4* initial) - : caller< HandlerBase4 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4) - { - return this->target->Call(param1, param2, param3, param4); - } -}; - -template class caller5 : public caller< HandlerBase5 > -{ - public: - caller5(HandlerBase5* initial) - : caller< HandlerBase5 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5) - { - return this->target->Call(param1, param2, param3, param4, param5); - } -}; - -template class caller6 : public caller< HandlerBase6 > -{ - public: - caller6(HandlerBase6* initial) - : caller< HandlerBase6 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6) - { - return this->target->Call(param1, param2, param3, param4, param5, param6); - } -}; - -template class caller7 : public caller< HandlerBase7 > -{ - public: - caller7(HandlerBase7* initial) - : caller< HandlerBase7 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7) - { - return this->target->Call(param1, param2, param3, param4, param5, param6, param7); - } -}; - -template class caller8 : public caller< HandlerBase8 > -{ - public: - caller8(HandlerBase8* initial) - : caller< HandlerBase8 >(initial) - { } - - ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7, Param8 param8) - { - return this->target->Call(param1, param2, param3, param4, param5, param6, param7, param8); - } -}; - -/** These shorthand macros are used to define a functor class which only implements Call(). Most functors are like this. - * If you want something more complex, define them by hand. - * - * The first parameter to each macro is the class name to define, the second parameter is the return value of Call(). - * The following parameters are the parameter types for Call(), and again, the macro is numbered to match the number of - * parameters, to prevent mistakes. - */ -#define DEFINE_HANDLER0(NAME, RETURN) \ - class CoreExport NAME : public HandlerBase0 { 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 diff --git a/include/compat.h b/include/compat.h index 4678de12a..7a95e9050 100644 --- a/include/compat.h +++ b/include/compat.h @@ -76,24 +76,6 @@ # define CXX11_OVERRIDE #endif -/** - * These macros enable the detection of the C++11 variadic templates in - * compilers which support them. - */ -#if __cplusplus >= 201103L -# define HAS_CXX11_VARIADIC_TEMPLATES -#elif defined __clang__ -# if __has_feature(cxx_variadic_templates) -# define HAS_CXX11_VARIADIC_TEMPLATES -# endif -#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -# if defined __GXX_EXPERIMENTAL_CXX0X__ -# define HAS_CXX11_VARIADIC_TEMPLATES -# endif -#elif _MSC_FULL_VER >= 170051025 -# define HAS_CXX11_VARIADIC_TEMPLATES -#endif - /** * This macro allows methods to be marked as deprecated. To use this, wrap the * method declaration in the header file with the macro. diff --git a/include/cull_list.h b/include/cull_list.h index ac64dced2..f5087f512 100644 --- a/include/cull_list.h +++ b/include/cull_list.h @@ -43,14 +43,22 @@ class CoreExport CullList void Apply(); }; +/** Represents an action which is executable by an action list */ +class CoreExport ActionBase : public classbase +{ + public: + /** Executes this action. */ + virtual void Call() = 0; +}; + class CoreExport ActionList { - std::vector*> list; + std::vector list; public: /** Adds an item to the list */ - void AddAction(HandlerBase0* item) { list.push_back(item); } + void AddAction(ActionBase* item) { list.push_back(item); } /** Runs the items */ diff --git a/include/inspircd.h b/include/inspircd.h index 00a705dd0..7e9007a1d 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -68,7 +68,6 @@ struct fakederef #include "convto.h" #include "dynref.h" #include "consolecolors.h" -#include "caller.h" #include "cull_list.h" #include "extensible.h" #include "fileutils.h" diff --git a/src/coremods/core_reloadmodule.cpp b/src/coremods/core_reloadmodule.cpp index 9684c8c13..910144221 100644 --- a/src/coremods/core_reloadmodule.cpp +++ b/src/coremods/core_reloadmodule.cpp @@ -565,7 +565,7 @@ void DataKeeper::DoRestoreModules() } // namespace ReloadModule -class ReloadAction : public HandlerBase0 +class ReloadAction : public ActionBase { Module* const mod; const std::string uuid; diff --git a/src/modules.cpp b/src/modules.cpp index 9a3618264..65e0a53ca 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -440,7 +440,7 @@ void ModuleManager::UnloadAll() namespace { - struct UnloadAction : public HandlerBase0 + struct UnloadAction : public ActionBase { Module* const mod; UnloadAction(Module* m) : mod(m) {} -- 2.39.2