VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkGarbageCollector.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00081 #ifndef __vtkGarbageCollector_h 00082 #define __vtkGarbageCollector_h 00083 00084 #include "vtkObject.h" 00085 #include "vtkGarbageCollectorManager.h" // Needed for singleton initialization. 00086 00087 // This function is a friend of the collector so that it can call the 00088 // internal report method. 00089 void VTK_COMMON_EXPORT 00090 vtkGarbageCollectorReportInternal(vtkGarbageCollector*, 00091 vtkObjectBase*, void*, 00092 const char*); 00093 00094 // This allows vtkObjectBase to get at the methods it needs. 00095 class vtkObjectBaseToGarbageCollectorFriendship; 00096 00097 class VTK_COMMON_EXPORT vtkGarbageCollector : public vtkObject 00098 { 00099 public: 00100 vtkTypeMacro(vtkGarbageCollector,vtkObject); 00101 void PrintSelf(ostream& os, vtkIndent indent); 00102 static vtkGarbageCollector* New(); 00103 00113 static void Collect(); 00114 00123 static void Collect(vtkObjectBase* root); 00124 00126 00130 static void DeferredCollectionPush(); 00131 static void DeferredCollectionPop(); 00133 00135 00137 static void SetGlobalDebugFlag(int flag); 00138 static int GetGlobalDebugFlag(); 00140 00141 protected: 00142 vtkGarbageCollector(); 00143 ~vtkGarbageCollector(); 00144 00145 private: 00146 00154 static int GiveReference(vtkObjectBase* obj); 00155 00161 static int TakeReference(vtkObjectBase* obj); 00162 00163 // Singleton management functions. 00164 static void ClassInitialize(); 00165 static void ClassFinalize(); 00166 00167 //BTX 00168 friend class vtkGarbageCollectorManager; 00169 friend class vtkObjectBaseToGarbageCollectorFriendship; 00170 //ETX 00171 00172 // Internal report callback and friend function that calls it. 00173 virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc); 00174 friend void VTK_COMMON_EXPORT 00175 vtkGarbageCollectorReportInternal(vtkGarbageCollector*, 00176 vtkObjectBase*, void*, 00177 const char*); 00178 00179 private: 00180 vtkGarbageCollector(const vtkGarbageCollector&); // Not implemented. 00181 void operator=(const vtkGarbageCollector&); // Not implemented. 00182 }; 00183 00184 //BTX 00185 class vtkSmartPointerBase; 00186 00188 00189 void VTK_COMMON_EXPORT 00190 vtkGarbageCollectorReport(vtkGarbageCollector* collector, 00191 vtkSmartPointerBase& ptr, 00192 const char* desc); 00194 00196 00197 template <class T> 00198 void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr, 00199 const char* desc) 00200 { 00201 vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc); 00202 } 00203 //ETX 00205 00206 #endif