VTK
dox/Common/Core/vtkGarbageCollector.h
Go to the documentation of this file.
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 "vtkCommonCoreModule.h" // For export macro
00085 #include "vtkObject.h"
00086 #include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
00087 
00088 // This function is a friend of the collector so that it can call the
00089 // internal report method.
00090 void VTKCOMMONCORE_EXPORT
00091 vtkGarbageCollectorReportInternal(vtkGarbageCollector*,
00092                                   vtkObjectBase*, void*,
00093                                   const char*);
00094 
00095 // This allows vtkObjectBase to get at the methods it needs.
00096 class vtkObjectBaseToGarbageCollectorFriendship;
00097 
00098 class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
00099 {
00100 public:
00101   vtkTypeMacro(vtkGarbageCollector,vtkObject);
00102   void PrintSelf(ostream& os, vtkIndent indent);
00103   static vtkGarbageCollector* New();
00104 
00114   static void Collect();
00115 
00124   static void Collect(vtkObjectBase* root);
00125 
00127 
00131   static void DeferredCollectionPush();
00132   static void DeferredCollectionPop();
00134 
00136 
00138   static void SetGlobalDebugFlag(int flag);
00139   static int GetGlobalDebugFlag();
00141 
00142 protected:
00143   vtkGarbageCollector();
00144   ~vtkGarbageCollector();
00145 
00146 private:
00147 
00155   static int GiveReference(vtkObjectBase* obj);
00156 
00162   static int TakeReference(vtkObjectBase* obj);
00163 
00164   // Singleton management functions.
00165   static void ClassInitialize();
00166   static void ClassFinalize();
00167 
00168   //BTX
00169   friend class vtkGarbageCollectorManager;
00170   friend class vtkObjectBaseToGarbageCollectorFriendship;
00171   //ETX
00172 
00173   // Internal report callback and friend function that calls it.
00174   virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
00175   friend void VTKCOMMONCORE_EXPORT
00176   vtkGarbageCollectorReportInternal(vtkGarbageCollector*,
00177                                     vtkObjectBase*, void*,
00178                                     const char*);
00179 
00180 private:
00181   vtkGarbageCollector(const vtkGarbageCollector&);  // Not implemented.
00182   void operator=(const vtkGarbageCollector&);  // Not implemented.
00183 };
00184 
00185 //BTX
00186 class vtkSmartPointerBase;
00187 
00189 
00190 void VTKCOMMONCORE_EXPORT
00191 vtkGarbageCollectorReport(vtkGarbageCollector* collector,
00192                           vtkSmartPointerBase& ptr,
00193                           const char* desc);
00195 
00197 
00198 template <class T>
00199 void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr,
00200                                const char* desc)
00201 {
00202   vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
00203 }
00204 //ETX
00206 
00207 #endif
00208 // VTK-HeaderTest-Exclude: vtkGarbageCollector.h