]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/caller.h
Pass an interface to the OnSync hooks
[user/henk/code/inspircd.git] / include / caller.h
index 66603575221e794e395b315606738b522c81d2d1..c3a29e8c2c0333d57412c7ccf0b053ddb18b797b 100644 (file)
@@ -1,18 +1,97 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   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 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 <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __CALLER__H__
-#define __CALLER__H__
+
+#pragma once
+
+#if defined HAS_CXX11_VARIADIC_TEMPLATES
+
+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
  *
  * MyNewFunction replaceme(ServerInstance);
  *
- * someclass->MyFunction = &replaceme;
+ * someclass->MyFunction = \&replaceme;
  *
  * After this point, calls to someclass->MyFunction will call the new code in your
  * replacement functor.
  * 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 <typename ReturnType> class CoreExport HandlerBase0
+template <typename ReturnType> class CoreExport HandlerBase0 : public classbase
 {
  public:
        virtual ReturnType Call() = 0;
        virtual ~HandlerBase0() { }
 };
 
-template <typename ReturnType, typename Param1> class CoreExport HandlerBase1
+template <typename ReturnType, typename Param1> class CoreExport HandlerBase1 : public classbase
 {
  public:
        virtual ReturnType Call(Param1) = 0;
        virtual ~HandlerBase1() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2> class CoreExport HandlerBase2
+template <typename ReturnType, typename Param1, typename Param2> class CoreExport HandlerBase2 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2) = 0;
        virtual ~HandlerBase2() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport HandlerBase3
+template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport HandlerBase3 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2, Param3) = 0;
        virtual ~HandlerBase3() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport HandlerBase4
+template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport HandlerBase4 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0;
        virtual ~HandlerBase4() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport HandlerBase5
+template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport HandlerBase5 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0;
        virtual ~HandlerBase5() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport HandlerBase6
+template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport HandlerBase6 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0;
        virtual ~HandlerBase6() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport HandlerBase7
+template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport HandlerBase7 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0;
        virtual ~HandlerBase7() { }
 };
 
-template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport HandlerBase8
+template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport HandlerBase8 : public classbase
 {
  public:
        virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0;
@@ -120,12 +199,6 @@ template <typename HandlerType> class CoreExport caller
        { }
 
        virtual ~caller() { }
-
-       caller& operator=(HandlerType* newtarget)
-       {
-               target = newtarget;
-               return *this;
-       }
 };
 
 template <typename ReturnType> class CoreExport caller0 : public caller< HandlerBase0<ReturnType> >