MCPcopy Create free account
hub / github.com/MITK/MITK / ApplyFromXMLElement

Function ApplyFromXMLElement

Modules/Core/src/IO/mitkIPreferences.cpp:56–102  ·  view source on GitHub ↗

Helper function that traverses the proference tree based on the passed xml and uses the PropertyApplier.*/

Source from the content-addressed store, hash-verified

54
55 /** Helper function that traverses the proference tree based on the passed xml and uses the PropertyApplier.*/
56 void ApplyFromXMLElement(
57 const tinyxml2::XMLElement* xmlElement,
58 mitk::IPreferences* targetNode,
59 const PropertyApplier& applyProperty,
60 bool createNodes,
61 const char* operationName)
62 {
63 const auto* xmlPropertyElement = xmlElement->FirstChildElement("property");
64
65 while (xmlPropertyElement != nullptr)
66 {
67 const auto* name = xmlPropertyElement->Attribute("name");
68 const auto* value = xmlPropertyElement->Attribute("value");
69
70 if (name == nullptr)
71 mitkThrow() << "Cannot apply preferences " << operationName << ": missing required attribute 'name' on <property> element.";
72
73 if (value == nullptr)
74 mitkThrow() << "Cannot apply preferences " << operationName << ": missing required attribute 'value' on <property> element.";
75
76 applyProperty(targetNode, name, value);
77
78 xmlPropertyElement = xmlPropertyElement->NextSiblingElement("property");
79 }
80
81 const auto* xmlChildElement = xmlElement->FirstChildElement("preferences");
82
83 while (xmlChildElement != nullptr)
84 {
85 const auto* childName = xmlChildElement->Attribute("name");
86
87 if (childName == nullptr)
88 mitkThrow() << "Cannot apply preferences " << operationName << ": missing required attribute 'name' on <preferences> element.";
89
90 if (!createNodes)
91 {
92 const auto childrenNames = targetNode->ChildrenNames();
93
94 if (std::find(childrenNames.begin(), childrenNames.end(), childName) == childrenNames.end())
95 mitkThrow() << "Cannot apply preferences " << operationName << ": preferences node \"" << childName << "\" does not exist.";
96 }
97
98 ApplyFromXMLElement(xmlChildElement, targetNode->Node(childName), applyProperty, createNodes, operationName);
99
100 xmlChildElement = xmlChildElement->NextSiblingElement("preferences");
101 }
102 }
103}
104
105void mitk::ApplyPreferencesOverrides(const std::string& xmlContent, IPreferences* prefs)

Callers 2

Calls 4

ChildrenNamesMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
NodeMethod · 0.45

Tested by

no test coverage detected