VTK  9.1.0
vtkObjectBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkObjectBase.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
43 #ifndef vtkObjectBase_h
44 #define vtkObjectBase_h
45 
46 // Semantics around vtkDebugLeaks usage has changed. Now just call
47 // vtkObjectBase::InitializeObjectBase() after creating an object with New().
48 // The object factory methods take care of this automatically.
49 #define VTK_HAS_INITIALIZE_OBJECT_BASE
50 
51 #include "vtkCommonCoreModule.h" // For export macro
52 #include "vtkFeatures.h" // for VTK_USE_MEMKIND
53 #include "vtkIndent.h"
54 #include "vtkSystemIncludes.h"
55 #include "vtkType.h"
56 
57 #include <atomic> // For std::atomic
58 
60 class vtkGarbageCollectorToObjectBaseFriendship;
61 class vtkWeakPointerBase;
62 class vtkWeakPointerBaseToObjectBaseFriendship;
63 
64 // typedefs for malloc and free compatible replacement functions
65 typedef void* (*vtkMallocingFunction)(size_t);
66 typedef void* (*vtkReallocingFunction)(void*, size_t);
67 typedef void (*vtkFreeingFunction)(void*);
68 
69 class VTKCOMMONCORE_EXPORT vtkObjectBase
70 {
76  virtual const char* GetClassNameInternal() const { return "vtkObjectBase"; }
77 
78 public:
79 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
80 // Avoid windows name mangling.
81 #define GetClassNameA GetClassName
82 #define GetClassNameW GetClassName
83 #endif
84 
88  const char* GetClassName() const;
89 
90 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
91 #undef GetClassNameW
92 #undef GetClassNameA
93 
94  // Define possible mangled names.
95  const char* GetClassNameA() const;
96  const char* GetClassNameW() const;
97 
98 #endif
99 
105  static vtkTypeBool IsTypeOf(const char* name);
106 
112  virtual vtkTypeBool IsA(const char* name);
113 
123 
133 
139  virtual void Delete();
140 
148  virtual void FastDelete();
149 
154  static vtkObjectBase* New()
155  {
156  vtkObjectBase* o = new vtkObjectBase;
158  return o;
159  }
160 
161  // Called by implementations of vtkObject::New(). Centralized location for
162  // vtkDebugLeaks registration:
164 
165 #if defined(_WIN32) || defined(VTK_USE_MEMKIND)
166  // Take control of allocation to avoid dll boundary problems or to use memkind.
167  void* operator new(size_t tSize);
168  void operator delete(void* p);
169 #endif
170 
175  void Print(ostream& os);
176 
178 
184  virtual void PrintSelf(ostream& os, vtkIndent indent);
185  virtual void PrintHeader(ostream& os, vtkIndent indent);
186  virtual void PrintTrailer(ostream& os, vtkIndent indent);
188 
192  virtual void Register(vtkObjectBase* o);
193 
199  virtual void UnRegister(vtkObjectBase* o);
200 
204  int GetReferenceCount() { return this->ReferenceCount; }
205 
209  void SetReferenceCount(int);
210 
217  static void SetMemkindDirectory(const char* directoryname);
218 
220 
225  static bool GetUsingMemkind();
227 
233  class VTKCOMMONCORE_EXPORT vtkMemkindRAII
234  {
235 #ifdef VTK_USE_MEMKIND
236  bool OriginalValue;
237 #endif
238 
239  public:
240  vtkMemkindRAII(bool newValue);
242  vtkMemkindRAII(vtkMemkindRAII const&) = default;
243 
244  private:
245  void Save(bool newValue);
246  void Restore();
247  };
248 
253  bool GetIsInMemkind() const;
254 
255 protected:
257  virtual ~vtkObjectBase();
258 
259  std::atomic<int32_t> ReferenceCount;
261 
262  // Internal Register/UnRegister implementation that accounts for
263  // possible garbage collection participation. The second argument
264  // indicates whether to participate in garbage collection.
267 
268  // See vtkGarbageCollector.h:
270 
271  // Call this to call from either malloc or memkind_malloc depending on current UsingMemkind
273  // Call this to call from either realloc or memkind_realloc depending on current UsingMemkind
275  // Call this to call from either free or memkind_free depending on instance's IsInMemkind
277  // Call this to unconditionally call memkind_free
279 
280 private:
281  friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, vtkObjectBase& o);
282  friend class vtkGarbageCollectorToObjectBaseFriendship;
283  friend class vtkWeakPointerBaseToObjectBaseFriendship;
284 
285  friend class vtkMemkindRAII;
286  friend class vtkTDSCMemkindRAII;
287  static void SetUsingMemkind(bool);
288  bool IsInMemkind;
289  void SetIsInMemkind(bool);
290 
291 protected:
293  void operator=(const vtkObjectBase&) {}
294 };
295 #endif
296 
297 // VTK-HeaderTest-Exclude: vtkObjectBase.h
vtkObjectBase::WeakPointers
vtkWeakPointerBase ** WeakPointers
Definition: vtkObjectBase.h:260
vtkObjectBase::GetAlternateFreeFunction
static vtkFreeingFunction GetAlternateFreeFunction()
vtkObjectBase::operator=
void operator=(const vtkObjectBase &)
Definition: vtkObjectBase.h:293
vtkObjectBase::PrintHeader
virtual void PrintHeader(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkFreeingFunction
void(* vtkFreeingFunction)(void *)
Definition: vtkObjectBase.h:67
vtkObjectBase::GetIsInMemkind
bool GetIsInMemkind() const
A local state flag that remembers whether this object lives in the normal or extended memory space.
vtkObjectBase::Print
void Print(ostream &os)
Print an object to an ostream.
vtkObjectBase::vtkObjectBase
vtkObjectBase()
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkObjectBase::RegisterInternal
virtual void RegisterInternal(vtkObjectBase *, vtkTypeBool check)
vtkObjectBase::Register
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkObjectBase::PrintTrailer
virtual void PrintTrailer(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkObjectBase::ReportReferences
virtual void ReportReferences(vtkGarbageCollector *)
vtkObjectBase::New
static vtkObjectBase * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
Definition: vtkObjectBase.h:154
vtkObjectBase::ReferenceCount
std::atomic< int32_t > ReferenceCount
Definition: vtkObjectBase.h:259
vtkObjectBase::SetMemkindDirectory
static void SetMemkindDirectory(const char *directoryname)
The name of a directory, ideally mounted -o dax, to memory map an extended memory space within.
vtkObjectBase::GetCurrentReallocFunction
static vtkReallocingFunction GetCurrentReallocFunction()
vtkObjectBase::vtkMemkindRAII::~vtkMemkindRAII
~vtkMemkindRAII()
vtkObjectBase::UnRegisterInternal
virtual void UnRegisterInternal(vtkObjectBase *, vtkTypeBool check)
vtkObjectBase::Delete
virtual void Delete()
Delete a VTK object.
vtkObjectBase::FastDelete
virtual void FastDelete()
Delete a reference to this object.
vtkObjectBase::InitializeObjectBase
void InitializeObjectBase()
vtkObjectBase::GetCurrentMallocFunction
static vtkMallocingFunction GetCurrentMallocFunction()
vtkObjectBase::~vtkObjectBase
virtual ~vtkObjectBase()
vtkType.h
vtkObjectBase::GetClassName
const char * GetClassName() const
Return the class name as a string.
vtkObjectBase::GetReferenceCount
int GetReferenceCount()
Return the current reference count of this object.
Definition: vtkObjectBase.h:204
vtkObjectBase::vtkObjectBase
vtkObjectBase(const vtkObjectBase &)
Definition: vtkObjectBase.h:292
vtkMallocingFunction
void *(* vtkMallocingFunction)(size_t)
Definition: vtkObjectBase.h:65
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
vtkWeakPointerBase
Non-templated superclass for vtkWeakPointer.
Definition: vtkWeakPointerBase.h:34
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkObjectBase::GetNumberOfGenerationsFromBase
virtual vtkIdType GetNumberOfGenerationsFromBase(const char *name)
Given the name of a base class of this class type, return the distance of inheritance between this cl...
vtkObjectBase::SetReferenceCount
void SetReferenceCount(int)
Sets the reference count.
vtkObjectBase::GetNumberOfGenerationsFromBaseType
static vtkIdType GetNumberOfGenerationsFromBaseType(const char *name)
Given a the name of a base class of this class type, return the distance of inheritance between this ...
vtkX3D::name
@ name
Definition: vtkX3D.h:225
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:95
vtkIndent.h
vtkObjectBase::operator<<
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
vtkObjectBase::vtkMemkindRAII
A class to help modify and restore the global UsingMemkind state, like SetUsingMemkind(newValue),...
Definition: vtkObjectBase.h:234
vtkObjectBase::vtkMemkindRAII::vtkMemkindRAII
vtkMemkindRAII(bool newValue)
vtkReallocingFunction
void *(* vtkReallocingFunction)(void *, size_t)
Definition: vtkObjectBase.h:66
vtkObjectBase::GetCurrentFreeFunction
static vtkFreeingFunction GetCurrentFreeFunction()
vtkObjectBase::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkObjectBase::IsTypeOf
static vtkTypeBool IsTypeOf(const char *name)
Return 1 if this class type is the same type of (or a subclass of) the named class.
vtkObjectBase::GetUsingMemkind
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
vtkObjectBase::vtkMemkindRAII::vtkMemkindRAII
vtkMemkindRAII(vtkMemkindRAII const &)=default
vtkObjectBase::UnRegister
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkObjectBase::IsA
virtual vtkTypeBool IsA(const char *name)
Return 1 if this class is the same type of (or a subclass of) the named class.
vtkSystemIncludes.h