Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkStringPropertySerializer_h_included
14 #define mitkStringPropertySerializer_h_included
15 
17 
18 #include "mitkStringProperty.h"
19 
20 namespace mitk
21 {
22  class StringPropertySerializer : public BasePropertySerializer
23  {
24  public:
25  mitkClassMacro(StringPropertySerializer, BasePropertySerializer);
26  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
27 
28  TiXmlElement *Serialize() override
29  {
30  if (const StringProperty *prop = dynamic_cast<const StringProperty *>(m_Property.GetPointer()))
31  {
32  auto element = new TiXmlElement("string");
33  element->SetAttribute("value", prop->GetValue());
34  return element;
35  }
36  else
37  return nullptr;
38  }
39 
40  BaseProperty::Pointer Deserialize(TiXmlElement *element) override
41  {
42  if (!element)
43  return nullptr;
44  const char *s(element->Attribute("value"));
45  return StringProperty::New(std::string(s ? s : "")).GetPointer();
46  }
47 
48  protected:
49  StringPropertySerializer() {}
50  ~StringPropertySerializer() override {}
51  };
52 
53 } // namespace
54 
55 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
56 MITK_REGISTER_SERIALIZER(StringPropertySerializer);
57 
58 #endif
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
MITK_REGISTER_SERIALIZER(StringPropertySerializer)
static Pointer New()