| 335 | } |
| 336 | |
| 337 | void cfg::encode(YAML::Emitter& out, const cfg::_base& rhs) |
| 338 | { |
| 339 | switch (rhs.get_type()) |
| 340 | { |
| 341 | case type::node: |
| 342 | { |
| 343 | out << YAML::BeginMap; |
| 344 | for (const auto& node : static_cast<const node&>(rhs).get_nodes()) |
| 345 | { |
| 346 | out << YAML::Key << node->get_name(); |
| 347 | out << YAML::Value; |
| 348 | encode(out, *node); |
| 349 | } |
| 350 | out << YAML::EndMap; |
| 351 | return; |
| 352 | } |
| 353 | case type::set: |
| 354 | { |
| 355 | out << YAML::BeginSeq; |
| 356 | for (const auto& str : static_cast<const set_entry&>(rhs).get_set()) |
| 357 | { |
| 358 | out << str; |
| 359 | } |
| 360 | out << YAML::EndSeq; |
| 361 | return; |
| 362 | } |
| 363 | case type::map: |
| 364 | { |
| 365 | out << YAML::BeginMap; |
| 366 | for (const auto& np : static_cast<const map_entry&>(rhs).get_map()) |
| 367 | { |
| 368 | out << YAML::Key << np.first; |
| 369 | out << YAML::Value << fmt::format("%s", np.second); |
| 370 | } |
| 371 | out << YAML::EndMap; |
| 372 | return; |
| 373 | } |
| 374 | case type::node_map: |
| 375 | { |
| 376 | // out << YAML::Block; // Does nothing, output is in Flow mode still (TODO) |
| 377 | out << YAML::BeginMap; |
| 378 | for (const auto& np : static_cast<const node_map_entry&>(rhs).get_map()) |
| 379 | { |
| 380 | out << YAML::Key << np.first; |
| 381 | out << YAML::Value << fmt::format("%s", np.second); |
| 382 | } |
| 383 | out << YAML::EndMap; |
| 384 | return; |
| 385 | } |
| 386 | case type::log: |
| 387 | { |
| 388 | out << YAML::BeginMap; |
| 389 | for (const auto& np : static_cast<const log_entry&>(rhs).get_map()) |
| 390 | { |
| 391 | if (np.second == logs::level::notice) |
| 392 | continue; |
| 393 | out << YAML::Key << np.first; |
| 394 | out << YAML::Value << fmt::format("%s", np.second); |
no test coverage detected