1#ifndef JSON_SPIRIT_WRITER_TEMPLATE
2#define JSON_SPIRIT_WRITER_TEMPLATE
9#if defined(_MSC_VER) && (_MSC_VER >= 1020)
19#include <boost/io/ios_state.hpp>
27 const char ch =
static_cast< char >( c );
29 if( ch < 10 )
return '0' + ch;
34 template<
class String_type >
37 typedef typename String_type::value_type Char_type;
39 String_type result( 6,
'\\' );
51 template<
typename Char_type,
class String_type >
56 case '"': s += to_str< String_type >(
"\\\"" );
return true;
57 case '\\': s += to_str< String_type >(
"\\\\" );
return true;
58 case '\b': s += to_str< String_type >(
"\\b" );
return true;
59 case '\f': s += to_str< String_type >(
"\\f" );
return true;
60 case '\n': s += to_str< String_type >(
"\\n" );
return true;
61 case '\r': s += to_str< String_type >(
"\\r" );
return true;
62 case '\t': s += to_str< String_type >(
"\\t" );
return true;
68 template<
class String_type >
71 typedef typename String_type::const_iterator Iter_type;
72 typedef typename String_type::value_type Char_type;
76 const Iter_type end( s.end() );
78 for( Iter_type i = s.begin(); i != end; ++i )
80 const Char_type c( *i );
90 const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c );
92 if( !esc_nonascii && iswprint( unsigned_c ) )
98 result += non_printable_to_string< String_type >( unsigned_c );
109 template<
class Value_type,
class Ostream_type >
130 if( precision_of_doubles > 0 )
146 switch( value.type() )
155 default: assert(
false );
166 output( Config_type::get_name( member ) );
space();
173 if( value.is_uint64() )
175 os_ << value.get_uint64();
179 os_ << value.get_int64();
190 os_ << to_str< String_type >( b ?
"true" :
"false" );
200 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
214 template<
class Iter >
231 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
253 for(
typename T::const_iterator i = t.begin(); i != t.end(); ++i )
303 template<
class Value_type,
class Ostream_type >
314 template<
class Value_type >
317 typedef typename Value_type::String_type::value_type Char_type;
319 std::basic_ostringstream< Char_type > os;
321 write_stream( value, os, options, precision_of_doubles );
Definition: json_spirit_writer_template.h:111
static bool contains_composite_elements(const Array_type &arr)
Definition: json_spirit_writer_template.h:198
boost::io::basic_ios_all_saver< Char_type > ios_saver_
Definition: json_spirit_writer_template.h:296
int precision_of_doubles_
Definition: json_spirit_writer_template.h:295
void output(double d)
Definition: json_spirit_writer_template.h:193
void output(const Object_type &obj)
Definition: json_spirit_writer_template.h:159
void output(const Value_type &value)
Definition: json_spirit_writer_template.h:144
Config_type::String_type String_type
Definition: json_spirit_writer_template.h:113
void output_array_or_obj(const T &t, Char_type start_char, Char_type end_char)
Definition: json_spirit_writer_template.h:247
Ostream_type & os_
Definition: json_spirit_writer_template.h:289
void output(const String_type &s)
Definition: json_spirit_writer_template.h:183
Value_type::Config_type Config_type
Definition: json_spirit_writer_template.h:112
Config_type::Object_type Object_type
Definition: json_spirit_writer_template.h:114
void indent()
Definition: json_spirit_writer_template.h:267
bool pretty_
Definition: json_spirit_writer_template.h:291
bool raw_utf8_
Definition: json_spirit_writer_template.h:292
void new_line()
Definition: json_spirit_writer_template.h:282
void output(const Array_type &arr)
Definition: json_spirit_writer_template.h:225
void space()
Definition: json_spirit_writer_template.h:277
bool single_line_arrays_
Definition: json_spirit_writer_template.h:294
String_type::value_type Char_type
Definition: json_spirit_writer_template.h:116
Generator(const Value_type &value, Ostream_type &os, int options, unsigned int precision_of_doubles)
Definition: json_spirit_writer_template.h:121
void output(bool b)
Definition: json_spirit_writer_template.h:188
Object_type::value_type Obj_member_type
Definition: json_spirit_writer_template.h:117
int indentation_level_
Definition: json_spirit_writer_template.h:290
void output_int(const Value_type &value)
Definition: json_spirit_writer_template.h:171
void output_composite_item(Iter i, Iter last)
Definition: json_spirit_writer_template.h:215
bool esc_nonascii_
Definition: json_spirit_writer_template.h:293
Config_type::Array_type Array_type
Definition: json_spirit_writer_template.h:115
Generator & operator=(const Generator &)
void output(const Obj_member_type &member)
Definition: json_spirit_writer_template.h:164
int get_value(const Value &value, Type_to_type< int >)
Definition: json_spirit_value.h:532
Definition: json_spirit_error_position.h:16
bool add_esc_char(Char_type c, String_type &s)
Definition: json_spirit_writer_template.h:52
void write_stream(const Value_type &value, Ostream_type &os, int options=none, unsigned int precision_of_doubles=0)
Definition: json_spirit_writer_template.h:304
String_type add_esc_chars(const String_type &s, bool raw_utf8, bool esc_nonascii)
Definition: json_spirit_writer_template.h:69
Value_type::String_type write_string(const Value_type &value, int options=none, unsigned int precision_of_doubles=0)
Definition: json_spirit_writer_template.h:315
@ none
Definition: json_spirit_writer_options.h:15
@ single_line_arrays
Definition: json_spirit_writer_options.h:26
@ raw_utf8
Definition: json_spirit_writer_options.h:19
@ remove_trailing_zeros
Definition: json_spirit_writer_options.h:24
@ pretty_print
Definition: json_spirit_writer_options.h:17
@ always_escape_nonascii
Definition: json_spirit_writer_options.h:29
char to_hex_char(unsigned int c)
Definition: json_spirit_writer_template.h:23
String_type non_printable_to_string(unsigned int c)
Definition: json_spirit_writer_template.h:35
Value_type
Definition: json_spirit_value.h:33
@ null_type
Definition: json_spirit_value.h:33
@ obj_type
Definition: json_spirit_value.h:33
@ array_type
Definition: json_spirit_value.h:33
@ int_type
Definition: json_spirit_value.h:33
@ str_type
Definition: json_spirit_value.h:33
@ bool_type
Definition: json_spirit_value.h:33
@ real_type
Definition: json_spirit_value.h:33
#define T(string_literal)
Definition: secure_crt.cpp:77