13 #ifndef mitkVectorPropertySerializer_h
14 #define mitkVectorPropertySerializer_h
50 template <
typename DATATYPE>
63 std::vector<std::string>
GetClassHierarchy()
const override {
return mitk::GetClassHierarchy<Self>(); }
70 static std::string nameOfClass =
72 return nameOfClass.c_str();
75 const char *
GetNameOfClass()
const override {
return this->GetStaticNameOfClass(); }
76 itkFactorylessNewMacro(
Self);
90 tinyxml2::XMLElement*
Serialize(tinyxml2::XMLDocument& doc)
override
92 auto *listElement = doc.NewElement(
"Values");
97 unsigned int index(0);
98 for (
auto listEntry : elements)
100 std::stringstream indexS;
103 auto *entryElement = doc.NewElement(
"Value");
104 entryElement->SetAttribute(
"idx", indexS.str().c_str());
105 entryElement->SetAttribute(
"value", boost::lexical_cast<std::string>(listEntry).c_str());
106 listElement->InsertEndChild(entryElement);
128 BaseProperty::Pointer
Deserialize(
const tinyxml2::XMLElement *listElement)
override
134 std::string valueString;
136 for (
auto *valueElement = listElement->FirstChildElement(
"Value"); valueElement;
137 valueElement = valueElement->NextSiblingElement(
"Value"))
139 valueString = valueElement->Attribute(
"value");
140 if (valueString.empty())
142 MITK_ERROR <<
"Missing value attribute in <Values> list";
148 value = boost::lexical_cast<DATATYPE>(valueString);
150 catch (boost::bad_lexical_cast &e)
152 MITK_ERROR <<
"Could not parse '" << valueString <<
"' as number: " << e.what();
156 datalist.push_back(value);
160 property->SetValue(datalist);
161 return property.GetPointer();
#define MITKSCENESERIALIZATIONBASE_EXPORT
Base class for objects that serialize and deserialize BaseProperty types to/from XML.
Serializes and deserializes VectorProperty instances to/from XML.
std::vector< std::string > GetClassHierarchy() const override
static const char * GetStaticNameOfClass()
itk::SmartPointer< const Self > ConstPointer
BaseProperty::Pointer Deserialize(const tinyxml2::XMLElement *listElement) override
Deserializes an XML "Values" element back into a VectorProperty.
BasePropertySerializer SuperClass
itk::SmartPointer< Self > Pointer
VectorPropertySerializer< DATATYPE > Self
const char * GetNameOfClass() const override
tinyxml2::XMLElement * Serialize(tinyxml2::XMLDocument &doc) override
Serializes the VectorProperty into an XML "Values" element.
VectorProperty< DATATYPE > PropertyType
Property for storing a std::vector of values.
std::vector< DATATYPE > VectorType
The type of the std::vector stored by this property.
Provides a robust lexical cast from strings to numeric types with a fallback for edge-case values.
#define MITK_ERROR
Log an error message.
Find image slices visible on a given plane.
VectorPropertySerializer< int > IntVectorPropertySerializer
Convenience typedef for a VectorPropertySerializer specialized for int values.
VectorPropertySerializer< double > DoubleVectorPropertySerializer
Convenience typedef for a VectorPropertySerializer specialized for double values.
Helper trait for VectorProperty to determine a good ITK class name prefix.