1 #ifndef JSON_SPIRIT_WRITER_TEMPLATE
2 #define JSON_SPIRIT_WRITER_TEMPLATE
21 const char ch =
static_cast< char >( c );
23 if( ch < 10 )
return '0' + ch;
28 template<
class String_type >
34 String_type result( 6,
'\\' );
46 template<
typename Char_type,
class String_type >
51 case '"': s += to_str< String_type >(
"\\\"" );
return true;
52 case '\\': s += to_str< String_type >(
"\\\\" );
return true;
53 case '\b': s += to_str< String_type >(
"\\b" );
return true;
54 case '\f': s += to_str< String_type >(
"\\f" );
return true;
55 case '\n': s += to_str< String_type >(
"\\n" );
return true;
56 case '\r': s += to_str< String_type >(
"\\r" );
return true;
57 case '\t': s += to_str< String_type >(
"\\t" );
return true;
63 template<
class String_type >
66 typedef typename String_type::const_iterator Iter_type;
67 typedef typename String_type::value_type Char_type;
71 const Iter_type end( s.end() );
73 for( Iter_type i = s.begin(); i != end; ++i )
75 const Char_type c( *i );
79 const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c );
81 if( iswprint( unsigned_c ) )
87 result += non_printable_to_string< String_type >( unsigned_c );
97 template<
class Value_type,
class Ostream_type >
121 switch( value.type() )
130 case real_type:
os_ << std::showpoint << std::fixed << std::setprecision(8)
131 << value.get_real();
break;
134 default: assert(
false );
148 void output(
const Obj_member_type& member )
150 output( Config_type::get_name( member ) );
space();
157 if( value.is_uint64() )
159 os_ << value.get_uint64();
163 os_ << value.get_int64();
174 os_ << to_str< String_type >( b ?
"true" :
"false" );
184 for(
typename T::const_iterator i = t.begin(); i != t.end(); ++i )
188 typename T::const_iterator
next = i;
190 if( ++next != t.end())
230 template<
class Value_type,
class Ostream_type >
236 template<
class Value_type >
239 typedef typename Value_type::String_type::value_type Char_type;
241 std::basic_ostringstream< Char_type > os;
String_type non_printable_to_string(unsigned int c)
String_type::value_type Char_type
void output(const Obj_member_type &member)
void output_array_or_obj(const T &t, Char_type start_char, Char_type end_char)
void output_int(const Value_type &value)
Config_type::Array_type Array_type
Config_type::String_type String_type
void output(const Value_type &value)
void write_stream(const Value_type &value, Ostream_type &os, bool pretty)
Object_type::value_type Obj_member_type
bool add_esc_char(Char_type c, String_type &s)
char to_hex_char(unsigned int c)
void output(const Object_type &obj)
Generator(const Value_type &value, Ostream_type &os, bool pretty)
int get_value(const Value &value, Type_to_type< int >)
void output(const Array_type &arr)
Config_type::Object_type Object_type
Value_type::String_type write_string(const Value_type &value, bool pretty)
void output(const String_type &s)
String_type add_esc_chars(const String_type &s)
Value_type::Config_type Config_type
Generator & operator=(const Generator &)