13 #include <daw/daw_function_traits.h>
15 #include <string_view>
17 #include <type_traits>
21 namespace json_details {
22 template<
typename T,
typename =
void>
23 inline constexpr
bool has_call_operator = std::is_function_v<T>;
26 inline constexpr
bool has_call_operator<
27 T, std::void_t<decltype( &std::remove_reference_t<T>::operator( ) )>> =
30 template<
typename Signature,
typename Callable,
31 typename... FromJsonParams>
32 DAW_ATTRIB_INLINE constexpr
auto
33 json_apply_impl( Callable &&callable, FromJsonParams &&...params ) {
34 using func_t =
typename std::conditional_t<
35 std::is_same_v<use_default, Signature>,
36 daw::traits::identity<daw::func::function_traits<Callable>>,
37 daw::traits::identity<daw::func::function_traits<Signature>>>::type;
39 if constexpr( func_t::arity == 1 ) {
40 return DAW_FWD( callable )(
42 typename func_t::template argument<0>::plain_type>(
43 DAW_FWD( params )... ) );
47 daw::json::from_json<typename func_t::plain_params_t>(
48 DAW_FWD( params )... ) );
64 template<
typename Signature = use_default,
typename String,
66 json_details::has_call_operator<Callable> )>
68 constexpr auto
json_apply( String &&json_doc, Callable &&callable ) {
69 return json_details::json_apply_impl<Signature>( DAW_FWD( callable ),
70 DAW_FWD( json_doc ) );
85 template<
typename Signature = use_default,
typename String,
87 json_details::has_call_operator<Callable> )>
89 constexpr auto
json_apply( String &&json_doc,
std::string_view json_path,
90 Callable &&callable ) {
91 return json_details::json_apply_impl<Signature>(
92 DAW_FWD( callable ), DAW_FWD( json_doc ), json_path );
109 template<
typename Signature = use_default,
typename String,
112 json_details::has_call_operator<Callable> )>
115 String &&json_doc,
std::string_view json_path,
116 daw::json::options::parse_flags_t<PolicyFlags...> flags,
117 Callable &&callable ) {
118 return json_details::json_apply_impl<Signature>(
119 DAW_FWD( callable ), DAW_FWD( json_doc ), json_path, flags );
135 template<
typename Signature = use_default,
typename String,
138 json_details::has_call_operator<Callable> )>
142 daw::json::options::parse_flags_t<PolicyFlags...> flags,
143 Callable &&callable ) {
144 return json_details::json_apply_impl<Signature>(
145 DAW_FWD( callable ), DAW_FWD( json_doc ), flags );
#define DAW_JSON_ENABLEIF(...)
constexpr auto from_json(String &&json_data, options::parse_flags_t< PolicyFlags... >)
Construct the JSONMember from the JSON document argument.
constexpr auto json_apply(String &&json_doc, Callable &&callable)
Parse to parameters specified in signature and pass them to Callable for evaluation....
Customization point traits.
DAW_JSON_REQUIRES(boost::describe::has_describe_members< T >::value and use_boost_describe_v< T >) struct json_data_contract< T >
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.