Logo ROOT   6.08/07
Reference Guide
TObjectSpy.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Matevz Tadel 16/08/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TObjectSpy
13 #define ROOT_TObjectSpy
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TObjectSpy, TObjectRefSpy //
18 // //
19 // Monitors objects for deletion and reflects the deletion by reverting //
20 // the internal pointer to zero. When this pointer is zero we know the //
21 // object has been deleted. This avoids the unsafe TestBit(kNotDeleted) //
22 // hack. The spied object must have the kMustCleanup bit set otherwise //
23 // you will get an error. //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 #ifndef ROOT_TObject
28 #include "TObject.h"
29 #endif
30 
31 
32 class TObjectSpy : public TObject {
33 
34 private:
35  TObjectSpy(const TObjectSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { }
36  TObjectSpy& operator=(const TObjectSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; }
37 
38 protected:
39  TObject *fObj; // object being spied
40  Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
41 
42 public:
43  TObjectSpy(TObject *obj = 0, Bool_t fixMustCleanupBit=kTRUE);
44  virtual ~TObjectSpy();
45 
46  virtual void RecursiveRemove(TObject *obj);
47  TObject *GetObject() const { return fObj; }
48  void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE);
49 
50  ClassDef(TObjectSpy, 0); // Spy object pointer for deletion
51 };
52 
53 
54 class TObjectRefSpy : public TObject {
55 
56 private:
57  TObjectRefSpy(const TObjectRefSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { }
58  TObjectRefSpy& operator=(const TObjectRefSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; }
59 
60 protected:
61  TObject *&fObj; // object being spied
62  Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
63 
64 public:
65  TObjectRefSpy(TObject *&obj, Bool_t fixMustCleanupBit=kTRUE);
66  virtual ~TObjectRefSpy();
67 
68  virtual void RecursiveRemove(TObject *obj);
69  TObject *GetObject() const { return fObj; }
70 
71  ClassDef(TObjectRefSpy, 0); // Spy object reference for deletion
72 };
73 
74 #endif
TObjectSpy(const TObjectSpy &s)
virtual void RecursiveRemove(TObject *obj)
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation...
Definition: TObjectSpy.cxx:63
TObjectSpy & operator=(const TObjectSpy &s)
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:254
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
Definition: TObjectSpy.cxx:74
TObject *& fObj
Definition: TObjectSpy.h:61
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:40
TObject * GetObject() const
Definition: TObjectSpy.h:69
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:62
TObject * fObj
Definition: TObjectSpy.h:39
virtual ~TObjectSpy()
Cleanup.
Definition: TObjectSpy.cxx:52
const Bool_t kTRUE
Definition: Rtypes.h:91
Monitors objects for deletion and reflects the deletion by reverting the internal pointer to zero...
Definition: TObjectSpy.h:32
TObject * GetObject() const
Definition: TObjectSpy.h:47