Logo ROOT   6.12/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 #include "TObject.h"
28 
29 
30 class TObjectSpy : public TObject {
31 
32 private:
33  TObjectSpy(const TObjectSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { }
34  TObjectSpy& operator=(const TObjectSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; }
35 
36 protected:
37  TObject *fObj; // object being spied
38  Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
39 
40 public:
41  TObjectSpy(TObject *obj = 0, Bool_t fixMustCleanupBit=kTRUE);
42  virtual ~TObjectSpy();
43 
44  virtual void RecursiveRemove(TObject *obj);
45  TObject *GetObject() const { return fObj; }
46  void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE);
47 
48  ClassDef(TObjectSpy, 0); // Spy object pointer for deletion
49 };
50 
51 
52 class TObjectRefSpy : public TObject {
53 
54 private:
55  TObjectRefSpy(const TObjectRefSpy& s); // Not implemented. : TObject(), fObj(s.fObj), fFixMustCleanupBit(s.fFixMustCleanupBit) { }
56  TObjectRefSpy& operator=(const TObjectRefSpy& s); // Not implemented. { fObj = s.fObj; fFixMustCleanupBit = s.fFixMustCleanupBit; return *this; }
57 
58 protected:
59  TObject *&fObj; // object being spied
60  Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
61 
62 public:
63  TObjectRefSpy(TObject *&obj, Bool_t fixMustCleanupBit=kTRUE);
64  virtual ~TObjectRefSpy();
65 
66  virtual void RecursiveRemove(TObject *obj);
67  TObject *GetObject() const { return fObj; }
68 
69  ClassDef(TObjectRefSpy, 0); // Spy object reference for deletion
70 };
71 
72 #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:67
TObjectSpy & operator=(const TObjectSpy &s)
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:320
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
Definition: TObjectSpy.cxx:78
TObject *& fObj
Definition: TObjectSpy.h:59
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:38
TObject * GetObject() const
Definition: TObjectSpy.h:67
static constexpr double s
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:60
TObject * fObj
Definition: TObjectSpy.h:37
virtual ~TObjectSpy()
Cleanup.
Definition: TObjectSpy.cxx:55
Monitors objects for deletion and reflects the deletion by reverting the internal pointer to zero...
Definition: TObjectSpy.h:30
const Bool_t kTRUE
Definition: RtypesCore.h:87
TObject * GetObject() const
Definition: TObjectSpy.h:45