| 1 | #ifndef BOOST_DESCRIBE_DETAIL_MEMBERS_HPP_INCLUDED |
| 2 | #define BOOST_DESCRIBE_DETAIL_MEMBERS_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2020 Peter Dimov |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // https://www.boost.org/LICENSE_1_0.txt |
| 7 | |
| 8 | #include <boost/describe/modifiers.hpp> |
| 9 | #include <boost/describe/detail/pp_for_each.hpp> |
| 10 | #include <boost/describe/detail/pp_utilities.hpp> |
| 11 | #include <boost/describe/detail/list.hpp> |
| 12 | #include <type_traits> |
| 13 | |
| 14 | namespace boost |
| 15 | { |
| 16 | namespace describe |
| 17 | { |
| 18 | namespace detail |
| 19 | { |
| 20 | |
| 21 | template<class Pm> constexpr unsigned add_static_modifier( Pm ) |
| 22 | { |
| 23 | return std::is_member_pointer<Pm>::value? 0: mod_static; |
| 24 | } |
| 25 | |
| 26 | template<class Pm> constexpr unsigned add_function_modifier( Pm ) |
| 27 | { |
| 28 | return std::is_member_function_pointer<Pm>::value || std::is_function< std::remove_pointer_t<Pm> >::value? mod_function: 0; |
| 29 | } |
| 30 | |
| 31 | template<class D, unsigned M> struct member_descriptor |
| 32 | { |
| 33 | static constexpr decltype(D::pointer()) pointer = D::pointer(); |
| 34 | static constexpr decltype(D::name()) name = D::name(); |
| 35 | static constexpr unsigned modifiers = M | add_static_modifier( D::pointer() ) | add_function_modifier( D::pointer() ); |
| 36 | }; |
| 37 | |
| 38 | #ifndef __cpp_inline_variables |
| 39 | template<class D, unsigned M> constexpr decltype(D::pointer()) member_descriptor<D, M>::pointer; |
| 40 | template<class D, unsigned M> constexpr decltype(D::name()) member_descriptor<D, M>::name; |
| 41 | template<class D, unsigned M> constexpr unsigned member_descriptor<D, M>::modifiers; |
| 42 | #endif |
| 43 | |
| 44 | template<unsigned M, class... T> auto member_descriptor_fn_impl( int, T... ) |
| 45 | { |
| 46 | return list<member_descriptor<T, M>...>(); |
| 47 | } |
| 48 | |
| 49 | template<class C, class F> constexpr auto mfn( F C::* p ) { return p; } |
| 50 | template<class C, class F> constexpr auto mfn( F * p ) { return p; } |
| 51 | |
| 52 | #define BOOST_DESCRIBE_MEMBER_IMPL(C, m) , []{ struct _boost_desc { \ |
| 53 | static constexpr auto pointer() noexcept { return BOOST_DESCRIBE_PP_POINTER(C, m); } \ |
| 54 | static constexpr auto name() noexcept { return BOOST_DESCRIBE_PP_NAME(m); } }; return _boost_desc(); }() |
| 55 | |
| 56 | #if defined(_MSC_VER) && !defined(__clang__) |
| 57 | |
| 58 | #define BOOST_DESCRIBE_PUBLIC_MEMBERS(C, ...) inline auto boost_public_member_descriptor_fn( C** ) \ |
| 59 | { return boost::describe::detail::member_descriptor_fn_impl<boost::describe::mod_public>( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_MEMBER_IMPL, C, __VA_ARGS__) ); } |
| 60 | |
| 61 | #define BOOST_DESCRIBE_PROTECTED_MEMBERS(C, ...) inline auto boost_protected_member_descriptor_fn( C** ) \ |
| 62 | { return boost::describe::detail::member_descriptor_fn_impl<boost::describe::mod_protected>( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_MEMBER_IMPL, C, __VA_ARGS__) ); } |
| 63 | |
| 64 | #define BOOST_DESCRIBE_PRIVATE_MEMBERS(C, ...) inline auto boost_private_member_descriptor_fn( C** ) \ |
| 65 | { return boost::describe::detail::member_descriptor_fn_impl<boost::describe::mod_private>( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_MEMBER_IMPL, C, __VA_ARGS__) ); } |
| 66 | |
| 67 | #else |
| 68 | |
| 69 | #define BOOST_DESCRIBE_PUBLIC_MEMBERS(C, ...) inline auto boost_public_member_descriptor_fn( C** ) \ |
| 70 | { return boost::describe::detail::member_descriptor_fn_impl<boost::describe::mod_public>( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_MEMBER_IMPL, C, ##__VA_ARGS__) ); } |
| 71 | |
| 72 | #define BOOST_DESCRIBE_PROTECTED_MEMBERS(C, ...) inline auto boost_protected_member_descriptor_fn( C** ) \ |
| 73 | { return boost::describe::detail::member_descriptor_fn_impl<boost::describe::mod_protected>( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_MEMBER_IMPL, C, ##__VA_ARGS__) ); } |
| 74 | |
| 75 | #define BOOST_DESCRIBE_PRIVATE_MEMBERS(C, ...) inline auto boost_private_member_descriptor_fn( C** ) \ |
| 76 | { return boost::describe::detail::member_descriptor_fn_impl<boost::describe::mod_private>( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_MEMBER_IMPL, C, ##__VA_ARGS__) ); } |
| 77 | |
| 78 | #endif |
| 79 | |
| 80 | } // namespace detail |
| 81 | } // namespace describe |
| 82 | } // namespace boost |
| 83 | |
| 84 | #endif // #ifndef BOOST_DESCRIBE_DETAIL_MEMBERS_HPP_INCLUDED |
| 85 | |