17 #include <rapidjson/prettywriter.h>
18 #include <rapidjson/stringbuffer.h>
23 namespace ns_rapidjson
37 explicit Writer(
const std::string &file_name)
40 output_stream_ = &config_ofs_;
41 document_.SetObject();
45 explicit Writer(std::ostream &output_stream)
47 output_stream_ = &output_stream;
48 document_.SetObject();
58 namespace ns_rapidjson
74 ::rapidjson::StringBuffer buffer;
75 ::rapidjson::PrettyWriter< ::rapidjson::StringBuffer> writer(buffer);
76 impl_->document_.Accept(writer);
77 *
impl_->output_stream_ << buffer.GetString() << std::endl;
78 impl_->output_stream_->flush();
84 impl_->getRawNode().SetObject();
91 ::rapidjson::Value key(map_name.c_str(),
impl_->document_.GetAllocator());
92 ::rapidjson::Value value;
93 impl_->getRawNode().AddMember(key, value,
impl_->document_.GetAllocator());
97 const ::rapidjson::Value::MemberIterator child = --(
impl_->getRawNode().MemberEnd());
103 impl_->node_stack_.pop_back();
109 ARILES2_TRACE_FUNCTION;
110 impl_->getRawNode().SetArray();
111 impl_->getRawNode().Reserve(size,
impl_->document_.GetAllocator());
112 for (std::size_t i = 0; i < size; ++i)
114 ::rapidjson::Value value;
115 impl_->getRawNode().PushBack(value,
impl_->document_.GetAllocator());
122 ARILES2_TRACE_FUNCTION;
124 impl_->node_stack_.back().index_ <
impl_->node_stack_.back().size_,
125 "Internal error: namevalue.has more elements than expected.");
130 ARILES2_TRACE_FUNCTION;
131 ARILES2_ASSERT(
true ==
impl_->node_stack_.back().isArray(),
"Internal error: expected array.");
132 ++
impl_->node_stack_.back().index_;
137 ARILES2_TRACE_FUNCTION;
138 impl_->node_stack_.pop_back();
149 impl_->getRawNode().SetString(element.c_str(),
impl_->document_.GetAllocator());
154 impl_->getRawNode().SetBool(element);
160 if (
true == param.fallback_to_string_floats_)
162 impl_->getRawNode().SetString(
163 boost::lexical_cast<std::string>(element).c_str(),
impl_->document_.GetAllocator());
167 impl_->getRawNode().SetDouble(element);
175 if (
true == param.fallback_to_string_floats_)
177 impl_->getRawNode().SetString(
178 boost::lexical_cast<std::string>(element).c_str(),
impl_->document_.GetAllocator());
182 impl_->getRawNode().SetDouble(element);
188 #define ARILES2_BASIC_TYPE(type) \
189 void Writer::writeElement(const type &element, const Parameters &) \
191 impl_->getRawNode().SetInt64(element); \
196 #undef ARILES2_BASIC_TYPE
199 #define ARILES2_BASIC_TYPE(type) \
200 void Writer::writeElement(const type &element, const Parameters &) \
202 impl_->getRawNode().SetUint64(element); \
207 #undef ARILES2_BASIC_TYPE