yet another multi-ABI bundle installer fix
[ardour.git] / libs / lua / LuaBridge / detail / TypeList.h
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   This file incorporates work covered by the following copyright and
29   permission notice:
30
31     The Loki Library
32     Copyright (c) 2001 by Andrei Alexandrescu
33     This code accompanies the book:
34     Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
35         Patterns Applied". Copyright (c) 2001. Addison-Wesley.
36     Permission to use, copy, modify, distribute and sell this software for any
37         purpose is hereby granted without fee, provided that the above copyright
38         notice appear in all copies and that both that copyright notice and this
39         permission notice appear in supporting documentation.
40     The author or Addison-Welsey Longman make no representations about the
41         suitability of this software for any purpose. It is provided "as is"
42         without express or implied warranty.
43 */
44 //==============================================================================
45
46 /**
47   None type means void parameters or return value.
48 */
49 typedef void None;
50
51 template <typename Head, typename Tail = None>
52 struct TypeList
53 {
54 };
55
56 /**
57   A TypeList with actual values.
58 */
59 template <typename List>
60 struct TypeListValues
61 {
62   static std::string const tostring (bool)
63   {
64     return "";
65   }
66 };
67
68 /**
69   TypeListValues recursive template definition.
70 */
71 template <typename Head, typename Tail>
72 struct TypeListValues <TypeList <Head, Tail> >
73 {
74   Head hd;
75   TypeListValues <Tail> tl;
76
77   TypeListValues (Head hd_, TypeListValues <Tail> const& tl_)
78     : hd (hd_), tl (tl_)
79   {
80   }
81
82   static std::string const tostring (bool comma = false)
83   {
84     std::string s;
85
86     if (comma)
87       s = ", ";
88
89     s = s + typeid (Head).name ();
90
91     return s + TypeListValues <Tail>::tostring (true);
92   }
93 };
94
95 // Specializations of type/value list for head types that are references and
96 // const-references.  We need to handle these specially since we can't count
97 // on the referenced object hanging around for the lifetime of the list.
98
99 template <typename Head, typename Tail>
100 struct TypeListValues <TypeList <Head&, Tail> >
101 {
102   Head hd;
103   TypeListValues <Tail> tl;
104
105   TypeListValues (Head& hd_, TypeListValues <Tail> const& tl_)
106     : hd (hd_), tl (tl_)
107   {
108   }
109
110   static std::string const tostring (bool comma = false)
111   {
112     std::string s;
113
114     if (comma)
115       s = ", ";
116
117     s = s + typeid (Head).name () + "&";
118
119     return s + TypeListValues <Tail>::tostring (true);
120   }
121 };
122
123 template <typename Head, typename Tail>
124 struct TypeListValues <TypeList <Head const&, Tail> >
125 {
126   Head hd;
127   TypeListValues <Tail> tl;
128
129   TypeListValues (Head const& hd_, const TypeListValues <Tail>& tl_)
130     : hd (hd_), tl (tl_)
131   {
132   }
133
134   static std::string const tostring (bool comma = false)
135   {
136     std::string s;
137
138     if (comma)
139       s = ", ";
140
141     s = s + typeid (Head).name () + " const&";
142
143     return s + TypeListValues <Tail>::tostring (true);
144   }
145 };
146
147 //==============================================================================
148 /**
149   Subclass of a TypeListValues constructable from the Lua stack.
150 */
151
152 template <typename List, int Start = 1>
153 struct ArgList
154 {
155 };
156
157 template <int Start>
158 struct ArgList <None, Start> : public TypeListValues <None>
159 {
160   ArgList (lua_State*)
161   {
162   }
163 };
164
165 template <typename Head, typename Tail, int Start>
166 struct ArgList <TypeList <Head, Tail>, Start>
167   : public TypeListValues <TypeList <Head, Tail> >
168 {
169   ArgList (lua_State* L)
170     : TypeListValues <TypeList <Head, Tail> > (Stack <Head>::get (L, Start),
171                                             ArgList <Tail, Start + 1> (L))
172   {
173   }
174 };