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