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