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 =========================================================================*/
82 #ifndef vtkGarbageCollector_h
83 #define vtkGarbageCollector_h
84 
85 #include "vtkCommonCoreModule.h" // For export macro
86 #include "vtkObject.h"
87 #include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
88 
89 // This function is a friend of the collector so that it can call the
90 // internal report method.
91 void VTKCOMMONCORE_EXPORT
93  vtkObjectBase*, void*,
94  const char*);
95 
96 // This allows vtkObjectBase to get at the methods it needs.
97 class vtkObjectBaseToGarbageCollectorFriendship;
98 
99 class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
100 {
101 public:
103  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
104  static vtkGarbageCollector* New();
105 
118  static void Collect();
119 
131  static void Collect(vtkObjectBase* root);
132 
134 
140  static void DeferredCollectionPush();
141  static void DeferredCollectionPop();
143 
145 
149  static void SetGlobalDebugFlag(bool flag);
150  static bool GetGlobalDebugFlag();
152 
153 protected:
155  ~vtkGarbageCollector() VTK_OVERRIDE;
156 
157 private:
158 
169  static int GiveReference(vtkObjectBase* obj);
170 
179  static int TakeReference(vtkObjectBase* obj);
180 
181  // Singleton management functions.
182  static void ClassInitialize();
183  static void ClassFinalize();
184 
186  friend class vtkObjectBaseToGarbageCollectorFriendship;
187 
188  // Internal report callback and friend function that calls it.
189  virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
190  friend void VTKCOMMONCORE_EXPORT
192  vtkObjectBase*, void*,
193  const char*);
194 
195 private:
196  vtkGarbageCollector(const vtkGarbageCollector&) VTK_DELETE_FUNCTION;
197  void operator=(const vtkGarbageCollector&) VTK_DELETE_FUNCTION;
198 };
199 
200 class vtkSmartPointerBase;
201 
205 void VTKCOMMONCORE_EXPORT
206 vtkGarbageCollectorReport(vtkGarbageCollector* collector,
207  vtkSmartPointerBase& ptr,
208  const char* desc);
209 
213 template <class T>
214 void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr,
215  const char* desc)
216 {
217  vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
218 }
219 
220 #endif
221 // VTK-HeaderTest-Exclude: vtkGarbageCollector.h
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:39
Manages the vtkGarbageCollector singleton.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
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.