VTK  9.0.3
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 "vtkIndent.h"
53 #include "vtkSystemIncludes.h"
54 #include "vtkType.h"
55 
56 #include <atomic> // For std::atomic
57 
59 class vtkGarbageCollectorToObjectBaseFriendship;
60 class vtkWeakPointerBase;
61 class vtkWeakPointerBaseToObjectBaseFriendship;
62 
63 class VTKCOMMONCORE_EXPORT vtkObjectBase
64 {
70  virtual const char* GetClassNameInternal() const { return "vtkObjectBase"; }
71 
72 public:
73 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
74 // Avoid windows name mangling.
75 #define GetClassNameA GetClassName
76 #define GetClassNameW GetClassName
77 #endif
78 
82  const char* GetClassName() const;
83 
84 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
85 #undef GetClassNameW
86 #undef GetClassNameA
87 
88  // Define possible mangled names.
89  const char* GetClassNameA() const;
90  const char* GetClassNameW() const;
91 
92 #endif
93 
99  static vtkTypeBool IsTypeOf(const char* name);
100 
106  virtual vtkTypeBool IsA(const char* name);
107 
117 
127 
133  virtual void Delete();
134 
142  virtual void FastDelete();
143 
148  static vtkObjectBase* New()
149  {
150  vtkObjectBase* o = new vtkObjectBase;
152  return o;
153  }
154 
155  // Called by implementations of vtkObject::New(). Centralized location for
156  // vtkDebugLeaks registration:
158 
159 #ifdef _WIN32
160  // avoid dll boundary problems
161  void* operator new(size_t tSize);
162  void operator delete(void* p);
163 #endif
164 
169  void Print(ostream& os);
170 
172 
178  virtual void PrintSelf(ostream& os, vtkIndent indent);
179  virtual void PrintHeader(ostream& os, vtkIndent indent);
180  virtual void PrintTrailer(ostream& os, vtkIndent indent);
182 
186  virtual void Register(vtkObjectBase* o);
187 
193  virtual void UnRegister(vtkObjectBase* o);
194 
198  int GetReferenceCount() { return this->ReferenceCount; }
199 
203  void SetReferenceCount(int);
204 
208 #ifndef VTK_LEGACY_REMOVE
209  void PrintRevisions(ostream&) {}
210 #endif
211 
212 protected:
214  virtual ~vtkObjectBase();
215 
216 #ifndef VTK_LEGACY_REMOVE
217  virtual void CollectRevisions(ostream&) {} // Legacy; do not use!
218 #endif
219 
220  std::atomic<int32_t> ReferenceCount;
222 
223  // Internal Register/UnRegister implementation that accounts for
224  // possible garbage collection participation. The second argument
225  // indicates whether to participate in garbage collection.
228 
229  // See vtkGarbageCollector.h:
231 
232 private:
233  friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, vtkObjectBase& o);
234  friend class vtkGarbageCollectorToObjectBaseFriendship;
235  friend class vtkWeakPointerBaseToObjectBaseFriendship;
236 
237 protected:
239  void operator=(const vtkObjectBase&) {}
240 };
241 
242 #endif
243 
244 // VTK-HeaderTest-Exclude: vtkObjectBase.h
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObjectBase.h:64
const char * GetClassName() const
Return the class name as a string.
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
static vtkObjectBase * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
void PrintRevisions(ostream &)
Legacy.
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)
void operator=(const vtkObjectBase &)
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
virtual void CollectRevisions(ostream &)
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.
virtual void RegisterInternal(vtkObjectBase *, vtkTypeBool check)
virtual void PrintHeader(ostream &os, vtkIndent indent)
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
virtual void Delete()
Delete a VTK object.
virtual ~vtkObjectBase()
virtual void ReportReferences(vtkGarbageCollector *)
virtual vtkIdType GetNumberOfGenerationsFromBase(const char *name)
Given a the name of a base class of this class type, return the distance of inheritance between this ...
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.
vtkObjectBase(const vtkObjectBase &)
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
Non-templated superclass for vtkWeakPointer.
@ name
Definition: vtkX3D.h:225
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:338