Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkIntPropertySerializer.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 mitkIntPropertySerializer_h_included
18 #define mitkIntPropertySerializer_h_included
19 
21 
22 #include "mitkProperties.h"
23 
24 namespace mitk
25 {
26  class IntPropertySerializer : public BasePropertySerializer
27  {
28  public:
29  mitkClassMacro(IntPropertySerializer, BasePropertySerializer);
30  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
31 
32  virtual TiXmlElement *Serialize() override
33  {
34  if (const IntProperty *prop = dynamic_cast<const IntProperty *>(m_Property.GetPointer()))
35  {
36  auto element = new TiXmlElement("int");
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 
49  int integer;
50  if (element->QueryIntAttribute("value", &integer) == TIXML_SUCCESS)
51  {
52  return IntProperty::New(integer).GetPointer();
53  }
54  else
55  {
56  return nullptr;
57  }
58  }
59 
60  protected:
61  IntPropertySerializer() {}
62  virtual ~IntPropertySerializer() {}
63  };
64 
65 } // namespace
66 
67 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
68 MITK_REGISTER_SERIALIZER(IntPropertySerializer);
69 
70 #endif
MITK_REGISTER_SERIALIZER(IntPropertySerializer)
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
static Pointer New()