Medical Imaging Interaction Toolkit  2023.04.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 
101 
102 #ifdef _WIN32
103 
104  void* operator new(size_t);
105  void* operator new[](size_t);
106  void operator delete(void*);
107  void operator delete[](void*, size_t);
108 #endif
109 
116  QDebug Print(QDebug os, Indent Indent=0) const;
117 
122  virtual QString ToString() const;
123 
127  virtual uint HashCode() const;
128 
133  virtual bool operator<(const Object*) const;
134 
136  void Register() const;
137 
141  void UnRegister(bool del = true) const;
142 
144  int GetReferenceCount() const
145  {
146  return m_ReferenceCount.load();
147  }
148 
151  void SetReferenceCount(int);
152 
153  inline void AddDestroyListener(const MessageAbstractDelegate<>& delegate) const
154  { m_DestroyMessage += delegate; }
155  inline void RemoveDestroyListener(const MessageAbstractDelegate<>& delegate) const
156  { m_DestroyMessage -= delegate; }
157 
158 
163  virtual bool operator==(const Object*) const;
164 
165 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER
166  unsigned int GetTraceId() const;
167 private:
168  unsigned int m_TraceId;
169  unsigned int& GetTraceIdCounter() const;
170 public:
171 #endif
172 
173 protected:
174 
176 
177  Object();
178  virtual ~Object();
179 
186  virtual QDebug PrintSelf(QDebug os, Indent indent) const;
187  virtual QDebug PrintHeader(QDebug os, Indent indent) const;
188  virtual QDebug PrintTrailer(QDebug os, Indent indent) const;
189 
191  mutable QAtomicInt m_ReferenceCount;
192 
194  mutable QMutex m_ReferenceCountLock;
195 
196 private:
197 
198  Object(const Self&); //purposely not implemented
199  void operator=(const Self&); //purposely not implemented
200 
201 };
202 
203 // A custom deleter for QScopedPointer
204 // berry::Object instances in a QScopedPointer should have reference count one,
205 // such that they are not accidentally deleted when a temporary smart pointer
206 // pointing to it goes out of scope. This deleter fixes the reference count and
207 // always deletes the instance. Use a berry::SmartPointer if the lifetime should
208 // exceed the one of the pointer.
210 {
211  static inline void cleanup(Object* obj)
212  {
213  if (obj == nullptr) return;
214  obj->UnRegister(false);
215  delete obj;
216  }
217 };
218 
220 
221 }
222 
232 
233 org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::Object& o);
235 //org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer<berry::Object>& o);
236 
238 
240 
241 #endif /*BERRYOBJECT_H_*/
org_blueberry_core_runtime_Export.h
berry::Object::AddDestroyListener
void AddDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:153
berry::Object::m_ReferenceCount
QAtomicInt m_ReferenceCount
Definition: berryObject.h:191
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:211
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:155
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:209
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:144
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:194