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