VTK  9.0.1
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 
116  static vtkIdType GetNumberOfGenerationsFromBaseType(const char* name);
117 
126  virtual vtkIdType GetNumberOfGenerationsFromBase(const char* name);
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:
157  void InitializeObjectBase();
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:
213  vtkObjectBase();
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.
226  virtual void RegisterInternal(vtkObjectBase*, vtkTypeBool check);
227  virtual void UnRegisterInternal(vtkObjectBase*, vtkTypeBool check);
228 
229  // See vtkGarbageCollector.h:
230  virtual void ReportReferences(vtkGarbageCollector*);
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
void InitializeObjectBase()
static vtkObjectBase * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void Print(const std::vector< T > &input, const std::string &name)
Print a vector with an associated name.
int vtkIdType
Definition: vtkType.h:338
vtkObjectBase(const vtkObjectBase &)
void PrintRevisions(ostream &)
Legacy.
int GetReferenceCount()
Return the current reference count of this object.
Detect and break reference loops.
int vtkTypeBool
Definition: vtkABI.h:69
a simple class to control print indentation
Definition: vtkIndent.h:33
Non-templated superclass for vtkWeakPointer.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:63
virtual void CollectRevisions(ostream &)
std::atomic< int32_t > ReferenceCount
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkIndent &o)
vtkWeakPointerBase ** WeakPointers
void operator=(const vtkObjectBase &)