1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 f r 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.
51 template <typename ReturnType> class CoreExport HandlerBase0
54 virtual ReturnType Call() = 0;
55 virtual ~HandlerBase0() { }
58 template <typename ReturnType, typename Param1> class CoreExport HandlerBase1
61 virtual ReturnType Call(Param1) = 0;
62 virtual ~HandlerBase1() { }
65 template <typename ReturnType, typename Param1, typename Param2> class CoreExport HandlerBase2
68 virtual ReturnType Call(Param1, Param2) = 0;
69 virtual ~HandlerBase2() { }
72 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport HandlerBase3
75 virtual ReturnType Call(Param1, Param2, Param3) = 0;
76 virtual ~HandlerBase3() { }
79 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport HandlerBase4
82 virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0;
83 virtual ~HandlerBase4() { }
86 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport HandlerBase5
89 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0;
90 virtual ~HandlerBase5() { }
93 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport HandlerBase6
96 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0;
97 virtual ~HandlerBase6() { }
100 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport HandlerBase7
103 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0;
104 virtual ~HandlerBase7() { }
107 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport HandlerBase8
110 virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0;
111 virtual ~HandlerBase8() { }
114 template <typename HandlerType> class CoreExport caller
119 caller(HandlerType* initial)
123 virtual ~caller() { }
125 caller& operator=(HandlerType* newtarget)
132 template <typename ReturnType> class CoreExport caller0 : public caller< HandlerBase0<ReturnType> >
135 caller0(HandlerBase0<ReturnType>* initial)
136 : caller< HandlerBase0<ReturnType> >::caller(initial)
139 virtual ReturnType operator() ()
141 return this->target->Call();
145 template <typename ReturnType, typename Param1> class CoreExport caller1 : public caller< HandlerBase1<ReturnType, Param1> >
148 caller1(HandlerBase1<ReturnType, Param1>* initial)
149 : caller< HandlerBase1<ReturnType, Param1> >(initial)
152 virtual ReturnType operator() (Param1 param1)
154 return this->target->Call(param1);
158 template <typename ReturnType, typename Param1, typename Param2> class CoreExport caller2 : public caller< HandlerBase2<ReturnType, Param1, Param2> >
161 caller2(HandlerBase2<ReturnType, Param1, Param2>* initial)
162 : caller< HandlerBase2<ReturnType, Param1, Param2> >(initial)
165 virtual ReturnType operator() (Param1 param1, Param2 param2)
167 return this->target->Call(param1, param2);
171 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport caller3 : public caller< HandlerBase3<ReturnType, Param1, Param2, Param3> >
174 caller3(HandlerBase3<ReturnType, Param1, Param2, Param3>* initial)
175 : caller< HandlerBase3<ReturnType, Param1, Param2, Param3> >(initial)
178 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3)
180 return this->target->Call(param1, param2, param3);
184 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport caller4 : public caller< HandlerBase4<ReturnType, Param1, Param2, Param3, Param4> >
187 caller4(HandlerBase4<ReturnType, Param1, Param2, Param3, Param4>* initial)
188 : caller< HandlerBase4<ReturnType, Param1, Param2, Param3, Param4> >(initial)
191 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4)
193 return this->target->Call(param1, param2, param3, param4);
197 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> >
200 caller5(HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5>* initial)
201 : caller< HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5> >(initial)
204 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5)
206 return this->target->Call(param1, param2, param3, param4, param5);
210 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> >
213 caller6(HandlerBase6<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6>* initial)
214 : caller< HandlerBase6<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6> >(initial)
217 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6)
219 return this->target->Call(param1, param2, param3, param4, param5, param6);
223 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> >
226 caller7(HandlerBase7<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7>* initial)
227 : caller< HandlerBase7<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7> >(initial)
230 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7)
232 return this->target->Call(param1, param2, param3, param4, param5, param6, param7);
236 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> >
239 caller8(HandlerBase8<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8>* initial)
240 : caller< HandlerBase8<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8> >(initial)
243 virtual ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7, Param8 param8)
245 return this->target->Call(param1, param2, param3, param4, param5, param6, param7, param8);
249 /** These shorthand macros are used to define a functor class which only implements Call(). Most functors are like this.
250 * If you want something more complex, define them by hand.
252 * The first parameter to each macro is the class name to define, the second parameter is the return value of Call().
253 * The following parameters are the parameter types for Call(), and again, the macro is numbered to match the number of
254 * parameters, to prevent mistakes.
257 #define DEFINE_HANDLER0(NAME, RETURN) \
258 class CoreExport NAME : public HandlerBase0<RETURN> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(); }
260 #define DEFINE_HANDLER1(NAME, RETURN, V1) \
261 class CoreExport NAME : public HandlerBase1<RETURN, V1> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1); }
263 #define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
264 class CoreExport NAME : public HandlerBase2<RETURN, V1, V2> { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1, V2); }
266 #define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
267 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); }
269 #define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
270 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); }
272 #define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
273 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); }
275 #define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
276 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); }
278 #define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
279 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); }
281 #define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
282 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); }