1 //------------------------------------------------------------------------------
3 https://github.com/vinniefalco/LuaBridge
5 Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
6 Copyright 2007, Nathan Reed
8 License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
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:
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
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
28 //==============================================================================
30 #ifndef LUABRIDGE_CONSTRUCTOR_HEADER
31 #define LUABRIDGE_CONSTRUCTOR_HEADER
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.
39 /** Constructor generators.
41 These templates call operator new with the contents of a type/value
42 list passed to the Constructor with up to 8 parameters. Two versions
43 of call() are provided. One performs a regular new, the other performs
46 template <class T, typename List>
47 struct Constructor {};
50 struct Constructor <T, None>
52 static T* call (TypeListValues <None> const&)
56 static T* call (void* mem, TypeListValues <None> const&)
62 template <class T, class P1>
63 struct Constructor <T, TypeList <P1> >
65 static T* call (const TypeListValues<TypeList <P1> > &tvl)
69 static T* call (void* mem, const TypeListValues<TypeList <P1> > &tvl)
71 return new (mem) T(tvl.hd);
75 template <class T, class P1, class P2>
76 struct Constructor <T, TypeList <P1, TypeList <P2> > >
78 static T* call (const TypeListValues<TypeList <P1, TypeList <P2> > > &tvl)
80 return new T(tvl.hd, tvl.tl.hd);
82 static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2> > > &tvl)
84 return new (mem) T(tvl.hd, tvl.tl.hd);
88 template <class T, class P1, class P2, class P3>
89 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3> > > >
91 static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
92 TypeList <P3> > > > &tvl)
94 return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
96 static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
97 TypeList <P3> > > > &tvl)
99 return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd);
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> > > > >
107 static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
108 TypeList <P3, TypeList <P4> > > > > &tvl)
110 return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
112 static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
113 TypeList <P3, TypeList <P4> > > > > &tvl)
115 return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd);
119 template <class T, class P1, class P2, class P3, class P4,
121 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
122 TypeList <P4, TypeList <P5> > > > > >
124 static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
125 TypeList <P3, TypeList <P4, TypeList <P5> > > > > > &tvl)
127 return new T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
130 static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
131 TypeList <P3, TypeList <P4, TypeList <P5> > > > > > &tvl)
133 return new (mem) T(tvl.hd, tvl.tl.hd, tvl.tl.tl.hd, tvl.tl.tl.tl.hd,
138 template <class T, class P1, class P2, class P3, class P4,
140 struct Constructor <T, TypeList <P1, TypeList <P2, TypeList <P3,
141 TypeList <P4, TypeList <P5, TypeList <P6> > > > > > >
143 static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
144 TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > > &tvl)
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);
149 static T* call (void* mem, const TypeListValues<TypeList <P1, TypeList <P2,
150 TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6> > > > > > > &tvl)
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);
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> > > > > > > >
162 static T* call (const TypeListValues<TypeList <P1, TypeList <P2,
163 TypeList <P3, TypeList <P4, TypeList <P5, TypeList <P6,
164 TypeList <P7> > > > > > > > &tvl)
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);
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)
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);
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> > > > > > > > >
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)
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);
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)
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);