11 #include <boost/math/special_functions.hpp>
13 #include <yaml-cpp/yaml.h>
45 ARILES2_TRACE_FUNCTION;
47 emitter_->SetDoublePrecision(std::numeric_limits<double>::digits10);
48 if (output_stream_->tellp() != 0)
50 *emitter_ << YAML::Newline;
52 *emitter_ << YAML::BeginMap;
54 skip_root_map_ =
false;
60 ARILES2_TRACE_FUNCTION;
61 *emitter_ << YAML::EndMap;
62 *output_stream_ << emitter_->c_str();
67 explicit Writer(
const std::string &file_name)
70 output_stream_ = &config_ofs_;
75 explicit Writer(std::ostream &output_stream)
77 output_stream_ = &output_stream;
85 *output_stream_ <<
"\n";
86 output_stream_->flush();
114 ARILES2_TRACE_FUNCTION;
115 if (
impl_->map_depth_ > 0 or
false ==
impl_->skip_root_map_)
117 *
impl_->emitter_ << YAML::BeginMap;
124 ARILES2_TRACE_FUNCTION;
125 ARILES2_TRACE_VALUE(map_name);
126 *
impl_->emitter_ << YAML::Key << map_name;
127 *
impl_->emitter_ << YAML::Value;
132 ARILES2_TRACE_FUNCTION;
133 ARILES2_ASSERT(
impl_->map_depth_ > 0,
"Internal logic error.");
135 if (
impl_->map_depth_ > 0 or
false ==
impl_->skip_root_map_)
137 *
impl_->emitter_ << YAML::EndMap;
144 ARILES2_TRACE_FUNCTION;
151 ARILES2_TRACE_FUNCTION;
154 *
impl_->emitter_ << YAML::Flow;
156 *
impl_->emitter_ << YAML::BeginSeq;
162 ARILES2_TRACE_FUNCTION;
163 *
impl_->emitter_ << YAML::EndSeq;
169 ARILES2_TRACE_FUNCTION;
170 ARILES2_TRACE_VALUE(name);
171 if (
true == name.empty())
173 impl_->skip_root_map_ =
true;
183 ARILES2_TRACE_FUNCTION;
184 if (
false == name.empty())
188 impl_->skip_root_map_ =
false;
192 #define ARILES2_BASIC_TYPE(type) \
193 void Writer::writeElement(const type &element, const Parameters &) \
195 *impl_->emitter_ << element; \
200 #undef ARILES2_BASIC_TYPE
203 #define ARILES2_BASIC_TYPE(type) \
204 void Writer::writeElement(const type &element, const Parameters &) \
206 if (true == boost::math::isnan(element)) \
208 *impl_->emitter_ << ".nan"; \
212 if (true == boost::math::isinf(element)) \
216 *impl_->emitter_ << "-.inf"; \
220 *impl_->emitter_ << ".inf"; \
225 *impl_->emitter_ << static_cast<double>(element); \
232 #undef ARILES2_BASIC_TYPE
238 *
impl_->emitter_ << element;
243 *
impl_->emitter_ << element;