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
75 ::rapidjson::StringBuffer buffer;
76 ::rapidjson::PrettyWriter< ::rapidjson::StringBuffer> writer(buffer);
77 impl_->document_.Accept(writer);
78 *
impl_->output_stream_ << buffer.GetString() << std::endl;
79 impl_->output_stream_->flush();
86 ::rapidjson::Value key(map_name.c_str(),
impl_->document_.GetAllocator());
87 ::rapidjson::Value value;
88 impl_->getRawNode().AddMember(key, value,
impl_->document_.GetAllocator());
92 const ::rapidjson::Value::MemberIterator child = --(
impl_->getRawNode().MemberEnd());
98 impl_->node_stack_.pop_back();
104 impl_->getRawNode().SetObject();
113 impl_->getRawNode().SetArray();
114 impl_->getRawNode().Reserve(size,
impl_->document_.GetAllocator());
115 for (std::size_t i = 0; i < size; ++i)
117 ::rapidjson::Value value;
118 impl_->getRawNode().PushBack(value,
impl_->document_.GetAllocator());
125 ARILES_ASSERT(
true ==
impl_->node_stack_.back().isArray(),
"Internal error: expected array.");
127 impl_->node_stack_.back().index_ <
impl_->node_stack_.back().size_,
128 "Internal error: array has more elements than expected.");
129 ++
impl_->node_stack_.back().index_;
134 impl_->node_stack_.pop_back();
143 void Writer::writeElement(
const std::string &element)
145 impl_->getRawNode().SetString(element.c_str(),
impl_->document_.GetAllocator());
148 void Writer::writeElement(
const bool &element)
150 impl_->getRawNode().SetBool(element);
154 void Writer::writeElement(
const float &element)
158 impl_->getRawNode().SetDouble(element);
163 impl_->getRawNode().SetString(
164 boost::lexical_cast<std::string>(element).c_str(),
impl_->document_.GetAllocator());
169 void Writer::writeElement(
const double &element)
173 impl_->getRawNode().SetDouble(element);
177 impl_->getRawNode().SetString(
178 boost::lexical_cast<std::string>(element).c_str(),
impl_->document_.GetAllocator());
184 #define ARILES_BASIC_TYPE(type) \ 185 void Writer::writeElement(const type &element) \ 187 impl_->getRawNode().SetInt64(element); \ 192 #undef ARILES_BASIC_TYPE 195 #define ARILES_BASIC_TYPE(type) \ 196 void Writer::writeElement(const type &element) \ 198 impl_->getRawNode().SetUint64(element); \ 203 #undef ARILES_BASIC_TYPE std::ostream * output_stream_
output stream
Floats are stored as strings by default to allow NaN and Inf (writer only)
Writer(const std::string &file_name)
#define ARILES_BASIC_UNSIGNED_INTEGER_TYPES_LIST
ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_INTEGER_TYPES_LIST) ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_REAL_TYPES_LIST) void Writer
ARILES_SHARED_PTR< t_Implementation > ImplPtr
Writer(const std::string &file_name, const Flags &flags=Flags::DEFAULT)
void startArray(const std::size_t size, const bool=false)
void startMap(const std::size_t)
#define ARILES_BASIC_SIGNED_INTEGER_TYPES_LIST
std::ofstream config_ofs_
output file stream
static void openFile(std::ofstream &config_ofs, const std::string &file_name)
open configuration file
void descend(const std::string &map_name)
Writer(std::ostream &output_stream)
#define ARILES_VISIBILITY_ATTRIBUTE