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 ) ) {}
82 static constexpr options::SerializationFormat serialization_format =
83 json_details::serialization::get_bits_for<options::SerializationFormat>(
86 static constexpr options::IndentationType indentation_type =
87 json_details::serialization::get_bits_for<options::IndentationType>(
90 static constexpr options::RestrictedStringOutput
91 restricted_string_output = json_details::serialization::get_bits_for<
92 options::RestrictedStringOutput>( PolicyFlags );
94 static constexpr options::NewLineDelimiter newline_delimiter =
95 json_details::serialization::get_bits_for<options::NewLineDelimiter>(
98 static constexpr options::OutputTrailingComma output_trailing_comma =
99 json_details::serialization::get_bits_for<options::OutputTrailingComma>(
103 if constexpr( serialization_format !=
104 options::SerializationFormat::Minified ) {
110 if constexpr( serialization_format !=
111 options::SerializationFormat::Minified ) {
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";
134 if constexpr( serialization_format !=
135 options::SerializationFormat::Minified ) {
140 static constexpr daw::string_view space =
141 serialization_format != options::SerializationFormat::Minified
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 )... );
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
constexpr bool is_serialization_policy_v
constexpr json_options_t serialize_options(Policies... policies)
constexpr WritableOutput & put_output(WritableOutput &out, CharT c)
constexpr WritableOutput & write_output(WritableOutput &out, StringViews const &...svs)
Customization point traits.
DAW_ATTRIB_INLINE constexpr void del_indent()
DAW_ATTRIB_INLINE constexpr WritableType & get()
DAW_ATTRIB_INLINE constexpr serialization_policy operator++(int) &
WritableType * m_writable
DAW_ATTRIB_INLINE constexpr serialization_policy & operator*()
void i_am_a_serialization_policy
DAW_ATTRIB_INLINE constexpr serialization_policy(WritableType &writable)
DAW_ATTRIB_INLINE constexpr void output_newline()
DAW_ATTRIB_INLINE constexpr serialization_policy & operator=(char c)
constexpr void write(ContiguousCharRange const &chr, ContiguousCharRanges const &...chrs)
DAW_ATTRIB_INLINE constexpr WritableType const & get() const
static DAW_ATTRIB_INLINE DAW_CONSTEVAL json_options_t policy_flags()
DAW_ATTRIB_INLINE constexpr void copy_buffer(char const *first, char const *last)
constexpr void put(char c)
DAW_ATTRIB_INLINE constexpr void next_member()
DAW_ATTRIB_INLINE constexpr serialization_policy & operator++()
DAW_ATTRIB_INLINE constexpr void add_indent()
DAW_ATTRIB_INLINE constexpr void output_indent()
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.