ROOT logo
// @(#)root/base:$Id$
// Author: Matevz Tadel   16/08/2006

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TObjectSpy
#define ROOT_TObjectSpy

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TObjectSpy, TObjectRefSpy                                            //
//                                                                      //
// Monitors objects for deletion and reflects the deletion by reverting //
// the internal pointer to zero. When this pointer is zero we know the  //
// object has been deleted. This avoids the unsafe TestBit(kNotDeleted) //
// hack. The spied object must have the kMustCleanup bit set otherwise  //
// you will get an error.                                               //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif


class TObjectSpy : public TObject {

private:
   TObjectSpy(const TObjectSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { }
   TObjectSpy& operator=(const TObjectSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; }

protected:
   TObject  *fObj;                 // object being spied
   Bool_t    fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor

public:
   TObjectSpy(TObject *obj = 0, Bool_t fixMustCleanupBit=kTRUE);
   virtual ~TObjectSpy();

   virtual void  RecursiveRemove(TObject *obj);
   TObject      *GetObject() const { return fObj; }
   void          SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE);

   ClassDef(TObjectSpy, 0);  // Spy object pointer for deletion
};


class TObjectRefSpy : public TObject {

private:
   TObjectRefSpy(const TObjectRefSpy& s); // Not implemented.  : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { }
   TObjectRefSpy& operator=(const TObjectRefSpy& s);  // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; }
   
protected:
   TObject  *&fObj;                // object being spied
   Bool_t    fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor

public:
   TObjectRefSpy(TObject *&obj, Bool_t fixMustCleanupBit=kTRUE);
   virtual ~TObjectRefSpy();

   virtual void  RecursiveRemove(TObject *obj);
   TObject      *GetObject() const { return fObj; }

   ClassDef(TObjectRefSpy, 0);  // Spy object reference for deletion
};

#endif
 TObjectSpy.h:1
 TObjectSpy.h:2
 TObjectSpy.h:3
 TObjectSpy.h:4
 TObjectSpy.h:5
 TObjectSpy.h:6
 TObjectSpy.h:7
 TObjectSpy.h:8
 TObjectSpy.h:9
 TObjectSpy.h:10
 TObjectSpy.h:11
 TObjectSpy.h:12
 TObjectSpy.h:13
 TObjectSpy.h:14
 TObjectSpy.h:15
 TObjectSpy.h:16
 TObjectSpy.h:17
 TObjectSpy.h:18
 TObjectSpy.h:19
 TObjectSpy.h:20
 TObjectSpy.h:21
 TObjectSpy.h:22
 TObjectSpy.h:23
 TObjectSpy.h:24
 TObjectSpy.h:25
 TObjectSpy.h:26
 TObjectSpy.h:27
 TObjectSpy.h:28
 TObjectSpy.h:29
 TObjectSpy.h:30
 TObjectSpy.h:31
 TObjectSpy.h:32
 TObjectSpy.h:33
 TObjectSpy.h:34
 TObjectSpy.h:35
 TObjectSpy.h:36
 TObjectSpy.h:37
 TObjectSpy.h:38
 TObjectSpy.h:39
 TObjectSpy.h:40
 TObjectSpy.h:41
 TObjectSpy.h:42
 TObjectSpy.h:43
 TObjectSpy.h:44
 TObjectSpy.h:45
 TObjectSpy.h:46
 TObjectSpy.h:47
 TObjectSpy.h:48
 TObjectSpy.h:49
 TObjectSpy.h:50
 TObjectSpy.h:51
 TObjectSpy.h:52
 TObjectSpy.h:53
 TObjectSpy.h:54
 TObjectSpy.h:55
 TObjectSpy.h:56
 TObjectSpy.h:57
 TObjectSpy.h:58
 TObjectSpy.h:59
 TObjectSpy.h:60
 TObjectSpy.h:61
 TObjectSpy.h:62
 TObjectSpy.h:63
 TObjectSpy.h:64
 TObjectSpy.h:65
 TObjectSpy.h:66
 TObjectSpy.h:67
 TObjectSpy.h:68
 TObjectSpy.h:69
 TObjectSpy.h:70
 TObjectSpy.h:71
 TObjectSpy.h:72
 TObjectSpy.h:73
 TObjectSpy.h:74