value_wrapper.hpp 4.2 KB

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