25 namespace json_details::serialization {
26 using policy_list =
typename option_list_impl<
27 options::SerializationFormat, options::IndentationType,
28 options::RestrictedStringOutput, options::NewLineDelimiter,
29 options::OutputTrailingComma>::type;
31 template<
typename Policy,
typename Policies>
32 inline constexpr unsigned basic_policy_bits_start =
33 option_bits_start_impl<Policy, Policies>::template calc<>(
34 std::make_index_sequence<pack_size_v<Policies>>{ } );
36 template<
typename Policy>
37 inline constexpr unsigned policy_bits_start =
38 basic_policy_bits_start<Policy, policy_list>;
40 template<
typename Policy>
41 static constexpr void set_bits_in(
json_options_t &value, Policy e ) {
42 static_assert( is_option_flag<Policy>,
43 "Only registered policy types are allowed" );
44 auto new_bits =
static_cast<unsigned>( e );
45 using mask = daw::constant<(1U << json_option_bits_width<Policy>)-1U>;
46 new_bits &= mask::value;
47 new_bits <<= policy_bits_start<Policy>;
48 value &= ~mask::value;
52 template<
typename Policy,
typename... Policies>
54 Policy pol, Policies... pols ) {
55 static_assert( are_option_flags<Policies...>,
56 "Only registered policy types are allowed" );
58 auto new_bits =
static_cast<unsigned>( pol );
60 daw::constant<( (1U << json_option_bits_width<Policy>)-1U )>;
61 new_bits &= mask::value;
62 new_bits <<= policy_bits_start<Policy>;
63 value &= ~( mask::value << policy_bits_start<Policy> );
65 if constexpr(
sizeof...( Policies ) > 0 ) {
66 if constexpr(
sizeof...( pols ) > 0 ) {
67 return set_bits( value, pols... );
76 template<
typename Policy>
78 static_assert( is_option_flag<Policy>,
79 "Only registered policy types are allowed" );
81 new_bits <<= policy_bits_start<Policy>;
86 struct default_policy_flag_t;
88 template<
typename... Policies>
89 struct default_policy_flag_t<pack_list<Policies...>> {
91 ( set_bits_for<Policies>( default_json_option_value<Policies> ) |
99 default_policy_flag_t<policy_list>::value;
101 template<
typename Policy,
typename Result = Policy>
103 static_assert( is_option_flag<Policy>,
104 "Only registered policy types are allowed" );
105 using mask = daw::constant<( 1U << (policy_bits_start<Policy> +
106 json_option_bits_width<Policy>)) -
108 value &= mask::value;
109 value >>= policy_bits_start<Policy>;
110 return static_cast<Result
>( Policy{ value } );
113 template<options::SerializationFormat, options::IndentationType>
114 inline constexpr std::string_view generate_indent{ };
117 inline constexpr std::string_view generate_indent<
118 options::SerializationFormat::Pretty, options::IndentationType::Tab> =
122 inline constexpr std::string_view
123 generate_indent<options::SerializationFormat::Pretty,
124 options::IndentationType::Space1> =
" ";
127 inline constexpr std::string_view
128 generate_indent<options::SerializationFormat::Pretty,
129 options::IndentationType::Space2> =
" ";
132 inline constexpr std::string_view
133 generate_indent<options::SerializationFormat::Pretty,
134 options::IndentationType::Space3> =
" ";
137 inline constexpr std::string_view
138 generate_indent<options::SerializationFormat::Pretty,
139 options::IndentationType::Space4> =
" ";
142 inline constexpr std::string_view
143 generate_indent<options::SerializationFormat::Pretty,
144 options::IndentationType::Space5> =
" ";
147 inline constexpr std::string_view
148 generate_indent<options::SerializationFormat::Pretty,
149 options::IndentationType::Space8> =
" ";
152 inline constexpr std::string_view
153 generate_indent<options::SerializationFormat::Pretty,
154 options::IndentationType::Space10> =
" ";