11 #include <daw/daw_consteval.h>
12 #include <daw/daw_traits.h>
15 #if not __has_include( <boost/describe.hpp> ) and __has_include( <boost/mp11.hpp> )
17 "In order to use daw_json_link_describe.h Boost.Describe and Boost.Mp11 must be available"
20 #include <boost/describe.hpp>
21 #include <boost/mp11.hpp>
31 template<
typename,
typename =
void>
34 namespace describe_impl {
35 template<
typename,
typename>
36 struct describe_member_impl;
40 template<
typename T, std::size_t... Is>
41 struct describe_member_impl<T,
std::index_sequence<Is...>> {
42 static constexpr
char const name[
sizeof...( Is )]{ T::name[Is]... };
45 daw::traits::member_type_of_t<DAW_TYPEOF( T::pointer )>>;
49 using describe_member =
50 describe_member_impl<T, std::make_index_sequence<
51 std::char_traits<char>::length( T::name ) + 1>>;
56 template<
template<
typename...>
typename List,
typename... Ts>
57 struct member_list<List<Ts...>> {
59 using desc_t =
typename describe_member<U>::type;
67 and use_boost_describe_v<T> )
71 boost::describe::describe_members<T, boost::describe::mod_public>;
73 boost::describe::describe_members<T, boost::describe::mod_private>;
75 boost::describe::describe_members<T, boost::describe::mod_protected>;
76 static_assert( boost::mp11::mp_empty<pri_desc_t>::value,
77 "Classes with private member variables are not supported. "
78 "Must use a manual mapping." );
79 static_assert( boost::mp11::mp_empty<pro_desc_t>::value,
80 "Classes with protected member variables are not supported. "
81 "Must use a manual mapping." );
84 using desc_t =
typename describe_impl::describe_member<U>::type;
86 template<
template<
typename...>
typename List,
typename... Ts>
87 static inline constexpr
auto
88 to_json_data_impl( T
const &value, List<Ts...>
const & ) noexcept {
89 return std::forward_as_tuple( value.*Ts::pointer... );
93 using type =
typename describe_impl::member_list<pub_desc_t>::type;
95 static constexpr
auto to_json_data( T
const &value ) noexcept {
96 return to_json_data_impl( value, pub_desc_t{ } );
typename json_details::ensure_mapped_t< json_details::json_deduced_type< T > >::template with_name< Name > json_link
Deduce the json type mapping based on common types and types already mapped.
Customization point traits.
DAW_JSON_REQUIRES(boost::describe::has_describe_members< T >::value and use_boost_describe_v< T >) struct json_data_contract< T >
constexpr bool use_boost_describe_v
Types that use Boost.Describe need to specialize use_boost_describe_v for their type with a bool valu...
Mapping class for JSON data structures to C++. It must be specialized in order to parse to a user cla...