Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryObject.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 #ifndef BERRYOBJECT_H_
18 #define BERRYOBJECT_H_
19 
21 
22 #include "berryMacros.h"
23 #include "berryMessage.h"
24 
25 #include <berryConfig.h>
26 
27 #include <QString>
28 #include <QMetaType>
29 #include <QMutex>
30 #include <QAtomicInt>
31 
32 #ifdef _MSC_VER
33 // disable inheritance by dominance warnings
34 #pragma warning( disable : 4250 4275 4251 )
35 // disable warning: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
36 #pragma warning( disable : 4290 )
37 #endif
38 
39 class QDebug;
40 class QTextStream;
41 
42 namespace berry {
43 
45 {
46 
47 public:
48 
50  typedef Indent Self;
51 
53  Indent(int ind = 0) { m_Indent=ind; }
54 
59  Indent GetNextIndent();
60 
62  friend org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const Indent& o);
63 
64 private:
65 
66  int m_Indent;
67 };
68 
69 
79 {
80 
81 private:
82 
83  mutable Message<> m_DestroyMessage;
84 
85 public:
86 
87  typedef Object Self;
92 
93  static const char* GetStaticClassName();
94  virtual QString GetClassName() const;
95 
96  static Reflection::TypeInfo GetStaticTypeInfo();
97  virtual Reflection::TypeInfo GetTypeInfo() const;
98 
99  static QList<Reflection::TypeInfo> GetStaticSuperclasses();
100  virtual QList<Reflection::TypeInfo> GetSuperclasses() const;
101 
105  virtual void Delete();
106 
107 
108 #ifdef _WIN32
109 
110  void* operator new(size_t);
111  void* operator new[](size_t);
112  void operator delete(void*);
113  void operator delete[](void*, size_t);
114 #endif
115 
122  QDebug Print(QDebug os, Indent Indent=0) const;
123 
128  virtual QString ToString() const;
129 
133  virtual uint HashCode() const;
134 
139  virtual bool operator<(const Object*) const;
140 
142  void Register() const;
143 
147  void UnRegister(bool del = true) const;
148 
150  int GetReferenceCount() const
151  {
152  return m_ReferenceCount.load();
153  }
154 
157  void SetReferenceCount(int);
158 
159  inline void AddDestroyListener(const MessageAbstractDelegate<>& delegate) const
160  { m_DestroyMessage += delegate; }
161  inline void RemoveDestroyListener(const MessageAbstractDelegate<>& delegate) const
162  { m_DestroyMessage -= delegate; }
163 
164 
169  virtual bool operator==(const Object*) const;
170 
171 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER
172  unsigned int GetTraceId() const;
173 private:
174  unsigned int m_TraceId;
175  unsigned int& GetTraceIdCounter() const;
176 public:
177 #endif
178 
179 protected:
180 
182 
183  Object();
184  virtual ~Object();
185 
192  virtual QDebug PrintSelf(QDebug os, Indent indent) const;
193  virtual QDebug PrintHeader(QDebug os, Indent indent) const;
194  virtual QDebug PrintTrailer(QDebug os, Indent indent) const;
195 
197  mutable QAtomicInt m_ReferenceCount;
198 
200  mutable QMutex m_ReferenceCountLock;
201 
202 private:
203 
204  Object(const Self&); //purposely not implemented
205  void operator=(const Self&); //purposely not implemented
206 
207 };
208 
209 // A custom deleter for QScopedPointer
210 // berry::Object instances in a QScopedPointer should have reference count one,
211 // such that they are not accidentally deleted when a temporary smart pointer
212 // pointing to it goes out of scope. This deleter fixes the reference count and
213 // always deletes the instance. Use a berry::SmartPointer if the lifetime should
214 // exceed the one of the pointer.
216 {
217  static inline void cleanup(Object* obj)
218  {
219  if (obj == nullptr) return;
220  obj->UnRegister(false);
221  delete obj;
222  }
223 };
224 
226 
227 }
228 
236 org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::SmartPointer<const berry::Object>& o);
237 org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::SmartPointer<berry::Object>& o);
238 
239 org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::Object& o);
240 org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer<const berry::Object>& o);
241 //org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer<berry::Object>& o);
242 
243 Q_DECLARE_METATYPE(berry::Object::Pointer)
244 
246 
247 #endif /*BERRYOBJECT_H_*/
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:89
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::Object &o)
void UnRegister(bool del=true) const
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
Indent(int ind=0)
Definition: berryObject.h:53
org_blueberry_core_runtime_EXPORT uint qHash(const berry::Object &o)
berry::WeakPointer< const Self > ConstWeakPtr
Definition: berryObject.h:91
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
#define org_blueberry_core_runtime_EXPORT
int GetReferenceCount() const
Definition: berryObject.h:150
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:88
void AddDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:159
static void cleanup(Object *obj)
Definition: berryObject.h:217
unsigned int uint
QAtomicInt m_ReferenceCount
Definition: berryObject.h:197
berry::WeakPointer< Self > WeakPtr
Definition: berryObject.h:90
Event/message/notification class.
Definition: berryMessage.h:720
QDebug operator<<(QDebug os, const berry::Indent &ind)
QMutex m_ReferenceCountLock
Definition: berryObject.h:200
QList< TypeInfo > GetSuperclasses()
virtual const char * GetClassName() const
void RemoveDestroyListener(const MessageAbstractDelegate<> &delegate) const
Definition: berryObject.h:161