summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-05 13:05:56 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-05 13:05:56 +0100
commitd88e0d955d74f6b274d094539c4a223243ef948c (patch)
tree3d643f434c754a2c1d0ee58c57559d87200f9a69
parentRefactor XmlSerializer::ModelTreeProcessElement with no pointer copy (diff)
downloadslicer-d88e0d955d74f6b274d094539c4a223243ef948c.tar.bz2
slicer-d88e0d955d74f6b274d094539c4a223243ef948c.tar.xz
slicer-d88e0d955d74f6b274d094539c4a223243ef948c.zip
Refactor XmlDeserializer::DocumentTreeIterateElement with no pointer copy
-rw-r--r--slicer/xml/serializer.cpp52
1 files changed, 28 insertions, 24 deletions
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index acbb83d..609eac2 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -255,35 +255,39 @@ namespace Slicer {
void
XmlDeserializer::DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr smp, const ChildRef & smpr)
{
- if (auto typeIdPropName = smp->GetTypeIdProperty()) {
- if (auto typeAttr = element->get_attribute(*typeIdPropName)) {
- smp = smp->GetSubclassModelPart(typeAttr->get_value());
- }
- }
- smp->Create();
- if (smpr.ChildMetaData().flagSet(md_attributes)) {
- auto attrs(element->get_attributes());
- if (!attrs.empty()) {
- DocumentTreeIterateDictAttrs(attrs, smp);
- }
- }
- else if (smpr.ChildMetaData().flagSet(md_elements)) {
- DocumentTreeIterateDictElements(element, smp);
- }
- else {
- auto attrs(element->get_attributes());
- if (!attrs.empty()) {
- DocumentTreeIterate(attrs.front(), smp);
+ 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, smp);
+ else if (smpr.ChildMetaData().flagSet(md_elements)) {
+ DocumentTreeIterateDictElements(element, lmp);
}
else {
- smp->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;
}
}
- smp->Complete();
+ oec(smp);
}
void