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 unsigned int index(0);
107 std::string valueString;
109 for (
auto *valueElement = listElement->FirstChildElement(
"Value"); valueElement;
110 valueElement = valueElement->NextSiblingElement(
"Value"))
112 valueString = valueElement->Attribute(
"value");
113 if (valueString.empty())
115 MITK_ERROR <<
"Missing value attribute in <Values> list";
121 value = boost::lexical_cast<DATATYPE>(valueString);
123 catch (boost::bad_lexical_cast &e)
125 MITK_ERROR <<
"Could not parse '" << valueString <<
"' as number: " << e.what();
129 datalist.push_back(value);
134 property->SetValue(datalist);
135 return property.GetPointer();