summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-11 00:31:25 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-11 00:31:25 +0100
commit4a28376403620736ad49f8bc886609154c51498b (patch)
tree7c9873cc0a630e0c41de858dae8ea920e74e075b
parentRemove unnecessary ValueTarget wrappers (diff)
downloadslicer-4a28376403620736ad49f8bc886609154c51498b.tar.bz2
slicer-4a28376403620736ad49f8bc886609154c51498b.tar.xz
slicer-4a28376403620736ad49f8bc886609154c51498b.zip
Bit of dedupe in DocumentTreeIterateDictAttrs
-rw-r--r--slicer/xml/serializer.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index cb0b0e4..369394e 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -229,15 +229,17 @@ namespace Slicer {
void
DocumentTreeIterateDictAttrs(const xmlpp::Element::const_AttributeList & attrs, ModelPartParam dict)
{
+ using AttrMember = Glib::ustring (xmlpp::Attribute::*)() const;
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();
+ const auto setChild = [&emp, &attr](const auto & childName, AttrMember attrMember) {
+ auto child = emp->GetChild(childName);
+ child->SetValue(XmlValueSource((attr->*attrMember)()));
+ child->Complete();
+ };
+ setChild(keyName, &xmlpp::Attribute::get_name);
+ setChild(valueName, &xmlpp::Attribute::get_value);
emp->Complete();
}
}