Redesigned the writer (#36) and added YAML support based on the new writer (#23)

This commit is contained in:
Patrick Urbanke
2024-01-03 07:22:36 +01:00
parent 0a524a9893
commit 5c81e40f09
133 changed files with 3082 additions and 838 deletions
+9 -7
View File
@@ -10,6 +10,7 @@
#include "../internal/StringLiteral.hpp"
#include "../internal/get_type_name.hpp"
#include "../internal/remove_namespaces.hpp"
#include "../parsing/Parent.hpp"
#include "Parser.hpp"
namespace rfl {
@@ -29,6 +30,8 @@ consteval auto get_root_name() {
template <internal::StringLiteral _root = internal::StringLiteral(""), class T>
std::ostream& write(const T& _obj, std::ostream& _stream,
const std::string& _indent = " ") {
using ParentType = parsing::Parent<Writer>;
constexpr auto root_name = get_root_name<_root, T>();
static_assert(root_name.string_view().find("<") == std::string_view::npos &&
@@ -38,18 +41,17 @@ std::ostream& write(const T& _obj, std::ostream& _stream,
"explicit root name to rfl::xml::write(...) like this: "
"rfl::xml::write<\"root_name\">(...).");
auto w = Writer();
const auto xml_obj = Parser<T>::write(w, _obj);
const auto doc = rfl::Ref<pugi::xml_document>::make();
pugi::xml_document doc;
auto declaration_node = doc.append_child(pugi::node_declaration);
auto declaration_node = doc->append_child(pugi::node_declaration);
declaration_node.append_attribute("version") = "1.0";
declaration_node.append_attribute("encoding") = "UTF-8";
xml_obj->insert(root_name.str(), &doc);
auto w = Writer(doc, root_name.str());
doc.save(_stream, _indent.c_str());
Parser<T>::write(w, _obj, typename ParentType::Root{});
doc->save(_stream, _indent.c_str());
return _stream;
}