Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
mitkGenericProperty.h
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 mitkGenericProperty_h
14 #define mitkGenericProperty_h
15 
16 #include <sstream>
17 #include <cstdlib>
18 #include <string>
19 
20 #include "mitkBaseProperty.h"
21 #include "mitkNumericTypes.h"
22 #include <MitkCoreExports.h>
23 
24 namespace mitk
25 {
26 #ifdef _MSC_VER
27 #pragma warning(push)
28 #pragma warning(disable : 4522)
29 #endif
30 
45  template <typename T>
47  {
48  public:
51  itkCloneMacro(Self);
52 
53  typedef T ValueType;
54 
55  itkSetMacro(Value, T);
56  itkGetConstMacro(Value, T);
57 
58  std::string GetValueAsString() const override
59  {
60  std::stringstream myStr;
61  myStr << GetValue();
62  return myStr.str();
63  }
64 
65  bool ToJSON(nlohmann::json&) const override
66  {
67  return false;
68  }
69 
70  bool FromJSON(const nlohmann::json&) override
71  {
72  return false;
73  }
74 
75  using BaseProperty::operator=;
76 
77  protected:
79  GenericProperty(T x) : m_Value(x) {}
80  GenericProperty(const GenericProperty &other) : BaseProperty(other), m_Value(other.m_Value) {}
82 
83  private:
84  // purposely not implemented
85  GenericProperty &operator=(const GenericProperty &);
86 
87  itk::LightObject::Pointer InternalClone() const override
88  {
89  itk::LightObject::Pointer result(new Self(*this));
90  result->UnRegister();
91  return result;
92  }
93 
94  bool IsEqual(const BaseProperty &other) const override
95  {
96  return (this->m_Value == static_cast<const Self &>(other).m_Value);
97  }
98 
99  bool Assign(const BaseProperty &other) override
100  {
101  this->m_Value = static_cast<const Self &>(other).m_Value;
102  return true;
103  }
104  };
105 
106 #ifdef _MSC_VER
107 #pragma warning(pop)
108 #endif
109 
110 } // namespace mitk
111 
120 #define mitkDeclareGenericProperty(PropertyName, Type, Export) \
121  \
122  class Export PropertyName : public GenericProperty<Type> \
123  \
124  { \
125  public: \
126  mitkClassMacro(PropertyName, GenericProperty<Type>); \
127  itkFactorylessNewMacro(Self); \
128  itkCloneMacro(Self); \
129  mitkNewMacro1Param(PropertyName, Type); \
130  \
131  bool ToJSON(nlohmann::json& j) const override; \
132  bool FromJSON(const nlohmann::json& j) override; \
133  \
134  using BaseProperty::operator=; \
135  \
136  protected: \
137  PropertyName(); \
138  PropertyName(const PropertyName &); \
139  PropertyName(Type x); \
140  \
141  private: \
142  itk::LightObject::Pointer InternalClone() const override; \
143  };
144 
145 #define mitkDefineGenericProperty(PropertyName, Type, DefaultValue) \
146  mitk::PropertyName::PropertyName() : Superclass(DefaultValue) {} \
147  mitk::PropertyName::PropertyName(const PropertyName &other) : GenericProperty<Type>(other) {} \
148  mitk::PropertyName::PropertyName(Type x) : Superclass(x) {} \
149  itk::LightObject::Pointer mitk::PropertyName::InternalClone() const \
150  { \
151  itk::LightObject::Pointer result(new Self(*this)); \
152  result->UnRegister(); \
153  return result; \
154  } \
155  bool mitk::PropertyName::ToJSON(nlohmann::json& j) const \
156  { \
157  j = this->GetValue(); \
158  return true; \
159  } \
160  \
161  bool mitk::PropertyName::FromJSON(const nlohmann::json& j) \
162  { \
163  this->SetValue(j.get<Type>()); \
164  return true; \
165  }
166 
167 #endif
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitk::GenericProperty::ToJSON
bool ToJSON(nlohmann::json &) const override
Serialize property value(s) to JSON.
Definition: mitkGenericProperty.h:65
mitk::GenericProperty::m_Value
T m_Value
Definition: mitkGenericProperty.h:81
mitkNewMacro1Param
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:68
mitk::GenericProperty::FromJSON
bool FromJSON(const nlohmann::json &) override
Deserialize property value(s) from JSON.
Definition: mitkGenericProperty.h:70
MITK_EXPORT
#define MITK_EXPORT
Definition: mitkCommon.h:191
mitk::GenericProperty
Definition: mitkGenericProperty.h:46
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::GenericProperty::GetValueAsString
std::string GetValueAsString() const override
Definition: mitkGenericProperty.h:58
mitk::GenericProperty::GenericProperty
GenericProperty(const GenericProperty &other)
Definition: mitkGenericProperty.h:80
json
nlohmann::json json
Definition: mitkModelTestFixture.h:29
MitkCoreExports.h
mitk::GenericProperty::GenericProperty
GenericProperty(T x)
Definition: mitkGenericProperty.h:79
mitkNumericTypes.h
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::GenericProperty::GenericProperty
GenericProperty()
Definition: mitkGenericProperty.h:78
mitkBaseProperty.h
mitk::GenericProperty::ValueType
T ValueType
Definition: mitkGenericProperty.h:51