InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
caller.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd. InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #ifndef CALLER_H
22 #define CALLER_H
23 
57 template <typename ReturnType> class CoreExport HandlerBase0 : public classbase
58 {
59  public:
60  virtual ReturnType Call() = 0;
61  virtual ~HandlerBase0() { }
62 };
63 
64 template <typename ReturnType, typename Param1> class CoreExport HandlerBase1 : public classbase
65 {
66  public:
67  virtual ReturnType Call(Param1) = 0;
68  virtual ~HandlerBase1() { }
69 };
70 
71 template <typename ReturnType, typename Param1, typename Param2> class CoreExport HandlerBase2 : public classbase
72 {
73  public:
74  virtual ReturnType Call(Param1, Param2) = 0;
75  virtual ~HandlerBase2() { }
76 };
77 
78 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class CoreExport HandlerBase3 : public classbase
79 {
80  public:
81  virtual ReturnType Call(Param1, Param2, Param3) = 0;
82  virtual ~HandlerBase3() { }
83 };
84 
85 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class CoreExport HandlerBase4 : public classbase
86 {
87  public:
88  virtual ReturnType Call(Param1, Param2, Param3, Param4) = 0;
89  virtual ~HandlerBase4() { }
90 };
91 
92 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class CoreExport HandlerBase5 : public classbase
93 {
94  public:
95  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5) = 0;
96  virtual ~HandlerBase5() { }
97 };
98 
99 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6> class CoreExport HandlerBase6 : public classbase
100 {
101  public:
102  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6) = 0;
103  virtual ~HandlerBase6() { }
104 };
105 
106 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7> class CoreExport HandlerBase7 : public classbase
107 {
108  public:
109  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7) = 0;
110  virtual ~HandlerBase7() { }
111 };
112 
113 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5, typename Param6, typename Param7, typename Param8> class CoreExport HandlerBase8 : public classbase
114 {
115  public:
116  virtual ReturnType Call(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8) = 0;
117  virtual ~HandlerBase8() { }
118 };
119 
120 template <typename HandlerType> class caller
121 {
122  public:
123  HandlerType* target;
124 
125  caller(HandlerType* initial)
126  : target(initial)
127  { }
128 
129  virtual ~caller() { }
130 };
131 
132 template <typename ReturnType> class caller0 : public caller< HandlerBase0<ReturnType> >
133 {
134  public:
137  { }
138 
139  ReturnType operator() ()
140  {
141  return this->target->Call();
142  }
143 };
144 
145 template <typename ReturnType, typename Param1> class caller1 : public caller< HandlerBase1<ReturnType, Param1> >
146 {
147  public:
150  { }
151 
152  ReturnType operator() (Param1 param1)
153  {
154  return this->target->Call(param1);
155  }
156 };
157 
158 template <typename ReturnType, typename Param1, typename Param2> class caller2 : public caller< HandlerBase2<ReturnType, Param1, Param2> >
159 {
160  public:
163  { }
164 
165  ReturnType operator() (Param1 param1, Param2 param2)
166  {
167  return this->target->Call(param1, param2);
168  }
169 };
170 
171 template <typename ReturnType, typename Param1, typename Param2, typename Param3> class caller3 : public caller< HandlerBase3<ReturnType, Param1, Param2, Param3> >
172 {
173  public:
176  { }
177 
178  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3)
179  {
180  return this->target->Call(param1, param2, param3);
181  }
182 };
183 
184 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4> class caller4 : public caller< HandlerBase4<ReturnType, Param1, Param2, Param3, Param4> >
185 {
186  public:
189  { }
190 
191  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4)
192  {
193  return this->target->Call(param1, param2, param3, param4);
194  }
195 };
196 
197 template <typename ReturnType, typename Param1, typename Param2, typename Param3, typename Param4, typename Param5> class caller5 : public caller< HandlerBase5<ReturnType, Param1, Param2, Param3, Param4, Param5> >
198 {
199  public:
202  { }
203 
204  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5)
205  {
206  return this->target->Call(param1, param2, param3, param4, param5);
207  }
208 };
209 
210 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> >
211 {
212  public:
215  { }
216 
217  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6)
218  {
219  return this->target->Call(param1, param2, param3, param4, param5, param6);
220  }
221 };
222 
223 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> >
224 {
225  public:
228  { }
229 
230  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7)
231  {
232  return this->target->Call(param1, param2, param3, param4, param5, param6, param7);
233  }
234 };
235 
236 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> >
237 {
238  public:
241  { }
242 
243  ReturnType operator() (Param1 param1, Param2 param2, Param3 param3, Param4 param4, Param5 param5, Param6 param6, Param7 param7, Param8 param8)
244  {
245  return this->target->Call(param1, param2, param3, param4, param5, param6, param7, param8);
246  }
247 };
248 
256 #define DEFINE_HANDLER0(NAME, RETURN) \
257  class CoreExport NAME : public HandlerBase0<RETURN> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(); }
258 
259 #define DEFINE_HANDLER1(NAME, RETURN, V1) \
260  class CoreExport NAME : public HandlerBase1<RETURN, V1> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1); }
261 
262 #define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
263  class CoreExport NAME : public HandlerBase2<RETURN, V1, V2> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2); }
264 
265 #define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
266  class CoreExport NAME : public HandlerBase3<RETURN, V1, V2, V3> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3); }
267 
268 #define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
269  class CoreExport NAME : public HandlerBase4<RETURN, V1, V2, V3, V4> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
270 
271 #define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
272  class CoreExport NAME : public HandlerBase5<RETURN, V1, V2, V3, V4, V5> { public: NAME() { } virtual ~NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
273 
274 #define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
275  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); }
276 
277 #define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
278  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); }
279 
280 #define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
281  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); }
282 
283 #endif
Definition: caller.h:132
Definition: caller.h:197
Definition: caller.h:64
Definition: caller.h:145
Definition: caller.h:120
Definition: caller.h:99
Definition: caller.h:210
Definition: caller.h:57
Definition: base.h:42
Definition: caller.h:158
Definition: caller.h:92
Definition: caller.h:223
Definition: caller.h:113
Definition: caller.h:171
Definition: caller.h:85
Definition: caller.h:236
Definition: caller.h:106
Definition: caller.h:184
Definition: caller.h:71
Definition: caller.h:78