Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkBoolPropertySerializer.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 mitkBoolPropertySerializer_h_included
18 #define mitkBoolPropertySerializer_h_included
19 
21 
22 #include "mitkProperties.h"
23 
24 namespace mitk
25 {
26  class BoolPropertySerializer : public BasePropertySerializer
27  {
28  public:
29  mitkClassMacro(BoolPropertySerializer, BasePropertySerializer);
30  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
31 
32  virtual TiXmlElement *Serialize() override
33  {
34  if (const BoolProperty *prop = dynamic_cast<const BoolProperty *>(m_Property.GetPointer()))
35  {
36  auto element = new TiXmlElement("bool");
37  if (prop->GetValue() == true)
38  {
39  element->SetAttribute("value", "true");
40  }
41  else
42  {
43  element->SetAttribute("value", "false");
44  }
45  return element;
46  }
47  else
48  return nullptr;
49  }
50 
51  virtual BaseProperty::Pointer Deserialize(TiXmlElement *element) override
52  {
53  if (!element)
54  return nullptr;
55  return BoolProperty::New(std::string(element->Attribute("value")) == "true").GetPointer();
56  }
57 
58  protected:
59  BoolPropertySerializer() {}
60  virtual ~BoolPropertySerializer() {}
61  };
62 
63 } // namespace
64 
65 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
66 MITK_REGISTER_SERIALIZER(BoolPropertySerializer);
67 
68 #endif
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
static Pointer New()
MITK_REGISTER_SERIALIZER(BoolPropertySerializer)
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44