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
60class vtkGarbageCollectorToObjectBaseFriendship;
62class vtkWeakPointerBaseToObjectBaseFriendship;
63
64// typedefs for malloc and free compatible replacement functions
65typedef void* (*vtkMallocingFunction)(size_t);
66typedef void* (*vtkReallocingFunction)(void*, size_t);
67typedef void (*vtkFreeingFunction)(void*);
68
69class VTKCOMMONCORE_EXPORT vtkObjectBase
70{
76 virtual const char* GetClassNameInternal() const { return "vtkObjectBase"; }
77
78public:
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
132 virtual vtkIdType GetNumberOfGenerationsFromBase(const char* name);
133
139 virtual void Delete();
140
148 virtual void FastDelete();
149
155 {
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
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);
243
244 private:
245 void Save(bool newValue);
246 void Restore();
247 };
248
253 bool GetIsInMemkind() const;
254
255protected:
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
280private:
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
291protected:
293 void operator=(const vtkObjectBase&) {}
294};
295#endif
296
297// VTK-HeaderTest-Exclude: vtkObjectBase.h
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:113
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:70
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.
int vtkTypeBool
Definition: vtkABI.h:69
void *(* vtkMallocingFunction)(size_t)
Definition: vtkObjectBase.h:65
void *(* vtkReallocingFunction)(void *, size_t)
Definition: vtkObjectBase.h:66
void(* vtkFreeingFunction)(void *)
Definition: vtkObjectBase.h:67
int vtkIdType
Definition: vtkType.h:332