Ardour  9.0-pre0-350-gf17a656217
Constructor.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 /*
3  https://github.com/vinniefalco/LuaBridge
4 
5  Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
6  Copyright 2007, Nathan Reed
7 
8  License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy
11  of this software and associated documentation files (the "Software"), to deal
12  in the Software without restriction, including without limitation the rights
13  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  copies of the Software, and to permit persons to whom the Software is
15  furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included in all
18  copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  SOFTWARE.
27 */
28 //==============================================================================
29 
30 #ifndef LUABRIDGE_CONSTRUCTOR_HEADER
31 #define LUABRIDGE_CONSTRUCTOR_HEADER
32 
33 /*
34 * Constructor generators. These templates allow you to call operator new and
35 * pass the contents of a type/value list to the Constructor. Like the
36 * function pointer containers, these are only defined up to 8 parameters.
37 */
38 
46 template <class T, typename List>
47 struct Constructor {};
48 
49 template <class T>
50 struct Constructor <T, None>
51 {
52  static T* call (TypeListValues <None> const&)
53  {
54  return new T;
55  }
56  static T* call (void* mem, TypeListValues <None> const&)
57  {
58  return new (mem) T;
59  }
60 };
61 
62 template <class T, class P1>
63 struct Constructor <T, TypeList <P1> >
64 {
65  static T* call (const TypeListValues<TypeList <P1> > &tvl)
66  {
67  return new T(tvl.hd);
68  }
69  static T* call (void* mem, const TypeListValues<TypeList <P1> > &tvl)
70  {
71  return new (mem) T(tvl.hd);
72  }
73 };
74 
75 template <class T, class P1, class P2>
76 struct Constructor <T, TypeList <P1, TypeList <P2> > >
77 {
78  static T* call (const TypeListValues<TypeList <P1, TypeList <P2> > > &tvl)
79  {
80  return new T(tvl.hd, tvl.tl.hd);
81  }
82  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2> > > &tvl)
83  {
84  return new (mem) T(tvl.hd, tvl.tl.hd);
85  }
86 };
87 
88 template <class T, class P1, class P2, class P3>
89 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3> > > >
90 {
91  static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
92  TypeList <P3> > > > &tvl)
93  {
94  return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
95  }
96  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
97  TypeList <P3> > > > &tvl)
98  {
99  return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
100  }
101 };
102 
103 template <class T, class P1, class P2, class P3, class P4>
104 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
105  TypeList <P4> > > > >
106 {
107  static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
108  TypeList <P3, TypeList <P4> > > > > &tvl)
109  {
110  return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
111  }
112  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
113  TypeList <P3, TypeList <P4> > > > > &tvl)
114  {
115  return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
116  }
117 };
118 
119 template <class T, class P1, class P2, class P3, class P4,
120  class P5>
121 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
122  TypeList <P4, TypeList <P5> > > > > >
123 {
124  static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
125  TypeList <P3, TypeList <P4, TypeList <P5> > > > > > &tvl)
126  {
127  return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
128  tvl.tl.tl.tl.tl.hd);
129  }
130  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
131  TypeList <P3, TypeList <P4, TypeList <P5> > > > > > &tvl)
132  {
133  return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
134  tvl.tl.tl.tl.tl.hd);
135  }
136 };
137 
138 template <class T, class P1, class P2, class P3, class P4,
139  class P5, class P6>
140 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
141  TypeList <P4, TypeList <P5, TypeList <P6> > > > > > >
142 {
143  static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
144  TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > > &tvl)
145  {
146  return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
147  tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
148  }
149  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
150  TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > > &tvl)
151  {
152  return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
153  tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd);
154  }
155 };
156 
157 template <class T, class P1, class P2, class P3, class P4,
158  class P5, class P6, class P7>
159 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
160  TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7> > > > > > > >
161 {
162  static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
163  TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
164  TypeList <P7> > > > > > > > &tvl)
165  {
166  return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
167  tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
168  tvl.tl.tl.tl.tl.tl.tl.hd);
169  }
170  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
171  TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
172  TypeList <P7> > > > > > > > &tvl)
173  {
174  return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
175  tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
176  tvl.tl.tl.tl.tl.tl.tl.hd);
177  }
178 };
179 
180 template <class T, class P1, class P2, class P3, class P4,
181  class P5, class P6, class P7, class P8>
182 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
183  TypeList <P4, TypeList <P5, TypeList <P6, TypeList <P7,
184  TypeList <P8> > > > > > > > >
185 {
186  static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
187  TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
188  TypeList <P7, TypeList <P8> > > > > > > > > &tvl)
189  {
190  return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
191  tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
192  tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
193  }
194  static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
195  TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
196  TypeList <P7, TypeList <P8> > > > > > > > > &tvl)
197  {
198  return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
199  tvl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.hd,
200  tvl.tl.tl.tl.tl.tl.tl.hd, tvl.tl.tl.tl.tl.tl.tl.tl.hd);
201  }
202 };
203 
204 #endif
void None
Definition: TypeList.h:49
static T * call(void *mem, TypeListValues< None > const &)
Definition: Constructor.h:56
static T * call(TypeListValues< None > const &)
Definition: Constructor.h:52
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4 > > > > > &tvl)
Definition: Constructor.h:112
static T * call(const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4 > > > > > &tvl)
Definition: Constructor.h:107
static T * call(const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5, TypeList< P6, TypeList< P7, TypeList< P8 > > > > > > > > > &tvl)
Definition: Constructor.h:186
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5, TypeList< P6, TypeList< P7, TypeList< P8 > > > > > > > > > &tvl)
Definition: Constructor.h:194
static T * call(const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5 > > > > > > &tvl)
Definition: Constructor.h:124
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5 > > > > > > &tvl)
Definition: Constructor.h:130
static T * call(const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5, TypeList< P6, TypeList< P7 > > > > > > > > &tvl)
Definition: Constructor.h:162
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5, TypeList< P6, TypeList< P7 > > > > > > > > &tvl)
Definition: Constructor.h:170
static T * call(const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5, TypeList< P6 > > > > > > > &tvl)
Definition: Constructor.h:143
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3, TypeList< P4, TypeList< P5, TypeList< P6 > > > > > > > &tvl)
Definition: Constructor.h:149
static T * call(const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3 > > > > &tvl)
Definition: Constructor.h:91
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2, TypeList< P3 > > > > &tvl)
Definition: Constructor.h:96
static T * call(const TypeListValues< TypeList< P1, TypeList< P2 > > > &tvl)
Definition: Constructor.h:78
static T * call(void *mem, const TypeListValues< TypeList< P1, TypeList< P2 > > > &tvl)
Definition: Constructor.h:82
static T * call(const TypeListValues< TypeList< P1 > > &tvl)
Definition: Constructor.h:65
static T * call(void *mem, const TypeListValues< TypeList< P1 > > &tvl)
Definition: Constructor.h:69