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