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=========================================================================*/
52#ifndef vtkObjectBase_h
53#define vtkObjectBase_h
54
55// Semantics around vtkDebugLeaks usage has changed. Now just call
56// vtkObjectBase::InitializeObjectBase() after creating an object with New().
57// The object factory methods take care of this automatically.
58#define VTK_HAS_INITIALIZE_OBJECT_BASE
59
60#include "vtkCommonCoreModule.h" // For export macro
61#include "vtkFeatures.h" // for VTK_USE_MEMKIND
62#include "vtkIndent.h"
63#include "vtkSystemIncludes.h"
64#include "vtkType.h"
65
66#include <atomic> // For std::atomic
67
69class vtkGarbageCollectorToObjectBaseFriendship;
71class vtkWeakPointerBaseToObjectBaseFriendship;
72
73// typedefs for malloc and free compatible replacement functions
74typedef void* (*vtkMallocingFunction)(size_t);
75typedef void* (*vtkReallocingFunction)(void*, size_t);
76typedef void (*vtkFreeingFunction)(void*);
77
78class VTKCOMMONCORE_EXPORT vtkObjectBase
79{
85 virtual const char* GetClassNameInternal() const { return "vtkObjectBase"; }
86
87public:
88#ifdef VTK_WORKAROUND_WINDOWS_MANGLE
89// Avoid windows name mangling.
90#define GetClassNameA GetClassName
91#define GetClassNameW GetClassName
92#endif
93
97 const char* GetClassName() const;
98
99#ifdef VTK_WORKAROUND_WINDOWS_MANGLE
100#undef GetClassNameW
101#undef GetClassNameA
102
103 // Define possible mangled names.
104 const char* GetClassNameA() const;
105 const char* GetClassNameW() const;
106
107#endif
108
114 static vtkTypeBool IsTypeOf(const char* name);
115
121 virtual vtkTypeBool IsA(const char* name);
122
132
142
148 virtual void Delete();
149
157 virtual void FastDelete();
158
164 {
167 return o;
168 }
169
170 // Called by implementations of vtkObject::New(). Centralized location for
171 // vtkDebugLeaks registration:
173
174#if defined(_WIN32) || defined(VTK_USE_MEMKIND)
175 // Take control of allocation to avoid dll boundary problems or to use memkind.
176 void* operator new(size_t tSize);
177 void operator delete(void* p);
178#endif
179
184 void Print(ostream& os);
185
187
193 virtual void PrintSelf(ostream& os, vtkIndent indent);
194 virtual void PrintHeader(ostream& os, vtkIndent indent);
195 virtual void PrintTrailer(ostream& os, vtkIndent indent);
197
201 virtual void Register(vtkObjectBase* o);
202
208 virtual void UnRegister(vtkObjectBase* o);
209
213 int GetReferenceCount() { return this->ReferenceCount; }
214
219
226 static void SetMemkindDirectory(const char* directoryname);
227
229
234 static bool GetUsingMemkind();
236
242 class VTKCOMMONCORE_EXPORT vtkMemkindRAII
243 {
244#ifdef VTK_USE_MEMKIND
245 bool OriginalValue;
246#endif
247
248 public:
249 vtkMemkindRAII(bool newValue);
252
253 private:
254 void Save(bool newValue);
255 void Restore();
256 };
257
262 bool GetIsInMemkind() const;
263
264protected:
266 virtual ~vtkObjectBase();
267
268 std::atomic<int32_t> ReferenceCount;
270
271 // Internal Register/UnRegister implementation that accounts for
272 // possible garbage collection participation. The second argument
273 // indicates whether to participate in garbage collection.
276
277 // See vtkGarbageCollector.h:
279
280 // Call this to call from either malloc or memkind_malloc depending on current UsingMemkind
282 // Call this to call from either realloc or memkind_realloc depending on current UsingMemkind
284 // Call this to call from either free or memkind_free depending on instance's IsInMemkind
286 // Call this to unconditionally call memkind_free
288
289private:
290 friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, vtkObjectBase& o);
291 friend class vtkGarbageCollectorToObjectBaseFriendship;
292 friend class vtkWeakPointerBaseToObjectBaseFriendship;
293
294 friend class vtkMemkindRAII;
295 friend class vtkTDSCMemkindRAII;
296 static void SetUsingMemkind(bool);
297 bool IsInMemkind;
298 void SetIsInMemkind(bool);
299
300protected:
302 void operator=(const vtkObjectBase&) {}
303};
304#endif
305
306// VTK-HeaderTest-Exclude: vtkObjectBase.h
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:43
A class to help modify and restore the global UsingMemkind state, like SetUsingMemkind(newValue),...
vtkMemkindRAII(vtkMemkindRAII const &)=default
abstract base class for most VTK objects
Definition: vtkObjectBase.h:79
static vtkFreeingFunction GetCurrentFreeFunction()
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
static void SetMemkindDirectory(const char *directoryname)
The name of a directory, ideally mounted -o dax, to memory map an extended memory space within.
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 ...
virtual void PrintTrailer(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void operator=(const vtkObjectBase &)
static vtkMallocingFunction GetCurrentMallocFunction()
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
static vtkReallocingFunction GetCurrentReallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
virtual void UnRegisterInternal(vtkObjectBase *, vtkTypeBool check)
virtual vtkTypeBool IsA(const char *name)
Return 1 if this class is the same type of (or a subclass of) the named class.
static vtkObjectBase * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
virtual void RegisterInternal(vtkObjectBase *, vtkTypeBool check)
virtual void PrintHeader(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void SetReferenceCount(int)
Sets the reference count.
int GetReferenceCount()
Return the current reference count of this object.
std::atomic< int32_t > ReferenceCount
void InitializeObjectBase()
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkWeakPointerBase ** WeakPointers
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
virtual void Delete()
Delete a VTK object.
virtual ~vtkObjectBase()
virtual void ReportReferences(vtkGarbageCollector *)
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...
static vtkTypeBool IsTypeOf(const char *name)
Return 1 if this class type is the same type of (or a subclass of) the named class.
virtual void FastDelete()
Delete a reference to this object.
void Print(ostream &os)
Print an object to an ostream.
bool GetIsInMemkind() const
A local state flag that remembers whether this object lives in the normal or extended memory space.
const char * GetClassName() const
Return the class name as a string.
vtkObjectBase(const vtkObjectBase &)
Non-templated superclass for vtkWeakPointer.
@ name
Definition: vtkX3D.h:225
int vtkTypeBool
Definition: vtkABI.h:69
void *(* vtkMallocingFunction)(size_t)
Definition: vtkObjectBase.h:74
void *(* vtkReallocingFunction)(void *, size_t)
Definition: vtkObjectBase.h:75
void(* vtkFreeingFunction)(void *)
Definition: vtkObjectBase.h:76
int vtkIdType
Definition: vtkType.h:332