Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE
00020 #define MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE
00021
00022 #include <string>
00023 #include <sstream>
00024 #include <stdlib.h>
00025
00026 #include "mitkVector.h"
00027 #include "mitkCommon.h"
00028 #include "mitkBaseProperty.h"
00029
00030 namespace mitk {
00031
00045 template <typename T>
00046 class GenericProperty : public BaseProperty
00047 {
00048 public:
00049
00050 mitkClassMacro(GenericProperty, BaseProperty);
00051 mitkNewMacro1Param(GenericProperty<T>, T);
00052
00053 typedef T ValueType;
00054
00055 virtual ~GenericProperty()
00056 {
00057 }
00058
00059 itkSetMacro(Value,T);
00060 itkGetConstMacro(Value,T);
00061
00062 virtual bool operator==(const BaseProperty& other) const
00063 {
00064 try
00065 {
00066 const Self *otherProp = dynamic_cast<const Self*>(&other);
00067 if(otherProp==NULL) return false;
00068 if (this->m_Value == otherProp->m_Value) return true;
00069 }
00070 catch (std::bad_cast)
00071 {
00072
00073 }
00074
00075 return false;
00076 }
00077
00078 virtual std::string GetValueAsString() const
00079 {
00080 std::stringstream myStr;
00081 myStr << GetValue() ;
00082 return myStr.str();
00083 }
00084
00085 virtual bool Assignable(const BaseProperty& other) const
00086 {
00087 try
00088 {
00089 dynamic_cast<const Self&>(other);
00090 return true;
00091 }
00092 catch (std::bad_cast)
00093 {
00094 }
00095 return false;
00096 }
00097
00098 virtual BaseProperty& operator=(const BaseProperty& other)
00099 {
00100 try
00101 {
00102 const Self& otherProp( dynamic_cast<const Self&>(other) );
00103
00104 if (this->m_Value != otherProp.m_Value)
00105 {
00106 this->m_Value = otherProp.m_Value;
00107 this->Modified();
00108 }
00109 }
00110 catch (std::bad_cast)
00111 {
00112
00113 }
00114
00115 return *this;
00116 }
00117
00118 protected:
00119 GenericProperty() {}
00120 GenericProperty(T x)
00121 : m_Value(x) {}
00122 T m_Value;
00123 };
00124
00125 }
00126
00134 #define mitkSpecializeGenericProperty(PropertyName,Type,DefaultValue) \
00135 class MITK_CORE_EXPORT PropertyName: public GenericProperty< Type > \
00136 { \
00137 public: \
00138 mitkClassMacro(PropertyName, GenericProperty< Type >); \
00139 itkNewMacro(PropertyName); \
00140 mitkNewMacro1Param(PropertyName, Type); \
00141 virtual ~PropertyName() {} \
00142 protected: \
00143 PropertyName() { m_Value = DefaultValue; } \
00144 PropertyName(Type x) : GenericProperty<Type>(x) {} \
00145 };
00146
00147 #endif
00148
00149