Medical Imaging Interaction Toolkit  2018.4.99-9c019225
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 
230 org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::SmartPointer<const berry::Object>& o);
231 org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::SmartPointer<berry::Object>& o);
232 
233 org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::Object& o);
234 org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer<const berry::Object>& o);
235 //org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer<berry::Object>& o);
236 
237 Q_DECLARE_METATYPE(berry::Object::Pointer)
238 
240 
241 #endif /*BERRYOBJECT_H_*/
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:83
QString GetClassName(const Object *obj)
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
void RemoveDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:155
bool operator<(const StaticParameterMap::ValueType &a, const StaticParameterMap::ValueType &b)
Compares two var lists and returns true if the first list&#39;s first item is lower than the second one&#39;s...
Indent(int ind=0)
Definition: berryObject.h:47
org_blueberry_core_runtime_EXPORT uint qHash(const berry::Object &o)
berry::WeakPointer< const Self > ConstWeakPtr
Definition: berryObject.h:85
void AddDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:153
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
void UnRegister(bool del=true) const
#define org_blueberry_core_runtime_EXPORT
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:82
int GetReferenceCount() const
Definition: berryObject.h:144
static void cleanup(Object *obj)
Definition: berryObject.h:211
unsigned int uint
QAtomicInt m_ReferenceCount
Definition: berryObject.h:191
berry::WeakPointer< Self > WeakPtr
Definition: berryObject.h:84
Event/message/notification class.
Definition: berryMessage.h:716
QDebug operator<<(QDebug os, const berry::Indent &ind)
QMutex m_ReferenceCountLock
Definition: berryObject.h:194
QList< TypeInfo > GetSuperclasses()