19 #include <daw/daw_move.h>
33 template<
typename... Policies>
35 static_assert( json_details::are_option_flags<Policies...>,
36 "Only registered policy types are allowed" );
37 auto result = json_details::serialization::default_policy_flag;
38 if constexpr(
sizeof...( Policies ) > 0 ) {
40 ( json_details::serialization::set_bits_for( policies ) | ... );
44 namespace json_details {
46 DAW_ATTRIB_INLINE constexpr daw::string_view as_sv( T
const &value ) {
47 if constexpr( std::is_same_v<
char, DAW_TYPEOF( value )> ) {
48 return daw::string_view( &value, 1 );
50 return daw::string_view( value );
55 template<
typename WritableType,
57 json_details::serialization::default_policy_flag>
60 concepts::is_writable_output_type_v<WritableType>,
61 "Output type does not have a writeable_output_trait specialization" );
69 std::size_t indentation_level = 0;
71 DAW_ATTRIB_INLINE constexpr WritableType
const &
get( )
const {
75 DAW_ATTRIB_INLINE constexpr WritableType &
get( ) {
80 : m_writable(
std::addressof( writable ) ) {}
83 json_details::serialization::get_bits_for<options::SerializationFormat>(
87 json_details::serialization::get_bits_for<options::IndentationType>(
91 restricted_string_output = json_details::serialization::get_bits_for<
95 json_details::serialization::get_bits_for<options::NewLineDelimiter>(
99 json_details::serialization::get_bits_for<options::OutputTrailingComma>(
102 DAW_ATTRIB_INLINE constexpr
void add_indent( ) {
103 if constexpr( serialization_format !=
104 options::SerializationFormat::Minified ) {
109 DAW_ATTRIB_INLINE constexpr
void del_indent( ) {
110 if constexpr( serialization_format !=
111 options::SerializationFormat::Minified ) {
116 DAW_ATTRIB_INLINE constexpr
void output_indent( ) {
117 if constexpr( serialization_format !=
118 options::SerializationFormat::Minified ) {
119 constexpr std::string_view indent =
120 json_details::serialization::generate_indent<serialization_format,
122 if( not indent.empty( ) ) {
123 for( std::size_t n = 0; n < indentation_level; ++n ) {
130 static constexpr std::string_view newline =
131 newline_delimiter == options::NewLineDelimiter::n ?
"\n" :
"\r\n";
133 DAW_ATTRIB_INLINE constexpr
void output_newline( ) {
134 if constexpr( serialization_format !=
135 options::SerializationFormat::Minified ) {
140 static constexpr daw::string_view space =
141 serialization_format != options::SerializationFormat::Minified
145 DAW_ATTRIB_INLINE constexpr
void next_member( ) {
150 template<
typename ContiguousCharRange,
typename... ContiguousCharRanges>
151 DAW_ATTRIB_FLATINLINE constexpr
void
152 write( ContiguousCharRange
const &chr,
153 ContiguousCharRanges
const &...chrs ) {
156 json_details::as_sv( chrs )... );
159 DAW_ATTRIB_INLINE constexpr
void copy_buffer(
char const *first,
162 daw::string_view( first,
static_cast<std::size_t
>( last - first ) ) );
165 DAW_ATTRIB_FLATINLINE constexpr
void put(
char c ) {
187 template<
typename,
typename...>
190 template<
typename OutputIterator, json_options_t PolicyFlags>
std::uint32_t json_options_t
SerializationFormat
Choose whether to produce minified or pretty output.
NewLineDelimiter
When Pretty mode is enabled, set how newlines are expressed.
IndentationType
When Pretty mode is enabled, choose the indentation type.
OutputTrailingComma
When outputting arrays, followitem with a comma.
RestrictedStringOutput
Allow for restricting the output of strings to 7bits.
constexpr bool is_serialization_policy_v
constexpr json_options_t serialize_options(Policies... policies)
constexpr decltype(auto) get(basic_json_pair< PolicyFlags, Allocator > const &parse_state)
constexpr WritableOutput & put_output(WritableOutput &out, CharT c)
constexpr WritableOutput & write_output(WritableOutput &out, StringViews const &...svs)
Customization point traits.
WritableType * m_writable
void i_am_a_serialization_policy
constexpr void write(ContiguousCharRange const &chr, ContiguousCharRanges const &...chrs)
static DAW_ATTRIB_INLINE DAW_CONSTEVAL json_options_t policy_flags()
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.