has_member_data.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_HAS_MEMBER_DATA_HPP)
  6. #define BOOST_TTI_HAS_MEMBER_DATA_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/preprocessor/cat.hpp>
  9. #include <boost/tti/detail/ddeftype.hpp>
  10. #include <boost/tti/detail/dmem_data.hpp>
  11. #include <boost/tti/gen/has_member_data_gen.hpp>
  12. /*
  13. The succeeding comments in this file are in doxygen format.
  14. */
  15. /** \file
  16. */
  17. /// A macro which expands to a metafunction which tests whether member data with a particular name and type exists.
  18. /**
  19. BOOST_TTI_TRAIT_HAS_MEMBER_DATA is a macro which expands to a metafunction.
  20. The metafunction tests whether member data with a particular
  21. name and type exists. The macro takes the form of BOOST_TTI_TRAIT_HAS_MEMBER_DATA(trait,name) where
  22. trait = the name of the metafunction. <br/>
  23. name = the name of the inner member data.
  24. BOOST_TTI_TRAIT_HAS_MEMBER_DATA generates a metafunction called "trait" where 'trait' is the macro parameter.
  25. @code
  26. template<class BOOST_TTI_TP_ET,class BOOST_TTI_TP_TYPE>
  27. struct trait
  28. {
  29. static const value = unspecified;
  30. typedef mpl::bool_<true-or-false> type;
  31. };
  32. The metafunction types and return:
  33. BOOST_TTI_TP_ET = the enclosing type in which to look for our 'name'
  34. The enclosing type can be a class, struct, or union.
  35. OR
  36. The type of the member data in the form of a pointer
  37. to member data.
  38. BOOST_TTI_TP_TYPE = (optional) The type of the member data if the first
  39. parameter is the enclosing type.
  40. returns = 'value' is true if the 'name' exists, with the correct data type,
  41. otherwise 'value' is false.
  42. @endcode
  43. */
  44. #define BOOST_TTI_TRAIT_HAS_MEMBER_DATA(trait,name) \
  45. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_DATA(trait,name) \
  46. template<class BOOST_TTI_TP_ET,class BOOST_TTI_TP_TYPE = BOOST_TTI_NAMESPACE::detail::deftype> \
  47. struct trait \
  48. { \
  49. typedef typename \
  50. BOOST_PP_CAT(trait,_detail_hmd) \
  51. < \
  52. BOOST_TTI_TP_ET, \
  53. BOOST_TTI_TP_TYPE \
  54. >::type type; \
  55. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  56. }; \
  57. /**/
  58. /// A macro which expands to a metafunction which tests whether a member data with a particular name and type exists.
  59. /**
  60. BOOST_TTI_HAS_MEMBER_DATA is a macro which expands to a metafunction.
  61. The metafunction tests whether member data with a particular
  62. name and type exists. The macro takes the form of BOOST_TTI_HAS_MEMBER_DATA(name) where
  63. name = the name of the inner member.
  64. BOOST_TTI_HAS_MEMBER_DATA generates a metafunction called "has_member_data_name" where 'name' is the macro parameter.
  65. @code
  66. template<class BOOST_TTI_TP_ET,class BOOST_TTI_TP_TYPE>
  67. struct has_member_data_'name'
  68. {
  69. static const value = unspecified;
  70. typedef mpl::bool_<true-or-false> type;
  71. };
  72. The metafunction types and return:
  73. BOOST_TTI_TP_ET = the enclosing type in which to look for our 'name'.
  74. The enclosing type can be a class, struct, or union.
  75. OR
  76. The type of the member data in the form of a pointer
  77. to member data.
  78. BOOST_TTI_TP_TYPE = (optional) The type of the member data if the first
  79. parameter is the enclosing type.
  80. returns = 'value' is true if the 'name' exists, with the correct data type,
  81. otherwise 'value' is false.
  82. @endcode
  83. */
  84. #define BOOST_TTI_HAS_MEMBER_DATA(name) \
  85. BOOST_TTI_TRAIT_HAS_MEMBER_DATA \
  86. ( \
  87. BOOST_TTI_HAS_MEMBER_DATA_GEN(name), \
  88. name \
  89. ) \
  90. /**/
  91. #endif // BOOST_TTI_HAS_MEMBER_DATA_HPP