Medical Imaging Interaction Toolkit  2016.11.0
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,
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 MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE
18 #define MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE
19 
20 #include <sstream>
21 #include <stdlib.h>
22 #include <string>
23 
24 #include "mitkBaseProperty.h"
25 #include "mitkNumericTypes.h"
26 #include <MitkCoreExports.h>
27 
28 namespace mitk
29 {
30 #ifdef _MSC_VER
31 #pragma warning(push)
32 #pragma warning(disable : 4522)
33 #endif
34 
48  template <typename T>
50  {
51  public:
54  itkCloneMacro(Self)
55 
56  typedef T ValueType;
57 
58  itkSetMacro(Value, T);
59  itkGetConstMacro(Value, T);
60 
61  virtual std::string GetValueAsString() const override
62  {
63  std::stringstream myStr;
64  myStr << GetValue();
65  return myStr.str();
66  }
67 
68  using BaseProperty::operator=;
69 
70  protected:
72  GenericProperty(T x) : m_Value(x) {}
73  GenericProperty(const GenericProperty &other) : BaseProperty(other), m_Value(other.m_Value) {}
75 
76  private:
77  // purposely not implemented
78  GenericProperty &operator=(const GenericProperty &);
79 
80  virtual itk::LightObject::Pointer InternalClone() const override
81  {
82  itk::LightObject::Pointer result(new Self(*this));
83  result->UnRegister();
84  return result;
85  }
86 
87  virtual bool IsEqual(const BaseProperty &other) const override
88  {
89  return (this->m_Value == static_cast<const Self &>(other).m_Value);
90  }
91 
92  virtual bool Assign(const BaseProperty &other) override
93  {
94  this->m_Value = static_cast<const Self &>(other).m_Value;
95  return true;
96  }
97  };
98 
99 #ifdef _MSC_VER
100 #pragma warning(pop)
101 #endif
102 
103 } // namespace mitk
104 
113 #define mitkDeclareGenericProperty(PropertyName, Type, Export) \
114  \
115  class Export PropertyName : public GenericProperty<Type> \
116  \
117  { \
118  public: \
119  mitkClassMacro(PropertyName, GenericProperty<Type>) itkFactorylessNewMacro(Self) itkCloneMacro(Self) \
120  mitkNewMacro1Param(PropertyName, Type) 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 /* MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE */
itk::SmartPointer< Self > Pointer
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:76
GenericProperty(const GenericProperty &other)
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
Abstract base class for properties.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
#define MITK_EXPORT
Definition: mitkCommon.h:199