InspIRCd  3.0
caller.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2007 Craig Edwards <[email protected]>
6  * Copyright (C) 2012 Adam <[email protected]>
7  *
8  * This file is part of InspIRCd. InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #pragma once
23 
24 #if defined HAS_CXX11_VARIADIC_TEMPLATES
25 
26 template<typename ReturnType, typename... Args> class CoreExport Handler : public classbase
27 {
28  public:
29  virtual ~Handler() { }
30  virtual ReturnType Call(Args...) = 0;
31 };
32 
33 template<typename ReturnType, typename... Args> class CoreExport Caller
34 {
35  public:
36  Handler<ReturnType, Args...>* target;
37 
38  Caller(Handler<ReturnType, Args...>* initial) : target(initial) { }
39  virtual ~Caller() { }
40 
41  virtual ReturnType operator()(const Args&... params)
42  {
43  return this->target->Call(params...);
44  }
45 };
46 
47 /* Below here is compat with the old API */
48 #define HandlerBase0 Handler
49 #define HandlerBase1 Handler
50 #define HandlerBase2 Handler
51 #define HandlerBase3 Handler
52 #define HandlerBase4 Handler
53 #define HandlerBase5 Handler
54 #define HandlerBase6 Handler
55 #define HandlerBase7 Handler
56 #define HandlerBase8 Handler
57 
58 #define caller1 Caller
59 #define caller2 Caller
60 #define caller3 Caller
61 #define caller4 Caller
62 #define caller5 Caller
63 #define caller6 Caller
64 #define caller7 Caller
65 #define caller8 Caller
66 
67 #define DEFINE_HANDLER0(NAME, RETURN) \
68  class CoreExport NAME : public Handler<RETURN> { public: NAME() { } virtual RETURN Call(); }
69 
70 #define DEFINE_HANDLER1(NAME, RETURN, V1) \
71  class CoreExport NAME : public Handler<RETURN, V1> { public: NAME() { } virtual RETURN Call(V1); }
72 
73 #define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
74  class CoreExport NAME : public Handler<RETURN, V1, V2> { public: NAME() { } virtual RETURN Call(V1, V2); }
75 
76 #define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
77  class CoreExport NAME : public Handler<RETURN, V1, V2, V3> { public: NAME() { } virtual RETURN Call(V1, V2, V3); }
78 
79 #define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
80  class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
81 
82 #define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
83  class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
84 
85 #define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
86  class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6); }
87 
88 #define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
89  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); }
90 
91 #define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
92  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); }
93 
94 #else
95 
129 template <typename ReturnType> class CoreExport HandlerBase0 : public classbase
130 {
131  public:
132  virtual ReturnType Call() = 0;
133  virtual ~HandlerBase0() { }
134 };
135 
136 template <typename ReturnType, typename Param1> class CoreExport HandlerBase1 : public classbase
137 {
138  public:
139  virtual ReturnType Call(Param1) = 0;
140  virtual ~HandlerBase1() { }
141 };
142 
143 template <typename ReturnType, typename Param1, typename Param2> class CoreExport HandlerBase2 : public classbase
144 {
145  public:
146  virtual ReturnType Call(Param1, Param2) = 0;
147  virtual ~HandlerBase2() { }
148 };
149 
150 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport HandlerBase3 : public classbase
151 {
152  public:
153  virtual ReturnType Call(Param1, Param2, Param3) = 0;
154  virtual ~HandlerBase3() { }
155 };
156 
157 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport HandlerBase4 : public classbase
158 {
159  public:
160  virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0;
161  virtual ~HandlerBase4() { }
162 };
163 
164 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport HandlerBase5 : public classbase
165 {
166  public:
167  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0;
168  virtual ~HandlerBase5() { }
169 };
170 
171 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport HandlerBase6 : public classbase
172 {
173  public:
174  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0;
175  virtual ~HandlerBase6() { }
176 };
177 
178 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport HandlerBase7 : public classbase
179 {
180  public:
181  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0;
182  virtual ~HandlerBase7() { }
183 };
184 
185 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport HandlerBase8 : public classbase
186 {
187  public:
188  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0;
189  virtual ~HandlerBase8() { }
190 };
191 
192 template <typename HandlerType> class caller
193 {
194  public:
195  HandlerType* target;
196 
197  caller(HandlerType* initial)
198  : target(initial)
199  { }
200 
201  virtual ~caller() { }
202 };
203 
204 template <typename ReturnType> class caller0 : public caller< HandlerBase0<ReturnType> >
205 {
206  public:
209  { }
210 
211  ReturnType operator() ()
212  {
213  return this->target->Call();
214  }
215 };
216 
217 template <typename ReturnType, typename Param1> class caller1 : public caller< HandlerBase1<ReturnType, Param1> >
218 {
219  public:
222  { }
223 
224  ReturnType operator() (Param1 param1)
225  {
226  return this->target->Call(param1);
227  }
228 };
229 
230 template <typename ReturnType, typename Param1, typename Param2> class caller2 : public caller< HandlerBase2<ReturnType, Param1, Param2> >
231 {
232  public:
235  { }
236 
237  ReturnType operator() (Param1 param1, Param2 param2)
238  {
239  return this->target->Call(param1, param2);
240  }
241 };
242 
243 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class caller3 : public caller< HandlerBase3<ReturnType, Param1, Param2, Param3> >
244 {
245  public:
248  { }
249 
250  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3)
251  {
252  return this->target->Call(param1, param2, param3);
253  }
254 };
255 
256 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class caller4 : public caller< HandlerBase4<ReturnType, Param1, Param2, Param3, Param4> >
257 {
258  public:
261  { }
262 
263  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4)
264  {
265  return this->target->Call(param1, param2, param3, param4);
266  }
267 };
268 
269 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class caller5 : public caller< HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5> >
270 {
271  public:
274  { }
275 
276  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5)
277  {
278  return this->target->Call(param1, param2, param3, param4, param5);
279  }
280 };
281 
282 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class caller6 : public caller< HandlerBase6<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6> >
283 {
284  public:
287  { }
288 
289  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6)
290  {
291  return this->target->Call(param1, param2, param3, param4, param5, param6);
292  }
293 };
294 
295 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class caller7 : public caller< HandlerBase7<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7> >
296 {
297  public:
300  { }
301 
302  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7)
303  {
304  return this->target->Call(param1, param2, param3, param4, param5, param6, param7);
305  }
306 };
307 
308 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class caller8 : public caller< HandlerBase8<ReturnType, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8> >
309 {
310  public:
313  { }
314 
315  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7, Param8 param8)
316  {
317  return this->target->Call(param1, param2, param3, param4, param5, param6, param7, param8);
318  }
319 };
320 
328 #define DEFINE_HANDLER0(NAME, RETURN) \
329  class CoreExport NAME : public HandlerBase0<RETURN> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(); }
330 
331 #define DEFINE_HANDLER1(NAME, RETURN, V1) \
332  class CoreExport NAME : public HandlerBase1<RETURN, V1> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1); }
333 
334 #define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
335  class CoreExport NAME : public HandlerBase2<RETURN, V1, V2> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2); }
336 
337 #define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
338  class CoreExport NAME : public HandlerBase3<RETURN, V1, V2, V3> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3); }
339 
340 #define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
341  class CoreExport NAME : public HandlerBase4<RETURN, V1, V2, V3, V4> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
342 
343 #define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
344  class CoreExport NAME : public HandlerBase5<RETURN, V1, V2, V3, V4, V5> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
345 
346 #define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
347  class CoreExport NAME : public HandlerBase6<RETURN, V1, V2, V3, V4, V5, V6> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6); }
348 
349 #define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
350  class CoreExport NAME : public HandlerBase7<RETURN, V1, V2, V3, V4, V5, V6, V7> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7); }
351 
352 #define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
353  class CoreExport NAME : public HandlerBase8<RETURN, V1, V2, V3, V4, V5, V6, V7, V8> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); }
354 
355 #endif
Definition: caller.h:204
Definition: caller.h:269
Definition: caller.h:136
Definition: caller.h:217
Definition: caller.h:192
Definition: caller.h:171
Definition: caller.h:282
Definition: caller.h:129
Definition: base.h:41
Definition: caller.h:230
Definition: caller.h:164
Definition: caller.h:295
Definition: caller.h:185
Definition: caller.h:243
Definition: caller.h:157
Definition: caller.h:308
Definition: caller.h:178
Definition: caller.h:256
Definition: caller.h:143
Definition: caller.h:150