VTK
vtkGarbageCollector.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGarbageCollector.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 =========================================================================*/
79 #ifndef vtkGarbageCollector_h
80 #define vtkGarbageCollector_h
81 
82 #include "vtkCommonCoreModule.h" // For export macro
83 #include "vtkObject.h"
84 #include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
85 
86 // This function is a friend of the collector so that it can call the
87 // internal report method.
88 void VTKCOMMONCORE_EXPORT
90  vtkObjectBase*, void*,
91  const char*);
92 
93 // This allows vtkObjectBase to get at the methods it needs.
94 class vtkObjectBaseToGarbageCollectorFriendship;
95 
96 class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
97 {
98 public:
100  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
101  static vtkGarbageCollector* New();
102 
115  static void Collect();
116 
128  static void Collect(vtkObjectBase* root);
129 
131 
137  static void DeferredCollectionPush();
138  static void DeferredCollectionPop();
140 
142 
146  static void SetGlobalDebugFlag(bool flag);
147  static bool GetGlobalDebugFlag();
149 
150 protected:
152  ~vtkGarbageCollector() VTK_OVERRIDE;
153 
154 private:
155 
166  static int GiveReference(vtkObjectBase* obj);
167 
176  static int TakeReference(vtkObjectBase* obj);
177 
178  // Singleton management functions.
179  static void ClassInitialize();
180  static void ClassFinalize();
181 
183  friend class vtkObjectBaseToGarbageCollectorFriendship;
184 
185  // Internal report callback and friend function that calls it.
186  virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
187  friend void VTKCOMMONCORE_EXPORT
189  vtkObjectBase*, void*,
190  const char*);
191 
192 private:
193  vtkGarbageCollector(const vtkGarbageCollector&) VTK_DELETE_FUNCTION;
194  void operator=(const vtkGarbageCollector&) VTK_DELETE_FUNCTION;
195 };
196 
197 class vtkSmartPointerBase;
198 
202 void VTKCOMMONCORE_EXPORT
203 vtkGarbageCollectorReport(vtkGarbageCollector* collector,
204  vtkSmartPointerBase& ptr,
205  const char* desc);
206 
210 template <class T>
211 void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr,
212  const char* desc)
213 {
214  vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
215 }
216 
217 #endif
218 // VTK-HeaderTest-Exclude: vtkGarbageCollector.h
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:33
Manages the vtkGarbageCollector singleton.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:62
Non-templated superclass for vtkSmartPointer.
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(vtkGarbageCollector *collector, vtkSmartPointerBase &ptr, const char *desc)
Function to report a reference held by a smart pointer to a collector.