Prevent deadlock when removing routes w/o engine
[ardour.git] / libs / lua / LuaBridge / detail / TypeTraits.h
1 //------------------------------------------------------------------------------
2 /*
3   https://github.com/vinniefalco/LuaBridge
4
5   Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
6
7   License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
8
9   Permission is hereby granted, free of charge, to any person obtaining a copy
10   of this software and associated documentation files (the "Software"), to deal
11   in the Software without restriction, including without limitation the rights
12   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13   copies of the Software, and to permit persons to whom the Software is
14   furnished to do so, subject to the following conditions:
15
16   The above copyright notice and this permission notice shall be included in all
17   copies or substantial portions of the Software.
18
19   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25   SOFTWARE.
26 */
27 //==============================================================================
28
29 #ifndef LUABRIDGE_TYPEINFO_HEADER
30 #define LUABRIDGE_TYPEINFO_HEADER
31
32 //------------------------------------------------------------------------------
33 /**
34     Container traits.
35
36     Unspecialized ContainerTraits has the isNotContainer typedef for SFINAE.
37     All user defined containers must supply an appropriate specialization for
38     ContinerTraits (without the typedef isNotContainer). The containers that
39     come with LuaBridge also come with the appropriate ContainerTraits
40     specialization. See the corresponding declaration for details.
41
42     A specialization of ContainerTraits for some generic type ContainerType
43     looks like this:
44
45         template <class T>
46         struct ContainerTraits <ContainerType <T> >
47         {
48           typedef typename T Type;
49
50           static T* get (ContainerType <T> const& c)
51           {
52             return c.get (); // Implementation-dependent on ContainerType
53           }
54         };
55 */
56 template <class T>
57 struct ContainerTraits
58 {
59   typedef bool isNotContainer;
60 };
61
62 //------------------------------------------------------------------------------
63 /**
64     Type traits.
65
66     Specializations return information about a type.
67 */
68 struct TypeTraits
69 {
70   /** Determine if type T is a container.
71
72       To be considered a container, there must be a specialization of
73       ContainerTraits with the required fields.
74   */
75   template <typename T>
76   class isContainer
77   {
78   private:
79     typedef char yes[1]; // sizeof (yes) == 1
80     typedef char no [2]; // sizeof (no)  == 2
81
82     template <typename C>
83     static no& test (typename C::isNotContainer*);
84
85     template <typename>
86     static yes& test (...);
87
88   public:
89     static const bool value = sizeof (test <ContainerTraits <T> >(0)) == sizeof (yes);
90   };
91
92   /** Determine if T is an enum */
93   template <typename T>
94   class isEnum
95   {
96   public:
97     //static const bool value = std::is_enum<T>::value; // C++11
98     static const bool value = boost::is_enum<T>::value;
99   };
100
101
102   /** Determine if T is const qualified.
103   */
104   /** @{ */
105   template <class T>
106   struct isConst
107   {
108     static bool const value = false;
109   };
110
111   template <class T>
112   struct isConst <T const>
113   {
114     static bool const value = true;
115   };
116   /** @} */
117
118   /** Remove the const qualifier from T.
119   */
120   /** @{ */
121   template <class T>
122   struct removeConst
123   {
124     typedef T Type;
125   };
126
127   template <class T>
128   struct removeConst <T const>
129   {
130     typedef T Type;
131   };
132   /**@}*/
133 };
134
135 #endif