00001 // @(#)root/base:$Id: TObjectSpy.h 22539 2008-03-08 14:36:37Z rdm $ 00002 // Author: Matevz Tadel 16/08/2006 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TObjectSpy 00013 #define ROOT_TObjectSpy 00014 00015 ////////////////////////////////////////////////////////////////////////// 00016 // // 00017 // TObjectSpy, TObjectRefSpy // 00018 // // 00019 // Monitors objects for deletion and reflects the deletion by reverting // 00020 // the internal pointer to zero. When this pointer is zero we know the // 00021 // object has been deleted. This avoids the unsafe TestBit(kNotDeleted) // 00022 // hack. The spied object must have the kMustCleanup bit set otherwise // 00023 // you will get an error. // 00024 // // 00025 ////////////////////////////////////////////////////////////////////////// 00026 00027 #ifndef ROOT_TObject 00028 #include "TObject.h" 00029 #endif 00030 00031 00032 class TObjectSpy : public TObject { 00033 00034 private: 00035 TObjectSpy(const TObjectSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { } 00036 TObjectSpy& operator=(const TObjectSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; } 00037 00038 protected: 00039 TObject *fObj; // object being spied 00040 Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor 00041 00042 public: 00043 TObjectSpy(TObject *obj = 0, Bool_t fixMustCleanupBit=kTRUE); 00044 virtual ~TObjectSpy(); 00045 00046 virtual void RecursiveRemove(TObject *obj); 00047 TObject *GetObject() const { return fObj; } 00048 void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE); 00049 00050 ClassDef(TObjectSpy, 0); // Spy object pointer for deletion 00051 }; 00052 00053 00054 class TObjectRefSpy : public TObject { 00055 00056 private: 00057 TObjectRefSpy(const TObjectRefSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { } 00058 TObjectRefSpy& operator=(const TObjectRefSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; } 00059 00060 protected: 00061 TObject *&fObj; // object being spied 00062 Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor 00063 00064 public: 00065 TObjectRefSpy(TObject *&obj, Bool_t fixMustCleanupBit=kTRUE); 00066 virtual ~TObjectRefSpy(); 00067 00068 virtual void RecursiveRemove(TObject *obj); 00069 TObject *GetObject() const { return fObj; } 00070 00071 ClassDef(TObjectRefSpy, 0); // Spy object reference for deletion 00072 }; 00073 00074 #endif