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 =========================================================================*/
81 #ifndef vtkGarbageCollector_h
82 #define vtkGarbageCollector_h
83 
84 #include "vtkCommonCoreModule.h" // For export macro
85 #include "vtkObject.h"
86 #include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
87 
88 // This function is a friend of the collector so that it can call the
89 // internal report method.
92  vtkObjectBase*, void*,
93  const char*);
94 
95 // This allows vtkObjectBase to get at the methods it needs.
96 class vtkObjectBaseToGarbageCollectorFriendship;
97 
99 {
100 public:
102  void PrintSelf(ostream& os, vtkIndent indent);
103  static vtkGarbageCollector* New();
104 
114  static void Collect();
115 
124  static void Collect(vtkObjectBase* root);
125 
127 
131  static void DeferredCollectionPush();
132  static void DeferredCollectionPop();
134 
136 
138  static void SetGlobalDebugFlag(bool flag);
139  static bool GetGlobalDebugFlag();
141 
142 protected:
145 
146 private:
147 
155  static int GiveReference(vtkObjectBase* obj);
156 
162  static int TakeReference(vtkObjectBase* obj);
163 
164  // Singleton management functions.
165  static void ClassInitialize();
166  static void ClassFinalize();
167 
168  //BTX
170  friend class vtkObjectBaseToGarbageCollectorFriendship;
171  //ETX
172 
173  // Internal report callback and friend function that calls it.
174  virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
175  friend void VTKCOMMONCORE_EXPORT
177  vtkObjectBase*, void*,
178  const char*);
179 
180 private:
181  vtkGarbageCollector(const vtkGarbageCollector&); // Not implemented.
182  void operator=(const vtkGarbageCollector&); // Not implemented.
183 };
184 
185 //BTX
186 class vtkSmartPointerBase;
187 
189 
192  vtkSmartPointerBase& ptr,
193  const char* desc);
195 
197 
198 template <class T>
200  const char* desc)
201 {
202  vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
203 }
204 //ETX
206 
207 #endif
208 // VTK-HeaderTest-Exclude: vtkGarbageCollector.h
abstract base class for most VTK objects
Definition: vtkObject.h:61
#define VTKCOMMONCORE_EXPORT
Detect and break reference loops.
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
Manages the vtkGarbageCollector singleton.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
Non-templated superclass for vtkSmartPointer.
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
static vtkObject * New()
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(vtkGarbageCollector *collector, vtkSmartPointerBase &ptr, const char *desc)