Medical Imaging Interaction Toolkit  2021.02.99-00f000b3
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_ */
virtual void Assign(Object::ConstPointer other)
virtual std::string GetValueAsString() const
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
SmartPointer< Other > Cast() const
bool operator==(const Object *o) const override
#define org_blueberry_core_runtime_EXPORT
#define berryObjectMacro(...)
Definition: berryMacros.h:33
virtual bool Assignable(Object::ConstPointer other) const