30 constexpr daw::string_view
to_string( ExecModeTypes mode ) {
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<
162 options::ExecModeTypes, options::ZeroTerminatedString,
163 options::PolicyCommentTypes, options::CheckedParseMode,
164 options::AllowEscapedNames, options::IEEE754Precise,
165 options::ForceFullNameCheck, options::MinifiedDocument,
166 options::UseExactMappingsByDefault, options::MustVerifyEndOfDataIsValid,
167 options::ExcludeSpecialEscapes, options::ExpectLongNames>::type;
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 ) | ... );