16 #include <daw/cpp_17.h>
17 #include <daw/daw_attributes.h>
18 #include <daw/daw_string_view.h>
19 #include <daw/daw_traits.h>
20 #include <daw/daw_unreachable.h>
32 case ExecModeTypes::compile_time:
33 return "compile_time";
34 case ExecModeTypes::runtime:
36 case ExecModeTypes::simd:
43 namespace json_details {
45 inline constexpr
unsigned json_option_bits_width<options::ExecModeTypes> =
49 inline constexpr
auto default_json_option_value<options::ExecModeTypes> =
50 options::ExecModeTypes::compile_time;
53 inline constexpr
unsigned
54 json_option_bits_width<options::ZeroTerminatedString> = 1;
58 default_json_option_value<options::ZeroTerminatedString> =
59 options::ZeroTerminatedString::no;
62 inline constexpr
unsigned
63 json_option_bits_width<options::PolicyCommentTypes> = 2;
67 default_json_option_value<options::PolicyCommentTypes> =
68 options::PolicyCommentTypes::none;
71 inline constexpr
unsigned
72 json_option_bits_width<options::CheckedParseMode> = 1;
76 default_json_option_value<options::CheckedParseMode> =
77 options::CheckedParseMode::yes;
80 inline constexpr
unsigned
81 json_option_bits_width<options::MinifiedDocument> = 1;
85 default_json_option_value<options::MinifiedDocument> =
86 options::MinifiedDocument::no;
89 inline constexpr
unsigned
90 json_option_bits_width<options::AllowEscapedNames> = 1;
94 default_json_option_value<options::AllowEscapedNames> =
95 options::AllowEscapedNames::no;
98 inline constexpr
unsigned
99 json_option_bits_width<options::IEEE754Precise> = 1;
102 inline constexpr
auto default_json_option_value<options::IEEE754Precise> =
103 options::IEEE754Precise::no;
106 inline constexpr
unsigned
107 json_option_bits_width<options::ForceFullNameCheck> = 1;
110 inline constexpr
auto
111 default_json_option_value<options::ForceFullNameCheck> =
112 options::ForceFullNameCheck::no;
115 inline constexpr
unsigned
116 json_option_bits_width<options::UseExactMappingsByDefault> = 1;
119 inline constexpr
auto
120 default_json_option_value<options::UseExactMappingsByDefault> =
121 options::UseExactMappingsByDefault::no;
124 inline constexpr
unsigned
125 json_option_bits_width<options::MustVerifyEndOfDataIsValid> = 1;
128 inline constexpr
auto
129 default_json_option_value<options::MustVerifyEndOfDataIsValid> =
130 options::MustVerifyEndOfDataIsValid::no;
133 inline constexpr
unsigned
134 json_option_bits_width<options::ExpectLongNames> = 1;
137 inline constexpr
auto
138 default_json_option_value<options::ExpectLongNames> =
139 options::ExpectLongNames::no;
153 inline constexpr
unsigned
154 json_option_bits_width<options::ExcludeSpecialEscapes> = 1;
157 inline constexpr
auto
158 default_json_option_value<options::ExcludeSpecialEscapes> =
159 options::ExcludeSpecialEscapes::no;
161 using policy_list =
typename option_list_impl<
169 template<
typename Policy,
typename Policies>
170 inline constexpr
unsigned basic_policy_bits_start =
171 option_bits_start_impl<Policy, Policies>::template calc<>(
172 std::make_index_sequence<pack_size_v<Policies>>{ } );
174 template<
typename Policy>
175 inline constexpr
unsigned policy_bits_start =
176 basic_policy_bits_start<Policy, policy_list>;
182 template<
typename PolicyFlag,
184 are_option_flags<PolicyFlag, PolicyFlags...> )>
187 set_bits(
json_options_t value, PolicyFlag pol, PolicyFlags... pols ) {
188 static_assert( are_option_flags<PolicyFlags...>,
189 "Only registered policy types are allowed" );
191 auto new_bits =
static_cast<unsigned>( pol );
192 constexpr
unsigned mask =
193 ( (1U << json_option_bits_width<PolicyFlag>)-1U );
195 new_bits <<= policy_bits_start<PolicyFlag>;
196 value &= ~( mask << policy_bits_start<PolicyFlag> );
198 if constexpr(
sizeof...( PolicyFlags ) > 0 ) {
199 if constexpr(
sizeof...( pols ) > 0 ) {
200 return set_bits( value, pols... );
209 template<
typename Policy>
211 static_assert( is_option_flag<Policy>,
212 "Only registered policy types are allowed" );
214 new_bits <<= policy_bits_start<Policy>;
219 struct default_policy_flag_t;
221 template<
typename... Policies>
222 struct default_policy_flag_t<pack_list<Policies...>> {
224 ( set_bits_for<Policies>( default_json_option_value<Policies> ) |
232 default_policy_flag_t<policy_list>::value;
234 template<
typename Policy,
typename Result = Policy>
236 static_assert( is_option_flag<Policy>,
237 "Only registered policy types are allowed" );
238 constexpr
unsigned mask = ( 1U << (policy_bits_start<Policy> +
239 json_option_bits_width<Policy>)) -
242 value >>= policy_bits_start<Policy>;
243 return static_cast<Result
>( Policy{ value } );
254 template<
typename... Policies>
255 DAW_CONSTEVAL
json_options_t parse_options( Policies... policies ) {
256 static_assert( json_details::are_option_flags<Policies...>,
257 "Only registered policy types are allowed" );
258 auto result = json_details::default_policy_flag;
259 if constexpr(
sizeof...( Policies ) > 0 ) {
260 result |= ( json_details::set_bits_for( policies ) | ... );
#define DAW_JSON_ENABLEIF(...)
constexpr std::string_view to_string(JsonBaseParseTypes pt)
std::uint32_t json_options_t
ZeroTerminatedString
Input is a zero terminated string. If this cannot be detected, you can specify it here....
CheckedParseMode
Enable all structure, buffer, and type checking. The default is yes, but no still does some checking ...
ExpectLongNames
Optimize name hashing for longer strings.
ExcludeSpecialEscapes
Exclude characters under 0x20 that are not explicitly allowed.
ForceFullNameCheck
If the hashes of all members being looked are unique, the lookup of names as they are found in the do...
PolicyCommentTypes
Allow comments in JSON. The supported modes are none, C++ style comments, and # hash style comments....
AllowEscapedNames
Allow the escape character '\' in names. This forces a slower parser and is generally not needed....
MinifiedDocument
When document is minified, it is assumed that there is no whitespace in the document....
MustVerifyEndOfDataIsValid
Continue checking that the data is whitespace or empty after the end of top level object is parsed fr...
IEEE754Precise
Use precise IEEE754 parsing of real numbers. The default is no, and results is much faster parsing wi...
ExecModeTypes
Allow for different optimizations. Currently only the compile_time path is fully supported....
UseExactMappingsByDefault
Set the default parser policy to require all JSON members in the parsed object be 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 >
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.