1 // Copyright (c) 2005 Daniel Wallin and Arvid Norberg
2 
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
9 
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
12 
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 #ifndef LUABIND_VALUE_WRAPPER_050419_HPP
24 #define LUABIND_VALUE_WRAPPER_050419_HPP
25 
26 #include <boost/mpl/integral_c.hpp>
27 #include <boost/mpl/bool.hpp>
28 #include <boost/mpl/aux_/msvc_eti_base.hpp>
29 
30 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
31 # define LUABIND_USE_VALUE_WRAPPER_TAG
32 #else
33 #endif
34 
35 #ifdef LUABIND_USE_VALUE_WRAPPER_TAG
36 # include <boost/mpl/identity.hpp>
37 # include <boost/mpl/eval_if.hpp>
38 # include <boost/mpl/has_xxx.hpp>
39 # include <boost/mpl/not.hpp>
40 # include <boost/mpl/and.hpp>
41 # include <boost/mpl/or.hpp>
42 # include <boost/type_traits/is_reference.hpp>
43 # include <boost/type_traits/is_pointer.hpp>
44 # include <boost/type_traits/is_array.hpp>
45 #endif
46 
47 namespace luabind {
48 
49 //
50 // Concept ``ValueWrapper``
51 //
52 
53 #ifdef LUABIND_USE_VALUE_WRAPPER_TAG
54 template<class T>
55 struct value_wrapper_traits;
56 
57 namespace detail
58 {
59 
60   BOOST_MPL_HAS_XXX_TRAIT_DEF(value_wrapper_tag);
61 
62   struct unspecialized_value_wrapper_traits
63   {
64       typedef boost::mpl::false_ is_specialized;
65   };
66 
67   template<class T>
68   struct value_wrapper_traits_aux
69   {
70       typedef value_wrapper_traits<typename T::value_wrapper_tag> type;
71   };
72 
73 } // namespace detail
74 #endif
75 
76 template<class T>
77 struct value_wrapper_traits
78 #ifdef LUABIND_USE_VALUE_WRAPPER_TAG
79   : boost::mpl::eval_if<
80         boost::mpl::and_<
81             boost::mpl::not_<
82                 boost::mpl::or_<
83                     boost::is_reference<T>
84                   , boost::is_pointer<T>
85                   , boost::is_array<T>
86                 >
87             >
88           , detail::has_value_wrapper_tag<T>
89         >
90       , detail::value_wrapper_traits_aux<T>
91       , boost::mpl::identity<detail::unspecialized_value_wrapper_traits>
92     >::type
93 {};
94 #else
95 {
96     typedef boost::mpl::false_ is_specialized;
97 };
98 #endif
99 
100 template<class T>
101 struct is_value_wrapper
102   : boost::mpl::aux::msvc_eti_base<
103         typename value_wrapper_traits<T>::is_specialized
104     >::type
105 {};
106 
107 } // namespace luabind
108 
109 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
110 
111 # include <boost/type_traits/remove_const.hpp>
112 # include <boost/type_traits/remove_reference.hpp>
113 
114 namespace luabind {
115 
116 template<class T>
117 struct is_value_wrapper_arg
118   : is_value_wrapper<
119       typename boost::remove_const<
120           typename boost::remove_reference<T>::type
121       >::type
122     >
123 {};
124 
125 } // namespace luabind
126 
127 #else
128 
129 # include <luabind/detail/yes_no.hpp>
130 # include <boost/type_traits/add_reference.hpp>
131 
132 namespace luabind {
133 
134 namespace detail
135 {
136   template<class T>
137   typename is_value_wrapper<T>::type is_value_wrapper_arg_check(T const*);
138 
139   yes_t to_yesno(boost::mpl::true_);
140   no_t to_yesno(boost::mpl::false_);
141 
142   template<class T>
143   struct is_value_wrapper_arg_aux
144   {
145       static typename boost::add_reference<T>::type x;
146 
147       BOOST_STATIC_CONSTANT(bool, value =
148           sizeof(to_yesno(is_value_wrapper_arg_check(&x)))
149             == sizeof(yes_t)
150       );
151 
152       typedef boost::mpl::bool_<value> type;
153   };
154 
155 } // namespace detail
156 
157 template<class T>
158 struct is_value_wrapper_arg
159   : detail::is_value_wrapper_arg_aux<T>::type
160 {
161 };
162 
163 } // namespace luabind
164 
165 #endif
166 
167 #endif // LUABIND_VALUE_WRAPPER_050419_HPP
168 
169