VTK
dox/Common/vtkDebugLeaks.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkDebugLeaks.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 =========================================================================*/
00031 #ifndef __vtkDebugLeaks_h
00032 #define __vtkDebugLeaks_h
00033 
00034 #include "vtkObject.h"
00035 
00036 #include "vtkToolkits.h" // Needed for VTK_DEBUG_LEAKS macro setting.
00037 #include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
00038 
00039 class vtkDebugLeaksHashTable;
00040 class vtkSimpleCriticalSection;
00041 class vtkDebugLeaksObserver;
00042 
00043 class VTK_COMMON_EXPORT vtkDebugLeaks : public vtkObject
00044 {
00045 public: 
00046   static vtkDebugLeaks *New();
00047   vtkTypeMacro(vtkDebugLeaks,vtkObject);
00048 
00050   static void ConstructClass(const char* classname);
00051 
00053   static void DestructClass(const char* classname);
00054 
00057   static int PrintCurrentLeaks();
00058 
00060 
00062   VTK_LEGACY(static void PromptUserOn());
00063   VTK_LEGACY(static void PromptUserOff());
00065 
00067 
00069   static int GetExitError();
00070   static void SetExitError(int);
00071   //BTX
00072   static void SetDebugLeaksObserver(vtkDebugLeaksObserver* observer);
00073   static vtkDebugLeaksObserver* GetDebugLeaksObserver();
00074   //ETX
00076 
00077 protected:
00078   vtkDebugLeaks(){}; 
00079   virtual ~vtkDebugLeaks(){}; 
00080 
00081   static int DisplayMessageBox(const char*);
00082 
00083   static void ClassInitialize();
00084   static void ClassFinalize();
00085 
00086   static void ConstructingObject(vtkObjectBase* object);
00087   static void DestructingObject(vtkObjectBase* object);
00088 
00089   //BTX
00090   friend class vtkDebugLeaksManager;
00091   friend class vtkObjectBase;
00092   //ETX
00093 
00094 private:
00095   static vtkDebugLeaksHashTable* MemoryTable;
00096   static vtkSimpleCriticalSection* CriticalSection;
00097   static vtkDebugLeaksObserver* Observer;
00098   static int ExitError;
00099 
00100   vtkDebugLeaks(const vtkDebugLeaks&);  // Not implemented.
00101   void operator=(const vtkDebugLeaks&);  // Not implemented.
00102 };
00103 
00104 //BTX
00105 // This class defines callbacks for debugging tools. The callbacks are not for general use.
00106 // The objects passed as arguments to the callbacks are in partially constructed or destructed
00107 // state and accessing them may cause undefined behavior.
00108 class VTK_COMMON_EXPORT vtkDebugLeaksObserver {
00109 public:
00110   virtual ~vtkDebugLeaksObserver() {};
00111   virtual void ConstructingObject(vtkObjectBase*) = 0;
00112   virtual void DestructingObject(vtkObjectBase*) = 0;
00113 };
00114 //ETX
00115 
00116 #endif // __vtkDebugLeaks_h