Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
berryObject.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 #ifndef BERRYOBJECT_H_
14 #define BERRYOBJECT_H_
15 
17 
18 #include "berryMacros.h"
19 #include "berryMessage.h"
20 
21 #include <berryConfig.h>
22 
23 #include <QString>
24 #include <QMetaType>
25 #include <QMutex>
26 #include <QAtomicInt>
27 
28 #ifdef _MSC_VER
29 // disable inheritance by dominance warnings
30 #pragma warning( disable : 4250 4275 )
31 #endif
32 
33 class QDebug;
34 class QTextStream;
35 
36 namespace berry {
37 
39 {
40 
41 public:
42 
44  typedef Indent Self;
45 
47  Indent(int ind = 0) { m_Indent=ind; }
48 
53  Indent GetNextIndent();
54 
56  friend org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const Indent& o);
57 
58 private:
59 
60  int m_Indent;
61 };
62 
63 
73 {
74 
75 private:
76 
77  mutable Message<> m_DestroyMessage;
78 
79 public:
80 
81  typedef Object Self;
86 
87  static const char* GetStaticClassName();
88  virtual QString GetClassName() const;
89 
90  static Reflection::TypeInfo GetStaticTypeInfo();
91  virtual Reflection::TypeInfo GetTypeInfo() const;
92 
93  static QList<Reflection::TypeInfo> GetStaticSuperclasses();
94  virtual QList<Reflection::TypeInfo> GetSuperclasses() const;
95 
99  virtual void Delete();
100 
107  QDebug Print(QDebug os, Indent Indent=0) const;
108 
113  virtual QString ToString() const;
114 
118  virtual uint HashCode() const;
119 
124  virtual bool operator<(const Object*) const;
125 
127  void Register() const;
128 
132  void UnRegister(bool del = true) const;
133 
135  int GetReferenceCount() const
136  {
137  return m_ReferenceCount.loadRelaxed();
138  }
139 
142  void SetReferenceCount(int);
143 
144  inline void AddDestroyListener(const MessageAbstractDelegate<>& delegate) const
145  { m_DestroyMessage += delegate; }
146  inline void RemoveDestroyListener(const MessageAbstractDelegate<>& delegate) const
147  { m_DestroyMessage -= delegate; }
148 
149 
154  virtual bool operator==(const Object*) const;
155 
156 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER
157  unsigned int GetTraceId() const;
158 private:
159  unsigned int m_TraceId;
160  unsigned int& GetTraceIdCounter() const;
161 public:
162 #endif
163 
164 protected:
165 
167 
168  Object();
169  virtual ~Object();
170 
177  virtual QDebug PrintSelf(QDebug os, Indent indent) const;
178  virtual QDebug PrintHeader(QDebug os, Indent indent) const;
179  virtual QDebug PrintTrailer(QDebug os, Indent indent) const;
180 
182  mutable QAtomicInt m_ReferenceCount;
183 
185  mutable QMutex m_ReferenceCountLock;
186 
187 private:
188 
189  Object(const Self&); //purposely not implemented
190  void operator=(const Self&); //purposely not implemented
191 
192 };
193 
194 // A custom deleter for QScopedPointer
195 // berry::Object instances in a QScopedPointer should have reference count one,
196 // such that they are not accidentally deleted when a temporary smart pointer
197 // pointing to it goes out of scope. This deleter fixes the reference count and
198 // always deletes the instance. Use a berry::SmartPointer if the lifetime should
199 // exceed the one of the pointer.
201 {
202  static inline void cleanup(Object* obj)
203  {
204  if (obj == nullptr) return;
205  obj->UnRegister(false);
206  delete obj;
207  }
208 };
209 
211 
212 }
213 
223 
224 org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::Object& o);
226 //org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer<berry::Object>& o);
227 
229 
231 
232 #endif /*BERRYOBJECT_H_*/
org_blueberry_core_runtime_Export.h
berry::Object::AddDestroyListener
void AddDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:144
berry::Object::m_ReferenceCount
QAtomicInt m_ReferenceCount
Definition: berryObject.h:182
berry::Reflection::GetClassName
org_blueberry_core_runtime_EXPORT QString GetClassName(const Object *obj)
berry::Indent::Self
Indent Self
Definition: berryObject.h:44
berry::QScopedPointerObjectDeleter::cleanup
static void cleanup(Object *obj)
Definition: berryObject.h:202
berryMacros.h
berry::MessageAbstractDelegate
Definition: berryMessage.h:54
mitk::modelFit::operator<
bool operator<(const StaticParameterMap::ValueType &a, const StaticParameterMap::ValueType &b)
Compares two var lists and returns true if the first list's first item is lower than the second one's...
Definition: mitkModelFitStaticParameterMap.h:139
berry::SmartPointer< Self >
berry::Message
Event/message/notification class.
Definition: berryMessage.h:716
berryMessage.h
berry::Object
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(mitk::ProcessExecutor::Pointer)
berry::Object::ConstWeakPtr
berry::WeakPointer< const Self > ConstWeakPtr
Definition: berryObject.h:85
berry::Indent
Definition: berryObject.h:38
berry::Object::RemoveDestroyListener
void RemoveDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:146
org_blueberry_core_runtime_EXPORT
#define org_blueberry_core_runtime_EXPORT
Definition: org_blueberry_core_runtime_Export.h:26
qHash
org_blueberry_core_runtime_EXPORT uint qHash(const berry::Object &o)
berry::Reflection::TypeInfo
Definition: berryReflection.h:139
berry::QScopedPointerObjectDeleter
Definition: berryObject.h:200
berryConfig.h
berry::Indent::Indent
Indent(int ind=0)
Definition: berryObject.h:47
mitk::operator==
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
berry::Object::UnRegister
void UnRegister(bool del=true) const
berry::Object::GetReferenceCount
int GetReferenceCount() const
Definition: berryObject.h:135
berry::Reflection::GetSuperclasses
QList< TypeInfo > GetSuperclasses()
Definition: berryReflection.h:220
berry::Object::ConstPointer
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:83
berry::operator<<
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::Indent &o)
berry::Object::Pointer
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:82
berry::Object::WeakPtr
berry::WeakPointer< Self > WeakPtr
Definition: berryObject.h:84
berry::WeakPointer
implements a WeakPointer class to deal with circular reference problems.
Definition: berrySmartPointer.h:32
berry::Object::Self
Object Self
Definition: berryObject.h:81
berry
Definition: QmitkPropertyItemModel.h:24
operator<<
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::Object &o)
berry::Object::m_ReferenceCountLock
QMutex m_ReferenceCountLock
Definition: berryObject.h:185