TrueReality  v0.1.1912
FunCall.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * The Base of this class has been adopted from the Delta3D engine
6 *
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the Free
9 * Software Foundation; either version 3.0 of the License, or (at your option)
10 * any later version.
11 *
12 * This library 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 Lesser General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * @author Maxim Serebrennik
22 */
23 
24 #pragma once
25 
26 #include <trUtil/TypeList.h>
27 
33 namespace trUtil
34 {
41  // Functor calls helpers
42 
43 
51  template <class TList> struct CallParms;
52  template <>
54  {
56  static inline ParmsListType Make() { return ParmsListType(); }
57  };
58 
66  template <typename P1>
67  struct CallParms<TYPELIST_1(P1)>
68  {
70  static inline ParmsListType Make(P1 p1)
71  {
72  return ParmsListType(p1);
73  }
74  };
75 
84  template <typename P1, typename P2>
85  struct CallParms<TYPELIST_2(P1, P2)>
86  {
88  static inline ParmsListType Make(P1 p1, P2 p2)
89  {
90  return ParmsListType(p1,
92  }
93  };
94 
104  template <typename P1, typename P2, typename P3>
105  struct CallParms<TYPELIST_3(P1, P2, P3)>
106  {
108  static inline ParmsListType Make(P1 p1, P2 p2, P3 p3)
109  {
110  return ParmsListType(p1,
113  }
114  };
115 
126  template <typename P1, typename P2, typename P3, typename P4>
127  struct CallParms<TYPELIST_4(P1, P2, P3, P4)>
128  {
130  static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4)
131  {
132  return ParmsListType(p1,
136  }
137  };
138 
150  template <typename P1, typename P2, typename P3, typename P4, typename P5>
151  struct CallParms<TYPELIST_5(P1, P2, P3, P4, P5)>
152  {
154  static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
155  {
156  return ParmsListType(p1,
161  }
162  };
163 
176  template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
177  struct CallParms<TYPELIST_6(P1, P2, P3, P4, P5, P6)>
178  {
180  static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
181  {
182  return ParmsListType(p1,
188  }
189  };
190 
204  template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
205  struct CallParms<TYPELIST_7(P1, P2, P3, P4, P5, P6, P7)>
206  {
208  static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
209  {
210  return ParmsListType(p1,
216  typename trUtil::TailAt<ParmsListType, 5>::Result(p7)))))));
217  }
218  };
219 
229  template <typename CallType, typename R, class TList> struct FunctorCall;
230  template <typename CallType, typename R>
231  struct FunctorCall<CallType, R, TYPELIST_0()>
232  {
234  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& /*parms*/)
235  {
236  return fun();
237  }
238  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& /*parms*/)
239  {
240  return ((*pobj).*memfun)();
241  }
242  };
243 
253  template <typename CallType, typename R, typename P1>
254  struct FunctorCall<CallType, R, TYPELIST_1(P1)>
255  {
257  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
258  {
259  return fun(trUtil::GetH<0>(parms).value);
260  }
261  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
262  {
263  return ((*pobj).*memfun)(trUtil::GetH<0>(parms).value);
264  }
265  };
266 
277  template <typename CallType, typename R, typename P1, typename P2>
278  struct FunctorCall<CallType, R, TYPELIST_2(P1, P2)>
279  {
281  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
282  {
283  return fun(
284  trUtil::GetH<0>(parms).value,
285  trUtil::GetH<1>(parms).value);
286  }
287  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
288  {
289  return ((*pobj).*memfun)(
290  trUtil::GetH<0>(parms).value,
291  trUtil::GetH<1>(parms).value);
292  }
293  };
294 
306  template <typename CallType, typename R, typename P1, typename P2, typename P3>
307  struct FunctorCall<CallType, R, TYPELIST_3(P1, P2, P3)>
308  {
310  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
311  {
312  return fun(
313  trUtil::GetH<0>(parms).value,
314  trUtil::GetH<1>(parms).value,
315  trUtil::GetH<2>(parms).value);
316  }
317  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
318  {
319  return ((*pobj).*memfun)(
320  trUtil::GetH<0>(parms).value,
321  trUtil::GetH<1>(parms).value,
322  trUtil::GetH<2>(parms).value);
323  }
324  };
325 
338  template <typename CallType, typename R, typename P1, typename P2, typename P3, typename P4>
339  struct FunctorCall<CallType, R, TYPELIST_4(P1, P2, P3, P4)>
340  {
342  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
343  {
344  return fun(
345  trUtil::GetH<0>(parms).value,
346  trUtil::GetH<1>(parms).value,
347  trUtil::GetH<2>(parms).value,
348  trUtil::GetH<3>(parms).value);
349  }
350  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
351  {
352  return ((*pobj).*memfun)(
353  trUtil::GetH<0>(parms).value,
354  trUtil::GetH<1>(parms).value,
355  trUtil::GetH<2>(parms).value,
356  trUtil::GetH<3>(parms).value);
357  }
358  };
359 
373  template <typename CallType, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
374  struct FunctorCall<CallType, R, TYPELIST_5(P1, P2, P3, P4, P5)>
375  {
377  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
378  {
379  return fun(
380  trUtil::GetH<0>(parms).value,
381  trUtil::GetH<1>(parms).value,
382  trUtil::GetH<2>(parms).value,
383  trUtil::GetH<3>(parms).value,
384  trUtil::GetH<4>(parms).value);
385  }
386  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
387  {
388  return ((*pobj).*memfun)(
389  trUtil::GetH<0>(parms).value,
390  trUtil::GetH<1>(parms).value,
391  trUtil::GetH<2>(parms).value,
392  trUtil::GetH<3>(parms).value,
393  trUtil::GetH<4>(parms).value);
394  }
395  };
396 
411  template <typename CallType, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
412  struct FunctorCall<CallType, R, TYPELIST_6(P1, P2, P3, P4, P5, P6)>
413  {
415  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
416  {
417  return fun(
418  trUtil::GetH<0>(parms).value,
419  trUtil::GetH<1>(parms).value,
420  trUtil::GetH<2>(parms).value,
421  trUtil::GetH<3>(parms).value,
422  trUtil::GetH<4>(parms).value,
423  trUtil::GetH<5>(parms).value);
424  }
425  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
426  {
427  return ((*pobj).*memfun)(
428  trUtil::GetH<0>(parms).value,
429  trUtil::GetH<1>(parms).value,
430  trUtil::GetH<2>(parms).value,
431  trUtil::GetH<3>(parms).value,
432  trUtil::GetH<4>(parms).value,
433  trUtil::GetH<5>(parms).value);
434  }
435  };
436 
452  template <typename CallType, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
453  struct FunctorCall<CallType, R, TYPELIST_7(P1, P2, P3, P4, P5, P6, P7)>
454  {
456  template <class Fun> static inline R Call(Fun const& fun, ParmsListType& parms)
457  {
458  return fun(
459  trUtil::GetH<0>(parms).value,
460  trUtil::GetH<1>(parms).value,
461  trUtil::GetH<2>(parms).value,
462  trUtil::GetH<3>(parms).value,
463  trUtil::GetH<4>(parms).value,
464  trUtil::GetH<5>(parms).value,
465  trUtil::GetH<6>(parms).value);
466  }
467  template <class PObj> static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms)
468  {
469  return ((*pobj).*memfun)(
470  trUtil::GetH<0>(parms).value,
471  trUtil::GetH<1>(parms).value,
472  trUtil::GetH<2>(parms).value,
473  trUtil::GetH<3>(parms).value,
474  trUtil::GetH<4>(parms).value,
475  trUtil::GetH<5>(parms).value,
476  trUtil::GetH<6>(parms).value);
477  }
478  };
479 }
static ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
Definition: FunCall.h:208
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:317
static ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4)
Definition: FunCall.h:130
#define TYPELIST_3(T1, T2, T3)
Definition: TypeList.h:132
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:350
#define TYPELIST_5(T1, T2, T3, T4, T5)
Definition: TypeList.h:134
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:386
static ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
Definition: FunCall.h:154
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:377
#define TYPELIST_4(T1, T2, T3, T4)
Definition: TypeList.h:133
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:261
#define TYPELIST_7(T1, T2, T3, T4, T5, T6, T7)
Definition: TypeList.h:136
static ParmsListType Make(P1 p1, P2 p2, P3 p3)
Definition: FunCall.h:108
#define TYPELIST_6(T1, T2, T3, T4, T5, T6)
Definition: TypeList.h:135
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:310
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:287
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:456
#define TYPELIST_0()
Macros that define various lists of Class types.
Definition: TypeList.h:129
static ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
Definition: FunCall.h:180
Namespace that holds various utility classes for the engine.
Definition: SmrtPtr.h:208
static R Call(PObj const &pobj, CallType memfun, ParmsListType &)
Definition: FunCall.h:238
#define TYPELIST_1(T1)
Definition: TypeList.h:130
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:415
static ParmsListType Make(P1 p1, P2 p2)
Definition: FunCall.h:88
#define TYPELIST_2(T1, T2)
Definition: TypeList.h:131
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:342
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:281
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:467
static R Call(Fun const &fun, ParmsListType &)
Definition: FunCall.h:234
static ParmsListType Make(P1 p1)
Definition: FunCall.h:70
static ParmsListType Make()
Definition: FunCall.h:56
static R Call(Fun const &fun, ParmsListType &parms)
Definition: FunCall.h:257
static R Call(PObj const &pobj, CallType memfun, ParmsListType &parms)
Definition: FunCall.h:425