Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkStringPropertySerializer.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef mitkStringPropertySerializer_h_included
18 #define mitkStringPropertySerializer_h_included
19 
21 
22 #include "mitkStringProperty.h"
23 
24 namespace mitk
25 {
26  class StringPropertySerializer : public BasePropertySerializer
27  {
28  public:
29  mitkClassMacro(StringPropertySerializer, BasePropertySerializer);
30  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
31 
32  virtual TiXmlElement *Serialize() override
33  {
34  if (const StringProperty *prop = dynamic_cast<const StringProperty *>(m_Property.GetPointer()))
35  {
36  auto element = new TiXmlElement("string");
37  element->SetAttribute("value", prop->GetValue());
38  return element;
39  }
40  else
41  return nullptr;
42  }
43 
44  virtual BaseProperty::Pointer Deserialize(TiXmlElement *element) override
45  {
46  if (!element)
47  return nullptr;
48  const char *s(element->Attribute("value"));
49  return StringProperty::New(std::string(s ? s : "")).GetPointer();
50  }
51 
52  protected:
53  StringPropertySerializer() {}
54  virtual ~StringPropertySerializer() {}
55  };
56 
57 } // namespace
58 
59 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
60 MITK_REGISTER_SERIALIZER(StringPropertySerializer);
61 
62 #endif
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
MITK_REGISTER_SERIALIZER(StringPropertySerializer)
static Pointer New()