12 #include <yaml-cpp/yaml.h> 46 emitter_->SetDoublePrecision(std::numeric_limits<double>::digits10);
47 if (output_stream_->tellp() != 0)
49 *emitter_ << YAML::Newline;
51 *emitter_ << YAML::BeginMap;
53 skip_root_map_ =
false;
60 *emitter_ << YAML::EndMap;
61 *output_stream_ << emitter_->c_str();
66 explicit Writer(
const std::string &file_name)
69 output_stream_ = &config_ofs_;
74 explicit Writer(std::ostream &output_stream)
76 output_stream_ = &output_stream;
84 *output_stream_ <<
"\n";
85 output_stream_->flush();
115 *
impl_->emitter_ << YAML::Key << map_name;
116 *
impl_->emitter_ << YAML::Value;
123 if (
impl_->map_depth_ > 0 or
false ==
impl_->skip_root_map_)
125 *
impl_->emitter_ << YAML::BeginMap;
134 ARILES_ASSERT(
impl_->map_depth_ > 0,
"Internal logic error.");
136 if (
impl_->map_depth_ > 0 or
false ==
impl_->skip_root_map_)
138 *
impl_->emitter_ << YAML::EndMap;
156 *
impl_->emitter_ << YAML::Flow;
158 *
impl_->emitter_ << YAML::BeginSeq;
165 *
impl_->emitter_ << YAML::EndSeq;
173 if (
true == name.empty())
175 impl_->skip_root_map_ =
true;
186 if (
false == name.empty())
190 impl_->skip_root_map_ =
false;
194 #define ARILES_BASIC_TYPE(type) \ 195 void Writer::writeElement(const type &element) \ 197 *impl_->emitter_ << element; \ 202 #undef ARILES_BASIC_TYPE 205 #define ARILES_BASIC_TYPE(type) \ 206 void Writer::writeElement(const type &element) \ 208 if (true == ariles::isNaN(element)) \ 210 *impl_->emitter_ << ".nan"; \ 214 if (true == ariles::isInfinity(element)) \ 218 *impl_->emitter_ << "-.inf"; \ 222 *impl_->emitter_ << ".inf"; \ 227 *impl_->emitter_ << element; \ 234 #undef ARILES_BASIC_TYPE 238 void Writer::writeElement(
const std::string &element)
240 *
impl_->emitter_ << element;
243 void Writer::writeElement(
const bool &element)
245 *
impl_->emitter_ << element;
#define ARILES_BASIC_INTEGER_TYPES_LIST
#define ARILES_TRACE_FUNCTION
void flush()
Flush the configuration to the output.
ARILES_SHARED_PTR< YAML::Emitter > EmitterPtr
ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_INTEGER_TYPES_LIST) ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_REAL_TYPES_LIST) void Writer
void startRoot(const std::string &name)
EmitterPtr emitter_
instance of YAML emitter, is destroyed and reinitialized by flush()
Writer(const std::string &file_name)
void startMap(const std::size_t)
Starts a nested map in the configuration file.
std::ofstream config_ofs_
output file stream
std::ostream * output_stream_
output stream
static void openFile(std::ofstream &config_ofs, const std::string &file_name)
open configuration file
#define ARILES_BASIC_REAL_TYPES_LIST
void startArray(const std::size_t, const bool compact=false)
void endMap()
Ends a nested map in the configuration file.
Writer(const std::string &file_name)
void endRoot(const std::string &name)
#define ARILES_VISIBILITY_ATTRIBUTE
Writer(std::ostream &output_stream)
ARILES_SHARED_PTR< impl::Writer > ImplPtr
#define ARILES_TRACE_ENTRY(entry_name)
void descend(const std::string &map_name)
Starts a nested map in the configuration file.