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 "vtkObject.h"
85 #include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
86 
87 // This function is a friend of the collector so that it can call the
88 // internal report method.
91  vtkObjectBase*, void*,
92  const char*);
93 
94 // This allows vtkObjectBase to get at the methods it needs.
95 class vtkObjectBaseToGarbageCollectorFriendship;
96 
98 {
99 public:
101  void PrintSelf(ostream& os, vtkIndent indent);
102  static vtkGarbageCollector* New();
103 
113  static void Collect();
114 
123  static void Collect(vtkObjectBase* root);
124 
126 
130  static void DeferredCollectionPush();
131  static void DeferredCollectionPop();
133 
135 
137  static void SetGlobalDebugFlag(int flag);
138  static int GetGlobalDebugFlag();
140 
141 protected:
144 
145 private:
146 
154  static int GiveReference(vtkObjectBase* obj);
155 
161  static int TakeReference(vtkObjectBase* obj);
162 
163  // Singleton management functions.
164  static void ClassInitialize();
165  static void ClassFinalize();
166 
167  //BTX
169  friend class vtkObjectBaseToGarbageCollectorFriendship;
170  //ETX
171 
172  // Internal report callback and friend function that calls it.
173  virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
174  friend void VTK_COMMON_EXPORT
176  vtkObjectBase*, void*,
177  const char*);
178 
179 private:
180  vtkGarbageCollector(const vtkGarbageCollector&); // Not implemented.
181  void operator=(const vtkGarbageCollector&); // Not implemented.
182 };
183 
184 //BTX
185 class vtkSmartPointerBase;
186 
188 
191  vtkSmartPointerBase& ptr,
192  const char* desc);
194 
196 
197 template <class T>
199  const char* desc)
200 {
201  vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
202 }
203 //ETX
205 
206 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:60
void VTK_COMMON_EXPORT vtkGarbageCollectorReport(vtkGarbageCollector *collector, vtkSmartPointerBase &ptr, const char *desc)
Detect and break reference loops.
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
Manages the vtkGarbageCollector singleton.
#define VTK_COMMON_EXPORT
void VTK_COMMON_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
Non-templated superclass for vtkSmartPointer.
static vtkObject * New()