?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. // https://github.com/vinniefalco/LuaBridge
  2. // Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
  3. // Copyright 2007, Nathan Reed
  4. // SPDX-License-Identifier: MIT
  5.  
  6. #pragma once
  7.  
  8. namespace luabridge {
  9.  
  10. namespace detail {
  11.  
  12. /*
  13.  * Constructor generators.  These templates allow you to call operator new and
  14.  * pass the contents of a type/value list to the Constructor.  Like the
  15.  * function pointer containers, these are only defined up to 8 parameters.
  16.  */
  17.  
  18. /** Constructor generators.
  19.  
  20.     These templates call operator new with the contents of a type/value
  21.     list passed to the Constructor with up to 8 parameters. Two versions
  22.     of call() are provided. One performs a regular new, the other performs
  23.     a placement new.
  24. */
  25. template<class T, typename List>
  26. struct Constructor
  27. {
  28. };
  29.  
  30. template<class T>
  31. struct Constructor<T, None>
  32. {
  33.     static T* call(TypeListValues<None> const&) { return new T; }
  34.     static T* call(void* mem, TypeListValues<None> const&) { return new (mem) T; }
  35. };
  36.  
  37. template<class T, class P1>
  38. struct Constructor<T, TypeList<P1>>
  39. {
  40.     static T* call(const TypeListValues<TypeList<P1>>& tvl) { return new T(tvl.hd); }
  41.     static T* call(void* mem, const TypeListValues<TypeList<P1>>& tvl)
  42.     {
  43.         return new (mem) T(tvl.hd);
  44.     }
  45. };
  46.  
  47. template<class T, class P1, class P2>
  48. struct Constructor<T, TypeList<P1, TypeList<P2>>>
  49. {
  50.     static T* call(const TypeListValues<TypeList<P1, TypeList<P2>>>& tvl)
  51.     {
  52.         return new T(tvl.hd, tvl.tl.hd);
  53.     }
  54.     static T* call(void* mem, const TypeListValues<TypeList<P1, TypeList<P2>>>& tvl)
  55.     {
  56.         return new (mem) T(tvl.hd, tvl.tl.hd);
  57.     }
  58. };
  59.  
  60. template<class T, class P1, class P2, class P3>
  61. struct Constructor<T, TypeList<P1, TypeList<P2, TypeList<P3>>>>
  62. {
  63.     static T* call(const TypeListValues<TypeList<P1, TypeList<P2, TypeList<P3>>>>& tvl)
  64.     {
  65.         return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
  66.     }
  67.     static T* call(void* mem, const TypeListValues<TypeList<P1, TypeList<P2, TypeList<P3>>>>& tvl)
  68.     {
  69.         return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
  70.     }
  71. };
  72.  
  73. template<class T, class P1, class P2, class P3, class P4>
  74. struct Constructor<T, TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4>>>>>
  75. {
  76.     static T*
  77.     call(const TypeListValues<TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4>>>>>& tvl)
  78.     {
  79.         return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
  80.     }
  81.     static T*
  82.     call(void* mem,
  83.          const TypeListValues<TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4>>>>>& tvl)
  84.     {
  85.         return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
  86.     }
  87. };
  88.  
  89. template<class T, class P1, class P2, class P3, class P4, class P5>
  90. struct Constructor<T, TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5>>>>>>
  91. {
  92.     static T*
  93.     call(const TypeListValues<TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5>>>>>>&
  94.              tvl)
  95.     {
  96.         return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
  97.     }
  98.     static T*
  99.     call(void* mem,
  100.          const TypeListValues<TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5>>>>>>&
  101.              tvl)
  102.     {
  103.         return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.hd);
  104.     }
  105. };
  106.  
  107. template<class T, class P1, class P2, class P3, class P4, class P5, class P6>
  108. struct Constructor<
  109.     T,
  110.     TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6>>>>>>>
  111. {
  112.     static T*
  113.     call(const TypeListValues<
  114.          TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6>>>>>>>& tvl)
  115.     {
  116.         return new T(tvl.hd,
  117.                      tvl.tl.hd,
  118.                      tvl.tl.tl.hd,
  119.                      tvl.tl.tl.tl.hd,
  120.                      tvl.tl.tl.tl.tl.hd,
  121.                      tvl.tl.tl.tl.tl.tl.hd);
  122.     }
  123.     static T*
  124.     call(void* mem,
  125.          const TypeListValues<
  126.              TypeList<P1, TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6>>>>>>>&
  127.              tvl)
  128.     {
  129.         return new (mem) T(tvl.hd,
  130.                            tvl.tl.hd,
  131.                            tvl.tl.tl.hd,
  132.                            tvl.tl.tl.tl.hd,
  133.                            tvl.tl.tl.tl.tl.hd,
  134.                            tvl.tl.tl.tl.tl.tl.hd);
  135.     }
  136. };
  137.  
  138. template<class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
  139. struct Constructor<
  140.     T,
  141.     TypeList<P1,
  142.              TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6, TypeList<P7>>>>>>>>
  143. {
  144.     static T*
  145.     call(const TypeListValues<TypeList<
  146.              P1,
  147.              TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6, TypeList<P7>>>>>>>>&
  148.              tvl)
  149.     {
  150.         return new T(tvl.hd,
  151.                      tvl.tl.hd,
  152.                      tvl.tl.tl.hd,
  153.                      tvl.tl.tl.tl.hd,
  154.                      tvl.tl.tl.tl.tl.hd,
  155.                      tvl.tl.tl.tl.tl.tl.hd,
  156.                      tvl.tl.tl.tl.tl.tl.tl.hd);
  157.     }
  158.     static T*
  159.     call(void* mem,
  160.          const TypeListValues<TypeList<
  161.              P1,
  162.              TypeList<P2, TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6, TypeList<P7>>>>>>>>&
  163.              tvl)
  164.     {
  165.         return new (mem) T(tvl.hd,
  166.                            tvl.tl.hd,
  167.                            tvl.tl.tl.hd,
  168.                            tvl.tl.tl.tl.hd,
  169.                            tvl.tl.tl.tl.tl.hd,
  170.                            tvl.tl.tl.tl.tl.tl.hd,
  171.                            tvl.tl.tl.tl.tl.tl.tl.hd);
  172.     }
  173. };
  174.  
  175. template<class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
  176. struct Constructor<
  177.     T,
  178.     TypeList<
  179.         P1,
  180.         TypeList<
  181.             P2,
  182.             TypeList<P3, TypeList<P4, TypeList<P5, TypeList<P6, TypeList<P7, TypeList<P8>>>>>>>>>
  183. {
  184.     static T*
  185.     call(const TypeListValues<TypeList<
  186.              P1,
  187.              TypeList<
  188.                  P2,
  189.                  TypeList<P3,
  190.                           TypeList<P4, TypeList<P5, TypeList<P6, TypeList<P7, TypeList<P8>>>>>>>>>&
  191.              tvl)
  192.     {
  193.         return new T(tvl.hd,
  194.                      tvl.tl.hd,
  195.                      tvl.tl.tl.hd,
  196.                      tvl.tl.tl.tl.hd,
  197.                      tvl.tl.tl.tl.tl.hd,
  198.                      tvl.tl.tl.tl.tl.tl.hd,
  199.                      tvl.tl.tl.tl.tl.tl.tl.hd,
  200.                      tvl.tl.tl.tl.tl.tl.tl.tl.hd);
  201.     }
  202.     static T*
  203.     call(void* mem,
  204.          const TypeListValues<TypeList<
  205.              P1,
  206.              TypeList<
  207.                  P2,
  208.                  TypeList<P3,
  209.                           TypeList<P4, TypeList<P5, TypeList<P6, TypeList<P7, TypeList<P8>>>>>>>>>&
  210.              tvl)
  211.     {
  212.         return new (mem) T(tvl.hd,
  213.                            tvl.tl.hd,
  214.                            tvl.tl.tl.hd,
  215.                            tvl.tl.tl.tl.hd,
  216.                            tvl.tl.tl.tl.tl.hd,
  217.                            tvl.tl.tl.tl.tl.tl.hd,
  218.                            tvl.tl.tl.tl.tl.tl.tl.hd,
  219.                            tvl.tl.tl.tl.tl.tl.tl.tl.hd);
  220.     }
  221. };
  222.  
  223. } // namespace detail
  224.  
  225. } // namespace luabridge
  226.