dmem_data.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // (C) Copyright Edward Diener 2011,2012,2013
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_TTI_DETAIL_MEM_DATA_HPP)
  6. #define BOOST_TTI_DETAIL_MEM_DATA_HPP
  7. #include <boost/detail/workaround.hpp>
  8. #include <boost/function_types/components.hpp>
  9. #include <boost/function_types/is_member_object_pointer.hpp>
  10. #include <boost/mpl/assert.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/mpl/eval_if.hpp>
  13. #include <boost/mpl/identity.hpp>
  14. #include <boost/preprocessor/cat.hpp>
  15. #include <boost/tti/detail/ddeftype.hpp>
  16. #include <boost/tti/detail/dftclass.hpp>
  17. #include <boost/tti/detail/denclosing_type.hpp>
  18. #include <boost/tti/gen/namespace_gen.hpp>
  19. #include <boost/type_traits/detail/yes_no_type.hpp>
  20. #include <boost/type_traits/is_same.hpp>
  21. #include <boost/type_traits/remove_const.hpp>
  22. #if defined(BOOST_MSVC) || (BOOST_WORKAROUND(BOOST_GCC, >= 40400) && BOOST_WORKAROUND(BOOST_GCC, < 40600))
  23. #define BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_OP(trait,name) \
  24. template<class BOOST_TTI_DETAIL_TP_T,class BOOST_TTI_DETAIL_TP_C> \
  25. struct BOOST_PP_CAT(trait,_detail_hmd_op) \
  26. { \
  27. template<class> \
  28. struct return_of; \
  29. \
  30. template<class BOOST_TTI_DETAIL_TP_R,class BOOST_TTI_DETAIL_TP_IC> \
  31. struct return_of<BOOST_TTI_DETAIL_TP_R BOOST_TTI_DETAIL_TP_IC::*> \
  32. { \
  33. typedef BOOST_TTI_DETAIL_TP_R type; \
  34. }; \
  35. \
  36. template<bool,typename BOOST_TTI_DETAIL_TP_U> \
  37. struct menable_if; \
  38. \
  39. template<typename BOOST_TTI_DETAIL_TP_U> \
  40. struct menable_if<true,BOOST_TTI_DETAIL_TP_U> \
  41. { \
  42. typedef BOOST_TTI_DETAIL_TP_U type; \
  43. }; \
  44. \
  45. template<typename BOOST_TTI_DETAIL_TP_U,typename BOOST_TTI_DETAIL_TP_V> \
  46. static ::boost::type_traits::yes_type check2(BOOST_TTI_DETAIL_TP_V BOOST_TTI_DETAIL_TP_U::*); \
  47. \
  48. template<typename BOOST_TTI_DETAIL_TP_U,typename BOOST_TTI_DETAIL_TP_V> \
  49. static ::boost::type_traits::no_type check2(BOOST_TTI_DETAIL_TP_U); \
  50. \
  51. template<typename BOOST_TTI_DETAIL_TP_U,typename BOOST_TTI_DETAIL_TP_V> \
  52. static typename \
  53. menable_if \
  54. < \
  55. sizeof(check2<BOOST_TTI_DETAIL_TP_U,BOOST_TTI_DETAIL_TP_V>(&BOOST_TTI_DETAIL_TP_U::name))==sizeof(::boost::type_traits::yes_type), \
  56. ::boost::type_traits::yes_type \
  57. > \
  58. ::type \
  59. has_matching_member(int); \
  60. \
  61. template<typename BOOST_TTI_DETAIL_TP_U,typename BOOST_TTI_DETAIL_TP_V> \
  62. static ::boost::type_traits::no_type has_matching_member(...); \
  63. \
  64. template<class BOOST_TTI_DETAIL_TP_U,class BOOST_TTI_DETAIL_TP_V> \
  65. struct ttc_md \
  66. { \
  67. typedef boost::mpl::bool_<sizeof(has_matching_member<BOOST_TTI_DETAIL_TP_V,typename return_of<BOOST_TTI_DETAIL_TP_U>::type>(0))==sizeof(::boost::type_traits::yes_type)> type; \
  68. }; \
  69. \
  70. typedef typename ttc_md<BOOST_TTI_DETAIL_TP_T,BOOST_TTI_DETAIL_TP_C>::type type; \
  71. \
  72. }; \
  73. /**/
  74. #else // !defined(BOOST_MSVC)
  75. #include <boost/tti/detail/dmem_fun.hpp>
  76. #define BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_OP(trait,name) \
  77. BOOST_TTI_DETAIL_TRAIT_HAS_TYPES_MEMBER_FUNCTION(trait,name) \
  78. template<class BOOST_TTI_DETAIL_TP_T,class BOOST_TTI_DETAIL_TP_C> \
  79. struct BOOST_PP_CAT(trait,_detail_hmd_op) : \
  80. BOOST_PP_CAT(trait,_detail_hmf_types)<BOOST_TTI_DETAIL_TP_T,BOOST_TTI_DETAIL_TP_C> \
  81. { \
  82. }; \
  83. /**/
  84. #endif // defined(BOOST_MSVC)
  85. #define BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_INVOKE_ENCLOSING_CLASS(trait) \
  86. template<class BOOST_TTI_DETAIL_TP_ET,class BOOST_TTI_DETAIL_TP_TYPE> \
  87. struct BOOST_PP_CAT(trait,_detail_hmd_invoke_enclosing_class) : \
  88. BOOST_PP_CAT(trait,_detail_hmd_op) \
  89. < \
  90. typename BOOST_TTI_NAMESPACE::detail::ptmd<BOOST_TTI_DETAIL_TP_ET,BOOST_TTI_DETAIL_TP_TYPE>::type, \
  91. typename boost::remove_const<BOOST_TTI_DETAIL_TP_ET>::type \
  92. > \
  93. { \
  94. }; \
  95. /**/
  96. #define BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_INVOKE_PT_MEMBER(trait) \
  97. template<class BOOST_TTI_DETAIL_TP_ET,class BOOST_TTI_DETAIL_TP_TYPE> \
  98. struct BOOST_PP_CAT(trait,_detail_hmd_invoke_pt_member) : \
  99. BOOST_PP_CAT(trait,_detail_hmd_op) \
  100. < \
  101. typename BOOST_TTI_NAMESPACE::detail::dmem_get_type<BOOST_TTI_DETAIL_TP_ET,BOOST_TTI_DETAIL_TP_TYPE>::type, \
  102. typename boost::remove_const \
  103. < \
  104. typename BOOST_TTI_NAMESPACE::detail::dmem_get_enclosing<BOOST_TTI_DETAIL_TP_ET,BOOST_TTI_DETAIL_TP_TYPE>::type \
  105. >::type \
  106. > \
  107. { \
  108. }; \
  109. /**/
  110. #define BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_WITH_ENCLOSING_CLASS(trait) \
  111. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_INVOKE_ENCLOSING_CLASS(trait) \
  112. template<class BOOST_TTI_DETAIL_TP_ET,class BOOST_TTI_DETAIL_TP_TYPE> \
  113. struct BOOST_PP_CAT(trait,_detail_hmd_with_enclosing_class) : \
  114. boost::mpl::eval_if \
  115. < \
  116. BOOST_TTI_NAMESPACE::detail::enclosing_type<BOOST_TTI_DETAIL_TP_ET>, \
  117. BOOST_PP_CAT(trait,_detail_hmd_invoke_enclosing_class) \
  118. < \
  119. BOOST_TTI_DETAIL_TP_ET, \
  120. BOOST_TTI_DETAIL_TP_TYPE \
  121. >, \
  122. boost::mpl::false_ \
  123. > \
  124. { \
  125. }; \
  126. /**/
  127. #define BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA(trait,name) \
  128. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_OP(trait,name) \
  129. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_WITH_ENCLOSING_CLASS(trait) \
  130. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA_INVOKE_PT_MEMBER(trait) \
  131. template<class BOOST_TTI_DETAIL_TP_ET,class BOOST_TTI_DETAIL_TP_TYPE> \
  132. struct BOOST_PP_CAT(trait,_detail_hmd) : \
  133. boost::mpl::eval_if \
  134. < \
  135. boost::is_same<BOOST_TTI_DETAIL_TP_TYPE,BOOST_TTI_NAMESPACE::detail::deftype>, \
  136. BOOST_PP_CAT(trait,_detail_hmd_invoke_pt_member) \
  137. < \
  138. BOOST_TTI_DETAIL_TP_ET, \
  139. BOOST_TTI_DETAIL_TP_TYPE \
  140. >, \
  141. BOOST_PP_CAT(trait,_detail_hmd_with_enclosing_class) \
  142. < \
  143. BOOST_TTI_DETAIL_TP_ET, \
  144. BOOST_TTI_DETAIL_TP_TYPE \
  145. > \
  146. > \
  147. { \
  148. }; \
  149. /**/
  150. namespace boost
  151. {
  152. namespace tti
  153. {
  154. namespace detail
  155. {
  156. template<class BOOST_TTI_DETAIL_TP_T,class BOOST_TTI_DETAIL_TP_R>
  157. struct ptmd
  158. {
  159. typedef BOOST_TTI_DETAIL_TP_R BOOST_TTI_DETAIL_TP_T::* type;
  160. };
  161. template<class BOOST_TTI_DETAIL_TP_T>
  162. struct dmem_check_ptmd :
  163. boost::mpl::identity<BOOST_TTI_DETAIL_TP_T>
  164. {
  165. BOOST_MPL_ASSERT((boost::function_types::is_member_object_pointer<BOOST_TTI_DETAIL_TP_T>));
  166. };
  167. template<class BOOST_TTI_DETAIL_TP_T>
  168. struct dmem_check_ptec :
  169. BOOST_TTI_NAMESPACE::detail::class_type<BOOST_TTI_DETAIL_TP_T>
  170. {
  171. BOOST_MPL_ASSERT((boost::function_types::is_member_object_pointer<BOOST_TTI_DETAIL_TP_T>));
  172. };
  173. template<class BOOST_TTI_DETAIL_TP_T,class BOOST_TTI_DETAIL_TP_T2>
  174. struct dmem_get_type :
  175. boost::mpl::eval_if
  176. <
  177. boost::is_same<BOOST_TTI_DETAIL_TP_T2,BOOST_TTI_NAMESPACE::detail::deftype>,
  178. BOOST_TTI_NAMESPACE::detail::dmem_check_ptmd<BOOST_TTI_DETAIL_TP_T>,
  179. BOOST_TTI_NAMESPACE::detail::ptmd<BOOST_TTI_DETAIL_TP_T,BOOST_TTI_DETAIL_TP_T2>
  180. >
  181. {
  182. };
  183. template<class BOOST_TTI_DETAIL_TP_T,class BOOST_TTI_DETAIL_TP_T2>
  184. struct dmem_get_enclosing :
  185. boost::mpl::eval_if
  186. <
  187. boost::is_same<BOOST_TTI_DETAIL_TP_T2,BOOST_TTI_NAMESPACE::detail::deftype>,
  188. BOOST_TTI_NAMESPACE::detail::dmem_check_ptec<BOOST_TTI_DETAIL_TP_T>,
  189. boost::mpl::identity<BOOST_TTI_DETAIL_TP_T>
  190. >
  191. {
  192. };
  193. }
  194. }
  195. }
  196. #endif // BOOST_TTI_DETAIL_MEM_DATA_HPP