Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
berryObjectGeneric.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 
14 #ifndef BERRYOBJECTGENERIC_H_
15 #define BERRYOBJECTGENERIC_H_
16 
17 #include <sstream>
19 #include "berryMacros.h"
20 #include "berryObject.h"
21 
22 namespace berry {
23 
24 template <typename T>
26 {
27  public:
28 
30 
31  typedef T ValueType;
32 
33  ObjectGeneric() : m_Value(0) {}
34  ObjectGeneric(T x) : m_Value(x) {}
35  //ObjectGeneric(const Self& o) { m_Value = o.m_Value; }
36 
37  ~ObjectGeneric() override
38  {
39  }
40 
41  void SetValue(T val) {
42  m_Value = val;
43  }
44 
45  T GetValue() const {
46  return m_Value;
47  }
48 
49  bool operator==(const Object* o) const override
50  {
51  if(const Self* other = dynamic_cast<const Self*>(o))
52  return (this->m_Value == other->m_Value);
53 
54  return false;
55  }
56 
57  virtual std::string GetValueAsString() const
58  {
59  std::stringstream myStr;
60  std::locale originalLocale = myStr.getloc();
61  std::locale C("C");
62  myStr.imbue(C);
63  myStr << GetValue() ;
64  myStr.imbue(originalLocale);
65  return myStr.str();
66  }
67 
68  virtual bool Assignable(Object::ConstPointer other) const
69  {
70  return other.Cast<const Self>() != 0;
71  }
72 
73  virtual void Assign(Object::ConstPointer other)
74  {
75  ConstPointer specOther = other.Cast<const Self>();
76 
77  if (specOther && this->m_Value != specOther->m_Value)
78  {
79  this->m_Value = specOther->m_Value;
80  }
81  }
82 
83  protected:
84 
86 };
87 
88 
89 } // namespace berry
90 
99 #define berrySpecializeGenericObject(ObjectName,Type,DefaultValue) \
100 class org_blueberry_core_runtime_EXPORT ObjectName: public ::berry::ObjectGeneric< Type > \
101 { \
102 public: \
103  berryObjectMacro(ObjectName); \
104  ObjectName() : ::berry::ObjectGeneric< Type >(DefaultValue) { } \
105  ObjectName(Type x) : ::berry::ObjectGeneric<Type>(x) {} \
106  QString ToString() const { QString txt; QTextStream ts(&txt); ts << m_Value; return txt; } \
107 };
108 
109 
110 #endif /* BERRYOBJECTGENERIC_H_ */
berry::ObjectGeneric::ValueType
T ValueType
Definition: berryObjectGeneric.h:31
org_blueberry_core_runtime_Export.h
berry::ObjectGeneric::GetValue
T GetValue() const
Definition: berryObjectGeneric.h:45
berry::ObjectGeneric::GetValueAsString
virtual std::string GetValueAsString() const
Definition: berryObjectGeneric.h:57
berry::ObjectGeneric::operator==
bool operator==(const Object *o) const override
Definition: berryObjectGeneric.h:49
berryMacros.h
berry::SmartPointer
Implements transparent reference counting.
Definition: berryICommandCategoryListener.h:21
berry::ObjectGeneric::Assign
virtual void Assign(Object::ConstPointer other)
Definition: berryObjectGeneric.h:73
berry::ObjectGeneric
Definition: berryObjectGeneric.h:25
berry::ObjectGeneric::m_Value
T m_Value
Definition: berryObjectGeneric.h:85
berry::Object
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
org_blueberry_core_runtime_EXPORT
#define org_blueberry_core_runtime_EXPORT
Definition: org_blueberry_core_runtime_Export.h:26
berry::ObjectGeneric::ObjectGeneric
ObjectGeneric(T x)
Definition: berryObjectGeneric.h:34
berry::ObjectGeneric::SetValue
void SetValue(T val)
Definition: berryObjectGeneric.h:41
berry::ObjectGeneric::~ObjectGeneric
~ObjectGeneric() override
Definition: berryObjectGeneric.h:37
berryObjectMacro
#define berryObjectMacro(...)
Definition: berryMacros.h:33
berry::SmartPointer::Cast
SmartPointer< Other > Cast() const
Definition: berrySmartPointer.h:111
berryObject.h
berry::ObjectGeneric::Assignable
virtual bool Assignable(Object::ConstPointer other) const
Definition: berryObjectGeneric.h:68
berry
Definition: QmitkPropertyItemModel.h:24
berry::ObjectGeneric::ObjectGeneric
ObjectGeneric()
Definition: berryObjectGeneric.h:33