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
mitkUIntPropertySerializer.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 mitkUIntPropertySerializer_h_included
18 #define mitkUIntPropertySerializer_h_included
19 
21 
22 #include "mitkProperties.h"
23 
24 namespace mitk
25 {
26  class UIntPropertySerializer : public BasePropertySerializer
27  {
28  public:
29  mitkClassMacro(UIntPropertySerializer, BasePropertySerializer);
30  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
31 
32  virtual TiXmlElement *Serialize() override
33  {
34  if (const UIntProperty *prop = dynamic_cast<const UIntProperty *>(m_Property.GetPointer()))
35  {
36  auto element = new TiXmlElement("unsigned");
37  element->SetAttribute("value", static_cast<unsigned int>(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  unsigned int integer;
50  if (element->QueryUnsignedAttribute("value", &integer) == TIXML_SUCCESS)
51  {
52  return UIntProperty::New(integer).GetPointer();
53  }
54  else
55  {
56  return nullptr;
57  }
58  }
59 
60  protected:
61  UIntPropertySerializer() {}
62  virtual ~UIntPropertySerializer() {}
63  };
64 
65 } // namespace
66 
67 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
68 MITK_REGISTER_SERIALIZER(UIntPropertySerializer);
69 
70 #endif
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
MITK_REGISTER_SERIALIZER(UIntPropertySerializer)
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
static Pointer New()