Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
44  template <typename T>
46  {
47  public:
50  itkCloneMacro(Self);
51 
52  typedef T ValueType;
53 
54  itkSetMacro(Value, T);
55  itkGetConstMacro(Value, T);
56 
57  std::string GetValueAsString() const override
58  {
59  std::stringstream myStr;
60  myStr << GetValue();
61  return myStr.str();
62  }
63 
64  using BaseProperty::operator=;
65 
66  protected:
68  GenericProperty(T x) : m_Value(x) {}
69  GenericProperty(const GenericProperty &other) : BaseProperty(other), m_Value(other.m_Value) {}
71 
72  private:
73  // purposely not implemented
74  GenericProperty &operator=(const GenericProperty &);
75 
76  itk::LightObject::Pointer InternalClone() const override
77  {
78  itk::LightObject::Pointer result(new Self(*this));
79  result->UnRegister();
80  return result;
81  }
82 
83  bool IsEqual(const BaseProperty &other) const override
84  {
85  return (this->m_Value == static_cast<const Self &>(other).m_Value);
86  }
87 
88  bool Assign(const BaseProperty &other) override
89  {
90  this->m_Value = static_cast<const Self &>(other).m_Value;
91  return true;
92  }
93  };
94 
95 #ifdef _MSC_VER
96 #pragma warning(pop)
97 #endif
98 
99 } // namespace mitk
100 
109 #define mitkDeclareGenericProperty(PropertyName, Type, Export) \
110  \
111  class Export PropertyName : public GenericProperty<Type> \
112  \
113  { \
114  public: \
115  mitkClassMacro(PropertyName, GenericProperty<Type>); \
116  itkFactorylessNewMacro(Self); \
117  itkCloneMacro(Self); \
118  mitkNewMacro1Param(PropertyName, Type); \
119  \
120  using BaseProperty::operator=; \
121  \
122  protected: \
123  PropertyName(); \
124  PropertyName(const PropertyName &); \
125  PropertyName(Type x); \
126  \
127  private: \
128  itk::LightObject::Pointer InternalClone() const override; \
129  };
130 
131 #define mitkDefineGenericProperty(PropertyName, Type, DefaultValue) \
132  mitk::PropertyName::PropertyName() : Superclass(DefaultValue) {} \
133  mitk::PropertyName::PropertyName(const PropertyName &other) : GenericProperty<Type>(other) {} \
134  mitk::PropertyName::PropertyName(Type x) : Superclass(x) {} \
135  itk::LightObject::Pointer mitk::PropertyName::InternalClone() const \
136  { \
137  itk::LightObject::Pointer result(new Self(*this)); \
138  result->UnRegister(); \
139  return result; \
140  }
141 
142 #endif
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:35
mitk::GenericProperty::m_Value
T m_Value
Definition: mitkGenericProperty.h:70
mitkNewMacro1Param
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:68
MITK_EXPORT
#define MITK_EXPORT
Definition: mitkCommon.h:191
mitk::GenericProperty
Definition: mitkGenericProperty.h:45
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::GenericProperty::GetValueAsString
std::string GetValueAsString() const override
Definition: mitkGenericProperty.h:57
mitk::GenericProperty::GenericProperty
GenericProperty(const GenericProperty &other)
Definition: mitkGenericProperty.h:69
MitkCoreExports.h
mitk::GenericProperty::GenericProperty
GenericProperty(T x)
Definition: mitkGenericProperty.h:68
mitkNumericTypes.h
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::GenericProperty::GenericProperty
GenericProperty()
Definition: mitkGenericProperty.h:67
mitkBaseProperty.h
mitk::GenericProperty::ValueType
T ValueType
Definition: mitkGenericProperty.h:50