From a5d646deae167491caf88785640beaee5c2058f9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 7 Jan 2015 12:32:55 +0000 Subject: Fix xml serializer modeltreeiterateroot to work the same as iterate element part --- slicer/xml/serializer.cpp | 26 +++++++++++++++----------- slicer/xml/serializer.h | 3 +++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index 85fe99e..f7281b3 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -218,23 +218,27 @@ namespace Slicer { mp->GetValue(new XmlAttributeValueTarget(n, name)); } else if (mp) { - auto element = n->add_child(name); - auto typeIdPropName = mp->GetTypeIdProperty(); - auto typeId = mp->GetTypeId(); - if (typeId && typeIdPropName) { - element->set_attribute(*typeIdPropName, *typeId); - mp = mp->GetSubclassModelPart(*typeId); - } - mp->GetValue(new XmlContentValueTarget(element)); - mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, element, _1, _2, _3)); + ModelTreeProcessElement(n->add_child(name), mp); + } + } + + void + XmlSerializer::ModelTreeProcessElement(xmlpp::Element * element, ModelPartPtr mp) + { + auto typeIdPropName = mp->GetTypeIdProperty(); + auto typeId = mp->GetTypeId(); + if (typeId && typeIdPropName) { + element->set_attribute(*typeIdPropName, *typeId); + mp = mp->GetSubclassModelPart(*typeId); } + mp->GetValue(new XmlContentValueTarget(element)); + mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, element, _1, _2, _3)); } void XmlSerializer::ModelTreeIterateRoot(xmlpp::Document * doc, const std::string & name, ModelPartPtr mp) { - auto root = doc->create_root_node(name); - mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, root, _1, _2, _3)); + ModelTreeProcessElement(doc->create_root_node(name), mp); } XmlFileSerializer::XmlFileSerializer(const boost::filesystem::path & p) : diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index 4e37eed..5b738ca 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -9,6 +9,9 @@ namespace Slicer { protected: static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartPtr mp, HookCommonPtr hp); static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, ModelPartPtr mp); + + private: + static void ModelTreeProcessElement(xmlpp::Element * n, ModelPartPtr mp); }; class XmlFileSerializer : public XmlSerializer { -- cgit v1.2.3