13 #ifndef mitkVectorPropertySerializer_h
14 #define mitkVectorPropertySerializer_h
42 template <
typename DATATYPE>
55 std::vector<std::string>
GetClassHierarchy()
const override {
return mitk::GetClassHierarchy<Self>(); }
62 static std::string nameOfClass =
64 return nameOfClass.c_str();
67 const char *
GetNameOfClass()
const override {
return this->GetStaticNameOfClass(); }
68 itkFactorylessNewMacro(Self);
72 tinyxml2::XMLElement*
Serialize(tinyxml2::XMLDocument& doc)
override
74 auto *listElement = doc.NewElement(
"Values");
79 unsigned int index(0);
80 for (
auto listEntry : elements)
82 std::stringstream indexS;
85 auto *entryElement = doc.NewElement(
"Value");
86 entryElement->SetAttribute(
"idx", indexS.str().c_str());
87 entryElement->SetAttribute(
"value", boost::lexical_cast<std::string>(listEntry).c_str());
88 listElement->InsertEndChild(entryElement);
106 std::string valueString;
108 for (
auto *valueElement = listElement->FirstChildElement(
"Value"); valueElement;
109 valueElement = valueElement->NextSiblingElement(
"Value"))
111 valueString = valueElement->Attribute(
"value");
112 if (valueString.empty())
114 MITK_ERROR <<
"Missing value attribute in <Values> list";
120 value = boost::lexical_cast<DATATYPE>(valueString);
122 catch (boost::bad_lexical_cast &e)
124 MITK_ERROR <<
"Could not parse '" << valueString <<
"' as number: " << e.what();
128 datalist.push_back(value);
132 property->SetValue(datalist);
133 return property.GetPointer();