1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /** The templates below can be auto generated by tools/create_templates.pl.
18 * They are used to represent a functor with a given number of parameters and
19 * a specific return type. To prevent passing the wrong number of parameters
20 * and have the compiler detect this error at build-time, each class is numbered
21 * according to the number of parameters it takes, e.g. caller0, caller1, caller2.
22 * These have been generated from zero parameters to eight.
24 * If you want to declare a functor which takes two parameters, a User and a Channel,
25 * and returns bool, simply create it like this:
27 * caller2<bool, User*, Channel*> MyFunction;
29 * and initialize it correctly, when placed into a class you will be able to call it:
31 * bool n = someclass->MyFunction(someuser, somechan);
33 * These functor templates work this way so that you can simply and easily allow
34 * for these class methods to be overridden from within a module, e.g. have a module
35 * which completely replaces the code for IsNick, etc. For example, with the example
38 * MyNewFunction replaceme(ServerInstance);
40 * someclass->MyFunction = &replaceme;
42 * After this point, calls to someclass->MyFunction will call the new code in your
43 * replacement functor.
45 * This is a very powerful feature which should be considered 'advanced' and not for
46 * beginners. If you do not understand these templates, STAY AWAY from playing with
47 * this until you do, as if you get this wrong, this can generate some pretty long
48 * winded and confusing error messages at compile time.
50 template <typename ReturnType> class CoreExport HandlerBase0
53 virtual ReturnType Call() = 0;
54 virtual ~HandlerBase0() { }
57 template <typename ReturnType, typename Param1> class CoreExport HandlerBase1
60 virtual ReturnType Call(Param1) = 0;
61 virtual ~HandlerBase1() { }
64 template <typename ReturnType, typename Param1, typename Param2> class CoreExport HandlerBase2
67 virtual ReturnType Call(Param1, Param2) = 0;
68 virtual ~HandlerBase2() { }
71 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport HandlerBase3
74 virtual ReturnType Call(Param1, Param2, Param3) = 0;
75 virtual ~HandlerBase3() { }
78 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport HandlerBase4
81 virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0;
82 virtual ~HandlerBase4() { }
85 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport HandlerBase5
88 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0;
89 virtual ~HandlerBase5() { }
92 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport HandlerBase6
95 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0;
96 virtual ~HandlerBase6() { }
99 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport HandlerBase7
102 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0;
103 virtual ~HandlerBase7() { }
106 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport HandlerBase8
109 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0;
110 virtual ~HandlerBase8() { }
113 template <typename HandlerType> class CoreExport caller
118 caller(HandlerType* initial)
122 virtual ~caller() { }
124 caller& operator=(HandlerType* newtarget)
131 template <typename ReturnType> class CoreExport caller0 : public caller< HandlerBase0<ReturnType> >
134 caller0(HandlerBase0<ReturnType>* initial)
135 : caller< HandlerBase0<ReturnType> >::caller(initial)
138 virtual ReturnType operator() ()
140 return this->target->Call();
144 template <typename ReturnType, typename Param1> class CoreExport caller1 : public caller< HandlerBase1<ReturnType, Param1> >
147 caller1(HandlerBase1<ReturnType, Param1>* initial)
148 : caller< HandlerBase1<ReturnType, Param1> >(initial)
151 virtual ReturnType operator() (Param1 param1)
153 return this->target->Call(param1);
157 template <typename ReturnType, typename Param1, typename Param2> class CoreExport caller2 : public caller< HandlerBase2<ReturnType, Param1, Param2> >
160 caller2(HandlerBase2<ReturnType, Param1, Param2>* initial)
161 : caller< HandlerBase2<ReturnType, Param1, Param2> >(initial)
164 virtual ReturnType operator() (Param1 param1, Param2 param2)
166 return this->target->Call(param1, param2);
170 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport caller3 : public caller< HandlerBase3<ReturnType, Param1, Param2, Param3> >
173 caller3(HandlerBase3<ReturnType, Param1, Param2, Param3>* initial)
174 : caller< HandlerBase3<ReturnType, Param1, Param2, Param3> >(initial)
177 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3)
179 return this->target->Call(param1, param2, param3);
183 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport caller4 : public caller< HandlerBase4<ReturnType, Param1, Param2, Param3, Param4> >
186 caller4(HandlerBase4<ReturnType, Param1, Param2, Param3, Param4>* initial)
187 : caller< HandlerBase4<ReturnType, Param1, Param2, Param3, Param4> >(initial)
190 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4)
192 return this->target->Call(param1, param2, param3, param4);
196 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport caller5 : public caller< HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5> >
199 caller5(HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5>* initial)
200 : caller< HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5> >(initial)
203 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5)
205 return this->target->Call(param1, param2, param3, param4, param5);
209 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport caller6 : public caller< HandlerBase6<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6> >
212 caller6(HandlerBase6<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6>* initial)
213 : caller< HandlerBase6<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6> >(initial)
216 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6)
218 return this->target->Call(param1, param2, param3, param4, param5, param6);
222 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport caller7 : public caller< HandlerBase7<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7> >
225 caller7(HandlerBase7<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7>* initial)
226 : caller< HandlerBase7<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7> >(initial)
229 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7)
231 return this->target->Call(param1, param2, param3, param4, param5, param6, param7);
235 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport caller8 : public caller< HandlerBase8<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8> >
238 caller8(HandlerBase8<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8>* initial)
239 : caller< HandlerBase8<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8> >(initial)
242 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7, Param8 param8)
244 return this->target->Call(param1, param2, param3, param4, param5, param6, param7, param8);
248 /** These shorthand macros are used to define a functor class which only implements Call(). Most functors are like this.
249 * If you want something more complex, define them by hand.
251 * The first parameter to each macro is the class name to define, the second parameter is the return value of Call().
252 * The following parameters are the parameter types for Call(), and again, the macro is numbered to match the number of
253 * parameters, to prevent mistakes.
255 #define DEFINE_HANDLER0(NAME, RETURN) \
256 class CoreExport NAME : public HandlerBase0<RETURN> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(); }
258 #define DEFINE_HANDLER1(NAME, RETURN, V1) \
259 class CoreExport NAME : public HandlerBase1<RETURN, V1> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1); }
261 #define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
262 class CoreExport NAME : public HandlerBase2<RETURN, V1, V2> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2); }
264 #define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
265 class CoreExport NAME : public HandlerBase3<RETURN, V1, V2, V3> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3); }
267 #define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
268 class CoreExport NAME : public HandlerBase4<RETURN, V1, V2, V3, V4> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
270 #define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
271 class CoreExport NAME : public HandlerBase5<RETURN, V1, V2, V3, V4, V5> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
273 #define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
274 class CoreExport NAME : public HandlerBase6<RETURN, V1, V2, V3, V4, V5, V6> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6); }
276 #define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
277 class CoreExport NAME : public HandlerBase7<RETURN, V1, V2, V3, V4, V5, V6, V7> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7); }
279 #define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
280 class CoreExport NAME : public HandlerBase8<RETURN, V1, V2, V3, V4, V5, V6, V7, V8> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); }