summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-10 23:16:36 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-10 23:16:36 +0100
commitec56144613e47cea2636b7179f3a8b27eacdba50 (patch)
tree6ee6a13ffdbc30832414111b148d58d1c854e2b6
parentMove ModelTreeIterate* into the anonymous namespace (diff)
downloadslicer-ec56144613e47cea2636b7179f3a8b27eacdba50.tar.bz2
slicer-ec56144613e47cea2636b7179f3a8b27eacdba50.tar.xz
slicer-ec56144613e47cea2636b7179f3a8b27eacdba50.zip
Move private stuff into anon namespace
-rw-r--r--slicer/xml/serializer.cpp687
-rw-r--r--slicer/xml/serializer.h37
2 files changed, 355 insertions, 369 deletions
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index f9cb045..f508a6f 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -10,16 +10,16 @@
#endif
#include <glibmm/ustring.h>
#include <libxml++/attribute.h>
+#include <libxml++/document.h>
#include <libxml++/nodes/contentnode.h>
#include <libxml++/nodes/element.h>
#include <libxml++/nodes/node.h>
+#include <libxml++/parsers/domparser.h>
#pragma GCC diagnostic pop
#include <Ice/Config.h>
#include <boost/numeric/conversion/cast.hpp>
#include <factory.h>
#include <lazyPointer.h>
-#include <libxml++/document.h>
-#include <libxml++/parsers/domparser.h>
#include <list>
#include <memory>
#include <optional>
@@ -37,411 +37,426 @@ NAMEDFACTORY("application/xml", Slicer::XmlStreamSerializer, Slicer::StreamSeria
NAMEDFACTORY("application/xml", Slicer::XmlStreamDeserializer, Slicer::StreamDeserializerFactory)
namespace Slicer {
- constexpr std::string_view md_attribute {"xml:attribute"};
- constexpr std::string_view md_text {"xml:text"};
- constexpr std::string_view md_bare {"xml:bare"};
- constexpr std::string_view md_attributes {"xml:attributes"};
- constexpr std::string_view md_elements {"xml:elements"};
- constexpr std::string_view keyName {"key"};
- constexpr std::string_view valueName {"value"};
-
- constexpr auto defaultElementCreator = [](auto && element, auto && name) {
- return element->add_child_element(name);
- };
+ namespace {
+ constexpr std::string_view md_attribute {"xml:attribute"};
+ constexpr std::string_view md_text {"xml:text"};
+ constexpr std::string_view md_bare {"xml:bare"};
+ constexpr std::string_view md_attributes {"xml:attributes"};
+ constexpr std::string_view md_elements {"xml:elements"};
+ constexpr std::string_view keyName {"key"};
+ constexpr std::string_view valueName {"value"};
+
+ using CurrentElementCreator = ::AdHoc::LazyPointer<xmlpp::Element, xmlpp::Element *>;
+ using ElementCreator = std::function<xmlpp::Element *(xmlpp::Element *, const Glib::ustring &)>;
+
+ constexpr auto defaultElementCreator = [](auto && element, auto && name) {
+ return element->add_child_element(name);
+ };
- static const Glib::ustring TrueText("true");
- static const Glib::ustring FalseText("false");
+ const Glib::ustring TrueText("true");
+ const Glib::ustring FalseText("false");
- class XmlValueSource : public ValueSource {
- public:
- explicit XmlValueSource(Glib::ustring s) : value(std::move(s)) { }
+ class XmlValueSource : public ValueSource {
+ public:
+ explicit XmlValueSource(Glib::ustring s) : value(std::move(s)) { }
- void
- set(bool & v) const override
- {
- if (value == TrueText) {
- v = true;
- return;
- }
- if (value == FalseText) {
- v = false;
- return;
+ void
+ set(bool & v) const override
+ {
+ if (value == TrueText) {
+ v = true;
+ return;
+ }
+ if (value == FalseText) {
+ v = false;
+ return;
+ }
+ throw BadBooleanValue(value);
}
- throw BadBooleanValue(value);
- }
- void
- set(Ice::Byte & v) const override
- {
- from_chars(v);
- }
+ void
+ set(Ice::Byte & v) const override
+ {
+ from_chars(v);
+ }
- void
- set(Ice::Short & v) const override
- {
- from_chars(v);
- }
+ void
+ set(Ice::Short & v) const override
+ {
+ from_chars(v);
+ }
- void
- set(Ice::Int & v) const override
- {
- from_chars(v);
- }
+ void
+ set(Ice::Int & v) const override
+ {
+ from_chars(v);
+ }
- void
- set(Ice::Long & v) const override
- {
- from_chars(v);
- }
+ void
+ set(Ice::Long & v) const override
+ {
+ from_chars(v);
+ }
- void
- set(Ice::Float & v) const override
- {
- from_chars(v);
- }
+ void
+ set(Ice::Float & v) const override
+ {
+ from_chars(v);
+ }
- void
- set(Ice::Double & v) const override
- {
- from_chars(v);
- }
+ void
+ set(Ice::Double & v) const override
+ {
+ from_chars(v);
+ }
- void
- set(std::string & v) const override
- {
- v = value.raw();
- }
+ void
+ set(std::string & v) const override
+ {
+ v = value.raw();
+ }
- private:
- template<typename T>
- void
- from_chars(T & v) const
- {
- std::string_view raw {value.raw()};
- if (std::from_chars(raw.begin(), raw.end(), v).ec != std::errc {}) {
- throw BadNumericValue(value);
+ private:
+ template<typename T>
+ void
+ from_chars(T & v) const
+ {
+ std::string_view raw {value.raw()};
+ if (std::from_chars(raw.begin(), raw.end(), v).ec != std::errc {}) {
+ throw BadNumericValue(value);
+ }
}
- }
- const Glib::ustring value;
- };
+ const Glib::ustring value;
+ };
- class XmlContentValueSource : public XmlValueSource {
- public:
- explicit XmlContentValueSource() : XmlValueSource(Glib::ustring()) { }
+ class XmlContentValueSource : public XmlValueSource {
+ public:
+ explicit XmlContentValueSource() : XmlValueSource(Glib::ustring()) { }
- explicit XmlContentValueSource(const xmlpp::ContentNode * c) : XmlValueSource(c->get_content()) { }
- };
+ explicit XmlContentValueSource(const xmlpp::ContentNode * c) : XmlValueSource(c->get_content()) { }
+ };
- class XmlAttributeValueSource : public XmlValueSource {
- public:
- explicit XmlAttributeValueSource(const xmlpp::Attribute * a) : XmlValueSource(a->get_value()) { }
- };
+ class XmlAttributeValueSource : public XmlValueSource {
+ public:
+ explicit XmlAttributeValueSource(const xmlpp::Attribute * a) : XmlValueSource(a->get_value()) { }
+ };
- class XmlValueTarget : public ValueTarget {
- public:
- explicit XmlValueTarget(std::function<void(const Glib::ustring &)> a) : apply(std::move(a)) { }
+ class XmlValueTarget : public ValueTarget {
+ public:
+ explicit XmlValueTarget(std::function<void(const Glib::ustring &)> a) : apply(std::move(a)) { }
- void
- get(const bool & value) const override
- {
- if (value) {
- apply(TrueText);
+ void
+ get(const bool & value) const override
+ {
+ if (value) {
+ apply(TrueText);
+ }
+ else {
+ apply(FalseText);
+ }
}
- else {
- apply(FalseText);
+
+ void
+ get(const Ice::Byte & value) const override
+ {
+ apply(Glib::ustring::format(value));
}
- }
- void
- get(const Ice::Byte & value) const override
- {
- apply(Glib::ustring::format(value));
- }
+ void
+ get(const Ice::Short & value) const override
+ {
+ apply(Glib::ustring::format(value));
+ }
- void
- get(const Ice::Short & value) const override
- {
- apply(Glib::ustring::format(value));
- }
+ void
+ get(const Ice::Int & value) const override
+ {
+ apply(Glib::ustring::format(value));
+ }
- void
- get(const Ice::Int & value) const override
- {
- apply(Glib::ustring::format(value));
- }
+ void
+ get(const Ice::Long & value) const override
+ {
+ apply(Glib::ustring::format(value));
+ }
- void
- get(const Ice::Long & value) const override
- {
- apply(Glib::ustring::format(value));
- }
+ void
+ get(const Ice::Float & value) const override
+ {
+ apply(Glib::ustring::format(value));
+ }
- void
- get(const Ice::Float & value) const override
- {
- apply(Glib::ustring::format(value));
- }
+ void
+ get(const Ice::Double & value) const override
+ {
+ apply(Glib::ustring::format(value));
+ }
- void
- get(const Ice::Double & value) const override
- {
- apply(Glib::ustring::format(value));
- }
+ void
+ get(const std::string & value) const override
+ {
+ apply(value);
+ }
- void
- get(const std::string & value) const override
- {
- apply(value);
- }
+ private:
+ const std::function<void(const Glib::ustring &)> apply;
+ };
- private:
- const std::function<void(const Glib::ustring &)> apply;
- };
+ class XmlAttributeValueTarget : public XmlValueTarget {
+ public:
+ explicit XmlAttributeValueTarget(xmlpp::Element * p, const std::string & n) :
+ XmlValueTarget([p, n](auto && PH1) {
+ p->set_attribute(n, PH1);
+ })
+ {
+ }
+ };
- class XmlAttributeValueTarget : public XmlValueTarget {
- public:
- explicit XmlAttributeValueTarget(xmlpp::Element * p, const std::string & n) :
- XmlValueTarget([p, n](auto && PH1) {
- p->set_attribute(n, PH1);
- })
- {
- }
- };
-
- class XmlContentValueTarget : public XmlValueTarget {
- public:
- explicit XmlContentValueTarget(xmlpp::Element * p) :
- XmlValueTarget([p](auto && PH1) {
- p->set_first_child_text(PH1);
- })
- {
- }
+ class XmlContentValueTarget : public XmlValueTarget {
+ public:
+ explicit XmlContentValueTarget(xmlpp::Element * p) :
+ XmlValueTarget([p](auto && PH1) {
+ p->set_first_child_text(PH1);
+ })
+ {
+ }
- explicit XmlContentValueTarget(const CurrentElementCreator & cec) :
- XmlValueTarget([&](auto && PH1) {
- cec->set_first_child_text(PH1);
- })
- {
- }
- };
+ explicit XmlContentValueTarget(const CurrentElementCreator & cec) :
+ XmlValueTarget([&](auto && PH1) {
+ cec->set_first_child_text(PH1);
+ })
+ {
+ }
+ };
- void
- XmlDeserializer::DocumentTreeIterateDictAttrs(
- const xmlpp::Element::const_AttributeList & attrs, ModelPartParam dict)
- {
- for (const auto & attr : attrs) {
- auto emp = dict->GetAnonChild();
- emp->Create();
- auto key = emp->GetChild(keyName);
- auto value = emp->GetChild(valueName);
- key->SetValue(XmlValueSource(attr->get_name()));
- key->Complete();
- value->SetValue(XmlValueSource(attr->get_value()));
- value->Complete();
- emp->Complete();
- }
- }
+ void DocumentTreeIterate(const xmlpp::Node * node, ModelPartParam mp);
+ void DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartParam mp, const ChildRef & c);
+ void DocumentTreeIterate(const xmlpp::Document * doc, ModelPartParam mp);
+ void DocumentTreeIterateDictAttrs(const xmlpp::Element::const_AttributeList & attrs, ModelPartParam dict);
+ void DocumentTreeIterateDictElements(const xmlpp::Element * parent, ModelPartParam dict);
- void
- XmlDeserializer::DocumentTreeIterateDictElements(const xmlpp::Element * element, ModelPartParam dict)
- {
- auto node = element->get_first_child();
- while (node) {
- if (auto childElement = dynamic_cast<const xmlpp::Element *>(node)) {
+ void
+ DocumentTreeIterateDictAttrs(const xmlpp::Element::const_AttributeList & attrs, ModelPartParam dict)
+ {
+ for (const auto & attr : attrs) {
auto emp = dict->GetAnonChild();
emp->Create();
auto key = emp->GetChild(keyName);
- auto value = emp->GetChildRef(valueName);
- key->SetValue(XmlValueSource(childElement->get_name()));
+ auto value = emp->GetChild(valueName);
+ key->SetValue(XmlValueSource(attr->get_name()));
key->Complete();
- DocumentTreeIterateElement(childElement, value.Child(), value);
+ value->SetValue(XmlValueSource(attr->get_value()));
+ value->Complete();
emp->Complete();
}
- node = node->get_next_sibling();
}
- }
- void
- XmlDeserializer::DocumentTreeIterateElement(
- const xmlpp::Element * element, ModelPartParam smp, const ChildRef & smpr)
- {
- auto oec = [&smpr, element](const auto & lmp) {
- lmp->Create();
- if (smpr.ChildMetaData().flagSet(md_attributes)) {
- auto attrs(element->get_attributes());
- if (!attrs.empty()) {
- DocumentTreeIterateDictAttrs(attrs, lmp);
+ void
+ DocumentTreeIterateDictElements(const xmlpp::Element * element, ModelPartParam dict)
+ {
+ auto node = element->get_first_child();
+ while (node) {
+ if (auto childElement = dynamic_cast<const xmlpp::Element *>(node)) {
+ auto emp = dict->GetAnonChild();
+ emp->Create();
+ auto key = emp->GetChild(keyName);
+ auto value = emp->GetChildRef(valueName);
+ key->SetValue(XmlValueSource(childElement->get_name()));
+ key->Complete();
+ DocumentTreeIterateElement(childElement, value.Child(), value);
+ emp->Complete();
}
+ node = node->get_next_sibling();
}
- else if (smpr.ChildMetaData().flagSet(md_elements)) {
- DocumentTreeIterateDictElements(element, lmp);
- }
- else {
- auto attrs(element->get_attributes());
- if (!attrs.empty()) {
- DocumentTreeIterate(attrs.front(), lmp);
+ }
+
+ void
+ DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartParam smp, const ChildRef & smpr)
+ {
+ auto oec = [&smpr, element](const auto & lmp) {
+ lmp->Create();
+ if (smpr.ChildMetaData().flagSet(md_attributes)) {
+ auto attrs(element->get_attributes());
+ if (!attrs.empty()) {
+ DocumentTreeIterateDictAttrs(attrs, lmp);
+ }
}
- auto firstChild = element->get_first_child();
- if (firstChild) {
- DocumentTreeIterate(firstChild, lmp);
+ else if (smpr.ChildMetaData().flagSet(md_elements)) {
+ DocumentTreeIterateDictElements(element, lmp);
}
else {
- lmp->SetValue(XmlContentValueSource());
+ auto attrs(element->get_attributes());
+ if (!attrs.empty()) {
+ DocumentTreeIterate(attrs.front(), lmp);
+ }
+ auto firstChild = element->get_first_child();
+ if (firstChild) {
+ DocumentTreeIterate(firstChild, lmp);
+ }
+ else {
+ lmp->SetValue(XmlContentValueSource());
+ }
+ }
+ lmp->Complete();
+ };
+ if (auto typeIdPropName = smp->GetTypeIdProperty()) {
+ if (auto typeAttr = element->get_attribute(*typeIdPropName)) {
+ oec(smp->GetSubclassModelPart(typeAttr->get_value()));
+ return;
}
}
- lmp->Complete();
- };
- if (auto typeIdPropName = smp->GetTypeIdProperty()) {
- if (auto typeAttr = element->get_attribute(*typeIdPropName)) {
- oec(smp->GetSubclassModelPart(typeAttr->get_value()));
- return;
- }
+ oec(smp);
}
- oec(smp);
- }
- void
- XmlDeserializer::DocumentTreeIterate(const xmlpp::Node * node, ModelPartParam mp)
- {
- while (node) {
- if (auto element = dynamic_cast<const xmlpp::Element *>(node)) {
- auto smpr = mp->GetChildRef(element->get_name().raw(), [](const auto & h) {
- return h->GetMetadata().flagNotSet(md_attribute);
- });
- if (smpr) {
- auto smp = smpr.Child();
- if (smpr.ChildMetaData().flagSet(md_bare)) {
- smp = smp->GetAnonChild();
+ void
+ DocumentTreeIterate(const xmlpp::Node * node, ModelPartParam mp)
+ {
+ while (node) {
+ if (auto element = dynamic_cast<const xmlpp::Element *>(node)) {
+ auto smpr = mp->GetChildRef(element->get_name().raw(), [](const auto & h) {
+ return h->GetMetadata().flagNotSet(md_attribute);
+ });
+ if (smpr) {
+ auto smp = smpr.Child();
+ if (smpr.ChildMetaData().flagSet(md_bare)) {
+ smp = smp->GetAnonChild();
+ }
+ if (smp) {
+ DocumentTreeIterateElement(element, smp, smpr);
+ }
}
+ }
+ else if (auto attribute = dynamic_cast<const xmlpp::Attribute *>(node)) {
+ auto smp = mp->GetChild(attribute->get_name().raw(), [](const auto & h) {
+ return h->GetMetadata().flagSet(md_attribute);
+ });
if (smp) {
- DocumentTreeIterateElement(element, smp, smpr);
+ smp->Create();
+ smp->SetValue(XmlAttributeValueSource(attribute));
+ smp->Complete();
}
}
- }
- else if (auto attribute = dynamic_cast<const xmlpp::Attribute *>(node)) {
- auto smp = mp->GetChild(attribute->get_name().raw(), [](const auto & h) {
- return h->GetMetadata().flagSet(md_attribute);
- });
- if (smp) {
- smp->Create();
- smp->SetValue(XmlAttributeValueSource(attribute));
- smp->Complete();
+ else if (auto content = dynamic_cast<const xmlpp::ContentNode *>(node)) {
+ ModelPartPtr smp;
+ if (!content->is_white_space()) {
+ smp = mp->GetAnonChild([](const auto & h) {
+ return h->GetMetadata().flagSet(md_text);
+ });
+ }
+ if (smp) {
+ smp->SetValue(XmlContentValueSource(content));
+ }
+ else {
+ mp->SetValue(XmlContentValueSource(content));
+ }
}
+ node = node->get_next_sibling();
+ }
+ }
+
+ void
+ DocumentTreeIterate(const xmlpp::Document * doc, ModelPartParam mp)
+ {
+ DocumentTreeIterate(doc->get_root_node(), mp);
+ }
+
+ void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartParam mp, const HookCommon * hp,
+ const ElementCreator &);
+ void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, ModelPartParam mp);
+ void ModelTreeProcessElement(const CurrentElementCreator &, ModelPartParam mp, const ElementCreator &);
+ void ModelTreeIterateDictAttrs(xmlpp::Element * element, ModelPartParam dict);
+ void ModelTreeIterateDictElements(xmlpp::Element * element, ModelPartParam dict);
+
+ void
+ ModelTreeIterate(xmlpp::Element * n, const std::string & name, ModelPartParam mp, const HookCommon * hp,
+ const ElementCreator & ec)
+ {
+ if (name.empty()) {
+ return;
+ }
+ if (hp && hp->GetMetadata().flagSet(md_attribute)) {
+ mp->GetValue(XmlAttributeValueTarget(n, name));
+ }
+ else if (hp && hp->GetMetadata().flagSet(md_text)) {
+ mp->GetValue(XmlContentValueTarget(n));
+ }
+ else if (hp && hp->GetMetadata().flagSet(md_attributes)) {
+ ModelTreeIterateDictAttrs(n->add_child_element(name), mp);
}
- else if (auto content = dynamic_cast<const xmlpp::ContentNode *>(node)) {
- ModelPartPtr smp;
- if (!content->is_white_space()) {
- smp = mp->GetAnonChild([](const auto & h) {
- return h->GetMetadata().flagSet(md_text);
+ else if (hp && hp->GetMetadata().flagSet(md_elements)) {
+ ModelTreeIterateDictElements(n->add_child_element(name), mp);
+ }
+ else {
+ if (hp && hp->GetMetadata().flagSet(md_bare)) {
+ ModelTreeProcessElement(n, mp, [name](auto && PH1, auto &&) {
+ return PH1->add_child_element(name);
});
}
- if (smp) {
- smp->SetValue(XmlContentValueSource(content));
- }
else {
- mp->SetValue(XmlContentValueSource(content));
+ CurrentElementCreator cec([ec, n, name] {
+ return ec(n, name);
+ });
+ ModelTreeProcessElement(cec, mp, defaultElementCreator);
}
}
- node = node->get_next_sibling();
}
- }
- void
- XmlDeserializer::DocumentTreeIterate(const xmlpp::Document * doc, ModelPartParam mp)
- {
- DocumentTreeIterate(doc->get_root_node(), mp);
- }
-
- void
- XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, ModelPartParam mp,
- const HookCommon * hp, const ElementCreator & ec)
- {
- if (name.empty()) {
- return;
- }
- if (hp && hp->GetMetadata().flagSet(md_attribute)) {
- mp->GetValue(XmlAttributeValueTarget(n, name));
- }
- else if (hp && hp->GetMetadata().flagSet(md_text)) {
- mp->GetValue(XmlContentValueTarget(n));
- }
- else if (hp && hp->GetMetadata().flagSet(md_attributes)) {
- ModelTreeIterateDictAttrs(n->add_child_element(name), mp);
- }
- else if (hp && hp->GetMetadata().flagSet(md_elements)) {
- ModelTreeIterateDictElements(n->add_child_element(name), mp);
+ void
+ ModelTreeIterateDictAttrs(xmlpp::Element * element, ModelPartParam dict)
+ {
+ dict->OnEachChild([element](const auto &, const auto & mp, const auto &) {
+ if (mp->HasValue()) {
+ mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp, element](const auto & name) {
+ mp->GetChild(valueName)->GetValue(XmlAttributeValueTarget(element, name));
+ }));
+ }
+ });
}
- else {
- if (hp && hp->GetMetadata().flagSet(md_bare)) {
- ModelTreeProcessElement(n, mp, [name](auto && PH1, auto &&) {
- return PH1->add_child_element(name);
- });
- }
- else {
- CurrentElementCreator cec([ec, n, name] {
- return ec(n, name);
- });
- ModelTreeProcessElement(cec, mp, defaultElementCreator);
- }
+
+ void
+ ModelTreeIterateDictElements(xmlpp::Element * element, ModelPartParam dict)
+ {
+ dict->OnEachChild([element](const auto &, const auto & mp, const auto &) {
+ if (mp->HasValue()) {
+ mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp, element](const auto & name) {
+ CurrentElementCreator cec([&element, &name]() {
+ return element->add_child_element(name);
+ });
+ ModelTreeProcessElement(cec, mp->GetChild(valueName), defaultElementCreator);
+ }));
+ }
+ });
}
- }
- void
- XmlSerializer::ModelTreeIterateDictAttrs(xmlpp::Element * element, ModelPartParam dict)
- {
- dict->OnEachChild([element](const auto &, const auto & mp, const auto &) {
- if (mp->HasValue()) {
- mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp, element](const auto & name) {
- mp->GetChild(valueName)->GetValue(XmlAttributeValueTarget(element, name));
- }));
+ void
+ ModelTreeProcessElement(const CurrentElementCreator & cec, ModelPartParam mp, const ElementCreator & ec)
+ {
+ if (mp->GetType() == ModelPartType::Simple) {
+ mp->GetValue(XmlContentValueTarget(cec));
}
- });
- }
-
- void
- XmlSerializer::ModelTreeIterateDictElements(xmlpp::Element * element, ModelPartParam dict)
- {
- dict->OnEachChild([element](const auto &, const auto & mp, const auto &) {
- if (mp->HasValue()) {
- mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp, element](const auto & name) {
- CurrentElementCreator cec([&element, &name]() {
- return element->add_child_element(name);
+ else if (mp->HasValue()) {
+ auto oec = [element = cec.get(), &ec](const auto & lmp) {
+ lmp->OnEachChild([element, &ec](auto && PH1, auto && PH2, auto && PH3) {
+ return ModelTreeIterate(element, PH1, PH2, PH3, ec);
});
- ModelTreeProcessElement(cec, mp->GetChild(valueName), defaultElementCreator);
- }));
- }
- });
- }
-
- void
- XmlSerializer::ModelTreeProcessElement(
- const CurrentElementCreator & cec, ModelPartParam mp, const ElementCreator & ec)
- {
- if (mp->GetType() == ModelPartType::Simple) {
- mp->GetValue(XmlContentValueTarget(cec));
- }
- else if (mp->HasValue()) {
- auto oec = [element = cec.get(), &ec](const auto & lmp) {
- lmp->OnEachChild([element, &ec](auto && PH1, auto && PH2, auto && PH3) {
- return XmlSerializer::ModelTreeIterate(element, PH1, PH2, PH3, ec);
- });
- return element;
- };
- if (auto typeIdPropName = mp->GetTypeIdProperty()) {
- if (auto typeId = mp->GetTypeId()) {
- oec(mp->GetSubclassModelPart(*typeId))->set_attribute(*typeIdPropName, *typeId);
- return;
+ return element;
+ };
+ if (auto typeIdPropName = mp->GetTypeIdProperty()) {
+ if (auto typeId = mp->GetTypeId()) {
+ oec(mp->GetSubclassModelPart(*typeId))->set_attribute(*typeIdPropName, *typeId);
+ return;
+ }
}
+ oec(mp);
}
- oec(mp);
}
- }
- void
- XmlSerializer::ModelTreeIterateRoot(xmlpp::Document * doc, const std::string & name, ModelPartParam mp)
- {
- ModelTreeProcessElement(doc->create_root_node(name), mp, defaultElementCreator);
+ void
+ ModelTreeIterateRoot(xmlpp::Document * doc, const std::string & name, ModelPartParam mp)
+ {
+ ModelTreeProcessElement(doc->create_root_node(name), mp, defaultElementCreator);
+ }
}
XmlStreamSerializer::XmlStreamSerializer(std::ostream & s) : strm(s) { }
@@ -488,7 +503,7 @@ namespace Slicer {
XmlDocumentSerializer::Serialize(ModelPartForRootParam modelRoot)
{
modelRoot->OnEachChild([this](auto && PH1, auto && PH2, auto &&) {
- return XmlSerializer::ModelTreeIterateRoot(&doc, PH1, PH2);
+ return ModelTreeIterateRoot(&doc, PH1, PH2);
});
}
diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h
index d138ac0..9c6e1ae 100644
--- a/slicer/xml/serializer.h
+++ b/slicer/xml/serializer.h
@@ -1,7 +1,6 @@
#ifndef SLICER_XML_H
#define SLICER_XML_H
-#include <lazyPointer.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wsign-conversion"
@@ -9,12 +8,9 @@
# pragma GCC diagnostic ignored "-Wuseless-cast"
#endif
#include <libxml++/document.h>
-#include <libxml++/nodes/element.h>
#pragma GCC diagnostic pop
#include <filesystem>
#include <fstream>
-#include <functional>
-#include <iosfwd>
#include <slicer/modelParts.h>
#include <slicer/serializer.h>
#include <string>
@@ -25,22 +21,7 @@ namespace Glib {
}
namespace Slicer {
- using CurrentElementCreator = ::AdHoc::LazyPointer<xmlpp::Element, xmlpp::Element *>;
-
- class DLL_PUBLIC XmlSerializer : public Serializer {
- protected:
- using ElementCreator = std::function<xmlpp::Element *(xmlpp::Element *, const Glib::ustring &)>;
- static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartParam mp, const HookCommon * hp,
- const ElementCreator &);
- static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, ModelPartParam mp);
-
- protected:
- static void ModelTreeProcessElement(const CurrentElementCreator &, ModelPartParam mp, const ElementCreator &);
- static void ModelTreeIterateDictAttrs(xmlpp::Element * element, ModelPartParam dict);
- static void ModelTreeIterateDictElements(xmlpp::Element * element, ModelPartParam dict);
- };
-
- class DLL_PUBLIC XmlDocumentSerializer : public XmlSerializer {
+ class DLL_PUBLIC XmlDocumentSerializer : public Serializer {
public:
void Serialize(ModelPartForRootParam) override;
@@ -66,17 +47,7 @@ namespace Slicer {
std::ofstream strm;
};
- class DLL_PUBLIC XmlDeserializer : public Deserializer {
- protected:
- static void DocumentTreeIterate(const xmlpp::Node * node, ModelPartParam mp);
- static void DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartParam mp, const ChildRef & c);
- static void DocumentTreeIterate(const xmlpp::Document * doc, ModelPartParam mp);
- static void DocumentTreeIterateDictAttrs(
- const xmlpp::Element::const_AttributeList & attrs, ModelPartParam dict);
- static void DocumentTreeIterateDictElements(const xmlpp::Element * parent, ModelPartParam dict);
- };
-
- class DLL_PUBLIC XmlStreamDeserializer : public XmlDeserializer {
+ class DLL_PUBLIC XmlStreamDeserializer : public Deserializer {
public:
explicit XmlStreamDeserializer(std::istream &);
@@ -86,7 +57,7 @@ namespace Slicer {
std::istream & strm;
};
- class DLL_PUBLIC XmlFileDeserializer : public XmlDeserializer {
+ class DLL_PUBLIC XmlFileDeserializer : public Deserializer {
public:
explicit XmlFileDeserializer(std::filesystem::path);
@@ -96,7 +67,7 @@ namespace Slicer {
const std::filesystem::path path;
};
- class DLL_PUBLIC XmlDocumentDeserializer : public XmlDeserializer {
+ class DLL_PUBLIC XmlDocumentDeserializer : public Deserializer {
public:
explicit XmlDocumentDeserializer(const xmlpp::Document *);