OregonCore  revision 80751cf-git
Your Favourite TBC server
Callback.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_CALLBACK_H
19 #define OREGON_CALLBACK_H
20 
21 // BASE CLASSES
22 
23 namespace Oregon
24 {
25 template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void >
26 class _Callback
27 {
28  protected:
29  typedef void (Class::*Method)(ParamType1, ParamType2, ParamType3, ParamType4);
30  Class* m_object;
32  ParamType1 m_param1;
33  ParamType2 m_param2;
34  ParamType3 m_param3;
35  ParamType4 m_param4;
36  void _Execute()
37  {
38  (m_object->*m_method)(m_param1, m_param2, m_param3, m_param4);
39  }
40  public:
41  _Callback(Class* object, Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
42  : m_object(object), m_method(method), m_param1(param1), m_param2(param2), m_param3(param3), m_param4(param4) {}
44  : m_object(cb.object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3), m_param4(cb.m_param4) {}
45 };
46 
47 template < class Class, typename ParamType1, typename ParamType2, typename ParamType3 >
48 class _Callback < Class, ParamType1, ParamType2, ParamType3 >
49 {
50  protected:
51  typedef void (Class::*Method)(ParamType1, ParamType2, ParamType3);
52  Class* m_object;
54  ParamType1 m_param1;
55  ParamType2 m_param2;
56  ParamType3 m_param3;
57  void _Execute()
58  {
59  (m_object->*m_method)(m_param1, m_param2, m_param3);
60  }
61  public:
62  _Callback(Class* object, Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
63  : m_object(object), m_method(method), m_param1(param1), m_param2(param2), m_param3(param3) {}
65  : m_object(cb.object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3) {}
66 };
67 
68 template < class Class, typename ParamType1, typename ParamType2 >
69 class _Callback < Class, ParamType1, ParamType2 >
70 {
71  protected:
72  typedef void (Class::*Method)(ParamType1, ParamType2);
73  Class* m_object;
75  ParamType1 m_param1;
76  ParamType2 m_param2;
77  void _Execute()
78  {
79  (m_object->*m_method)(m_param1, m_param2);
80  }
81  public:
82  _Callback(Class* object, Method method, ParamType1 param1, ParamType2 param2)
83  : m_object(object), m_method(method), m_param1(param1), m_param2(param2) {}
85  : m_object(cb.m_object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2) {}
86 };
87 
88 template < class Class, typename ParamType1 >
89 class _Callback < Class, ParamType1 >
90 {
91  protected:
92  typedef void (Class::*Method)(ParamType1);
93  Class* m_object;
95  ParamType1 m_param1;
96  void _Execute()
97  {
98  (m_object->*m_method)(m_param1);
99  }
100  public:
101  _Callback(Class* object, Method method, ParamType1 param1)
102  : m_object(object), m_method(method), m_param1(param1) {}
104  : m_object(cb.m_object), m_method(cb.m_method), m_param1(cb.m_param1) {}
105 };
106 
107 template < class Class >
108 class _Callback < Class >
109 {
110  protected:
111  typedef void (Class::*Method)();
112  Class* m_object;
114  void _Execute()
115  {
116  (m_object->*m_method)();
117  }
118  public:
119  _Callback(Class* object, Method method)
120  : m_object(object), m_method(method) {}
122  : m_object(cb.m_object), m_method(cb.m_method) {}
123 };
124 
125 // STATICS
126 
127 template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void >
129 {
130  protected:
131  typedef void (*Method)(ParamType1, ParamType2, ParamType3, ParamType4);
133  ParamType1 m_param1;
134  ParamType2 m_param2;
135  ParamType3 m_param3;
136  ParamType4 m_param4;
137  void _Execute()
138  {
139  (*m_method)(m_param1, m_param2, m_param3, m_param4);
140  }
141  public:
142  _SCallback(Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
143  : m_method(method), m_param1(param1), m_param2(param2), m_param3(param3), m_param4(param4) {}
145  : m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3), m_param4(cb.m_param4) {}
146 };
147 
148 template < typename ParamType1, typename ParamType2, typename ParamType3 >
149 class _SCallback < ParamType1, ParamType2, ParamType3 >
150 {
151  protected:
152  typedef void (*Method)(ParamType1, ParamType2, ParamType3);
154  ParamType1 m_param1;
155  ParamType2 m_param2;
156  ParamType3 m_param3;
157  void _Execute()
158  {
159  (*m_method)(m_param1, m_param2, m_param3);
160  }
161  public:
162  _SCallback(Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
163  : m_method(method), m_param1(param1), m_param2(param2), m_param3(param3) {}
165  : m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3) {}
166 };
167 
168 template < typename ParamType1, typename ParamType2 >
169 class _SCallback < ParamType1, ParamType2 >
170 {
171  protected:
172  typedef void (*Method)(ParamType1, ParamType2);
174  ParamType1 m_param1;
175  ParamType2 m_param2;
176  void _Execute()
177  {
178  (*m_method)(m_param1, m_param2);
179  }
180  public:
181  _SCallback(Method method, ParamType1 param1, ParamType2 param2)
182  : m_method(method), m_param1(param1), m_param2(param2) {}
184  : m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2) {}
185 };
186 
187 template < typename ParamType1 >
188 class _SCallback < ParamType1 >
189 {
190  protected:
191  typedef void (*Method)(ParamType1);
193  ParamType1 m_param1;
194  void _Execute()
195  {
196  (*m_method)(m_param1);
197  }
198  public:
199  _SCallback(Method method, ParamType1 param1)
200  : m_method(method), m_param1(param1) {}
202  : m_method(cb.m_method), m_param1(cb.m_param1) {}
203 };
204 
205 template < >
206 class _SCallback < >
207 {
208  protected:
209  typedef void (*Method)();
211  void _Execute()
212  {
213  (*m_method)();
214  }
215  public:
217  : m_method(method) {}
219  : m_method(cb.m_method) {}
220 };
221 }
222 
223 // GENERIC CALLBACKS
224 
225 namespace Oregon
226 {
228 {
229  public:
230  virtual void Execute() = 0;
231  virtual ~ICallback() {}
232 };
233 
234 template < class CB >
235 class _ICallback : public CB, public ICallback
236 {
237  public:
238  _ICallback(CB const& cb) : CB(cb) {}
239  void Execute()
240  {
241  CB::_Execute();
242  }
243 };
244 
245 template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void >
246 class Callback :
247  public _ICallback< _Callback < Class, ParamType1, ParamType2, ParamType3, ParamType4 > >
248 {
249  private:
251  public:
252  Callback(Class* object, typename C4::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
253  : _ICallback< C4 >(C4(object, method, param1, param2, param3, param4)) {}
254 };
255 
256 template < class Class, typename ParamType1, typename ParamType2, typename ParamType3 >
257 class Callback < Class, ParamType1, ParamType2, ParamType3 > :
258  public _ICallback< _Callback < Class, ParamType1, ParamType2, ParamType3 > >
259 {
260  private:
262  public:
263  Callback(Class* object, typename C3::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
264  : _ICallback< C3 >(C3(object, method, param1, param2, param3)) {}
265 };
266 
267 template < class Class, typename ParamType1, typename ParamType2 >
268 class Callback < Class, ParamType1, ParamType2 > :
269  public _ICallback< _Callback < Class, ParamType1, ParamType2 > >
270 {
271  private:
273  public:
274  Callback(Class* object, typename C2::Method method, ParamType1 param1, ParamType2 param2)
275  : _ICallback< C2 >(C2(object, method, param1, param2)) {}
276 };
277 
278 template < class Class, typename ParamType1 >
279 class Callback < Class, ParamType1 > :
280  public _ICallback< _Callback < Class, ParamType1 > >
281 {
282  private:
284  public:
285  Callback(Class* object, typename C1::Method method, ParamType1 param1)
286  : _ICallback< C1 >(C1(object, method, param1)) {}
287 };
288 
289 template < class Class >
290 class Callback < Class > : public _ICallback< _Callback < Class > >
291 {
292  private:
294  public:
295  Callback(Class* object, typename C0::Method method)
296  : _ICallback< C0 >(C0(object, method)) {}
297 };
298 }
299 
300 // QUERY CALLBACKS
301 
302 #include "QueryResult.h"
303 class QueryResult;
304 
305 namespace Oregon
306 {
308 {
309  public:
310  virtual void Execute() = 0;
311  virtual ~IQueryCallback() {}
312  virtual void SetResult(QueryResult_AutoPtr result) = 0;
313  virtual QueryResult_AutoPtr GetResult() = 0;
314 };
315 
316 template < class CB >
317 class _IQueryCallback : public CB, public IQueryCallback
318 {
319  public:
320  _IQueryCallback(CB const& cb) : CB(cb) {}
321  void Execute()
322  {
323  CB::_Execute();
324  }
326  {
327  CB::m_param1 = result;
328  }
330  {
331  return CB::m_param1;
332  }
333 };
334 
335 template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
337  public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > >
338 {
339  private:
341  public:
342  QueryCallback(Class* object, typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
343  : _IQueryCallback< QC3 >(QC3(object, method, result, param1, param2, param3)) {}
344 };
345 
346 template < class Class, typename ParamType1, typename ParamType2 >
347 class QueryCallback < Class, ParamType1, ParamType2 > :
348  public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > >
349 {
350  private:
352  public:
353  QueryCallback(Class* object, typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2)
354  : _IQueryCallback< QC2 >(QC2(object, method, result, param1, param2)) {}
355 };
356 
357 template < class Class, typename ParamType1 >
358 class QueryCallback < Class, ParamType1 > :
359  public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1 > >
360 {
361  private:
363  public:
364  QueryCallback(Class* object, typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1)
365  : _IQueryCallback< QC1 >(QC1(object, method, result, param1)) {}
366 };
367 
368 template < class Class >
369 class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr > >
370 {
371  private:
373  public:
374  QueryCallback(Class* object, typename QC0::Method method, QueryResult_AutoPtr result)
375  : _IQueryCallback< QC0 >(QC0(object, method, result)) {}
376 };
377 
378 // STATICS
379 
380 template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
382  public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > >
383 {
384  private:
386  public:
387  SQueryCallback(typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
388  : _IQueryCallback< QC3 >(QC3(method, result, param1, param2, param3)) {}
389 };
390 
391 template < typename ParamType1, typename ParamType2 >
392 class SQueryCallback < ParamType1, ParamType2 > :
393  public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > >
394 {
395  private:
397  public:
398  SQueryCallback(typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2)
399  : _IQueryCallback< QC2 >(QC2(method, result, param1, param2)) {}
400 };
401 
402 template < typename ParamType1 >
403 class SQueryCallback < ParamType1 > :
404  public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1 > >
405 {
406  private:
408  public:
409  SQueryCallback(typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1)
410  : _IQueryCallback< QC1 >(QC1(method, result, param1)) {}
411 };
412 
413 template < >
414 class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult_AutoPtr > >
415 {
416  private:
418  public:
419  SQueryCallback(QC0::Method method, QueryResult_AutoPtr result)
420  : _IQueryCallback< QC0 >(QC0(method, result)) {}
421 };
422 }
423 
424 #endif
425 
_Callback(Class *object, Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
Definition: Callback.h:41
_SCallback(Method method, ParamType1 param1, ParamType2 param2)
Definition: Callback.h:181
_Callback< Class > C0
Definition: Callback.h:293
_Callback< Class, ParamType1 > C1
Definition: Callback.h:283
_Callback(Class *object, Method method)
Definition: Callback.h:119
_SCallback(_SCallback< ParamType1 > const &cb)
Definition: Callback.h:201
QueryCallback(Class *object, typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2)
Definition: Callback.h:353
_SCallback< QueryResult_AutoPtr > QC0
Definition: Callback.h:417
_SCallback(Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
Definition: Callback.h:142
_SCallback(_SCallback<> const &cb)
Definition: Callback.h:218
_Callback< Class, ParamType1, ParamType2 > C2
Definition: Callback.h:272
_SCallback(_SCallback< ParamType1, ParamType2 > const &cb)
Definition: Callback.h:183
Class * m_object
Definition: Callback.h:30
void(Class::* Method)(ParamType1, ParamType2, ParamType3, ParamType4)
Definition: Callback.h:29
_SCallback< QueryResult_AutoPtr, ParamType1 > QC1
Definition: Callback.h:407
ParamType3 m_param3
Definition: Callback.h:135
_Callback(Class *object, Method method, ParamType1 param1)
Definition: Callback.h:101
_Callback(Class *object, Method method, ParamType1 param1, ParamType2 param2)
Definition: Callback.h:82
_Callback< Class, QueryResult_AutoPtr, ParamType1, ParamType2 > QC2
Definition: Callback.h:351
virtual ~IQueryCallback()
Definition: Callback.h:311
ParamType1 m_param1
Definition: Callback.h:32
Callback(Class *object, typename C0::Method method)
Definition: Callback.h:295
QueryCallback(Class *object, typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
Definition: Callback.h:342
_Callback< Class, ParamType1, ParamType2, ParamType3 > C3
Definition: Callback.h:261
_Callback(Class *object, Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
Definition: Callback.h:62
_Callback(_Callback< Class, ParamType1, ParamType2 > const &cb)
Definition: Callback.h:84
QueryResult_AutoPtr GetResult()
Definition: Callback.h:329
ParamType4 m_param4
Definition: Callback.h:136
Callback(Class *object, typename C4::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
Definition: Callback.h:252
_Callback(_Callback< Class, ParamType1, ParamType2, ParamType3 > const &cb)
Definition: Callback.h:64
ParamType2 m_param2
Definition: Callback.h:134
Callback(Class *object, typename C2::Method method, ParamType1 param1, ParamType2 param2)
Definition: Callback.h:274
void SetResult(QueryResult_AutoPtr result)
Definition: Callback.h:325
Method m_method
Definition: Callback.h:31
_Callback(_Callback< Class > const &cb)
Definition: Callback.h:121
_SCallback(Method method)
Definition: Callback.h:216
_Callback< Class, QueryResult_AutoPtr, ParamType1 > QC1
Definition: Callback.h:362
ParamType2 m_param2
Definition: Callback.h:33
_Callback< Class, QueryResult_AutoPtr > QC0
Definition: Callback.h:372
SQueryCallback(typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
Definition: Callback.h:387
_SCallback(_SCallback< ParamType1, ParamType2, ParamType3 > const &cb)
Definition: Callback.h:164
_SCallback< QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3
Definition: Callback.h:385
void _Execute()
Definition: Callback.h:36
Callback(Class *object, typename C1::Method method, ParamType1 param1)
Definition: Callback.h:285
QueryCallback(Class *object, typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1)
Definition: Callback.h:364
virtual ~ICallback()
Definition: Callback.h:231
_SCallback(_SCallback< ParamType1, ParamType2, ParamType3, ParamType4 > const &cb)
Definition: Callback.h:144
SQueryCallback(typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2)
Definition: Callback.h:398
SQueryCallback(typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1)
Definition: Callback.h:409
_ICallback(CB const &cb)
Definition: Callback.h:238
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
_SCallback< QueryResult_AutoPtr, ParamType1, ParamType2 > QC2
Definition: Callback.h:396
_Callback< Class, ParamType1, ParamType2, ParamType3, ParamType4 > C4
Definition: Callback.h:250
ParamType4 m_param4
Definition: Callback.h:35
SQueryCallback(QC0::Method method, QueryResult_AutoPtr result)
Definition: Callback.h:419
QueryCallback(Class *object, typename QC0::Method method, QueryResult_AutoPtr result)
Definition: Callback.h:374
_Callback(_Callback< Class, ParamType1 > const &cb)
Definition: Callback.h:103
_SCallback(Method method, ParamType1 param1)
Definition: Callback.h:199
_Callback(_Callback< Class, ParamType1, ParamType2, ParamType3, ParamType4 > const &cb)
Definition: Callback.h:43
_IQueryCallback(CB const &cb)
Definition: Callback.h:320
Callback(Class *object, typename C3::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
Definition: Callback.h:263
ParamType3 m_param3
Definition: Callback.h:34
_Callback< Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3
Definition: Callback.h:340
ParamType1 m_param1
Definition: Callback.h:133
_SCallback(Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
Definition: Callback.h:162