37 #ifndef _ARGO_WINDOWS_ 54 m_indent_inc(indent_inc)
58 void unparser::print_indent(
int indent_level)
60 for (
int i = 0; i < indent_level; i++)
67 void unparser::unparse_object(
const json &j,
int indent_level)
69 print_indent(indent_level);
70 m_writer <<
'{' << m_space << m_newline;
74 print_indent(indent_level + m_indent_inc);
75 m_writer <<
'"' << p.first <<
'"' << m_space <<
':' << m_space;
76 if (p.second->get_instance_type() == json::object_e ||
77 p.second->get_instance_type() == json::array_e)
79 m_writer << m_newline;
80 unparse(*(p.second), indent_level + (m_indent_inc * 2));
84 unparse(*(p.second), indent_level + m_indent_inc);
90 m_writer << m_newline;
92 print_indent(indent_level);
93 m_writer << m_space <<
'}';
96 void unparser::unparse_array(
const json &j,
int indent_level)
98 print_indent(indent_level);
99 m_writer <<
'[' << m_space << m_newline;
103 if (i->get_instance_type() != json::object_e &&
104 i->get_instance_type() != json::array_e)
106 print_indent(indent_level + m_indent_inc);
108 unparse(*i, indent_level + m_indent_inc);
111 m_writer <<
',' << m_space;
113 m_writer << m_newline;
115 print_indent(indent_level);
116 m_writer << m_space <<
']';
126 unparse_object(j, indent_level);
129 unparse_array(j, indent_level);
131 case json::boolean_e:
132 m_writer << (static_cast<bool>(j) ?
"true" :
"false");
137 case json::number_int_e:
138 m_writer << static_cast<int>(j);
140 case json::number_double_e:
141 m_writer << static_cast<double>(j);
172 unparser u(w, space, newline, indent, indent_inc);
176 #ifndef _ARGO_WINDOWS_ 186 unparser u(w, space, newline, indent, indent_inc);
200 unparser u(w, space, newline, indent, indent_inc);
206 const string &file_name,
212 ofstream os(file_name);
217 unparser u(w, space, newline, indent, indent_inc);
226 ostream &NAMESPACE::operator<<(ostream &stream,
const json &j)
232 void NAMESPACE::operator<<(
string &s,
const json &j)
const std::string & get_raw_value() const
Simple proxy for write operations on various types of stream.
Base class for all exceptions thrown by the library.
The json_exception class.
A class to write JSON messages to a C++ istream.
static void unparse(std::ostream &o, const json &j, const char *space=" ", const char *newline="", const char *indent=" ", int indent_inc=0)
std::vector< std::unique_ptr< json > > & get_array()
#define NAMESPACE
You can change the namespace of the whole library by changing this value.
Specific class of exceptions for IO errors of various types.
static void save(const json &j, const std::string &file_name, const char *space=" ", const char *newline="", const char *indent=" ", int indent_inc=0)
Internal error - the m_type member variable has an invalid value.
Class to unparse json instances into JSON messages.
Common defs needed everywhere and, as far as is possible, platform specific changes.
Attempt to open file failed.
A derived class of writer that writes to POSIX file descriptors.
A derived class of writer that writes to stdio FILEs.
All json things are represented by instances of this class.
std::map< std::string, std::unique_ptr< json > > & get_object()
static std::unique_ptr< std::string > utf8_to_json_string(const std::string &src)
type get_instance_type() const
The json_io_exception class.