Logo ROOT  
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) = delete;
34  TObjectSpy& operator=(const TObjectSpy& s) = delete;
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 = nullptr, 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) = delete;
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::TObjectSpy
TObjectSpy(const TObjectSpy &s)=delete
TObjectSpy::~TObjectSpy
virtual ~TObjectSpy()
Cleanup.
Definition: TObjectSpy.cxx:56
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TObjectSpy::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
Definition: TObjectSpy.cxx:68
TObjectRefSpy::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
Definition: TObjectSpy.cxx:135
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TObjectSpy::operator=
TObjectSpy & operator=(const TObjectSpy &s)=delete
TObjectSpy::SetObject
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
Definition: TObjectSpy.cxx:79
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
bool
TObjectSpy
Monitors objects for deletion and reflects the deletion by reverting the internal pointer to zero.
Definition: TObjectSpy.h:30
TObjectRefSpy::fObj
TObject *& fObj
Definition: TObjectSpy.h:59
TObjectRefSpy::~TObjectRefSpy
virtual ~TObjectRefSpy()
Cleanup.
Definition: TObjectSpy.cxx:123
TObjectRefSpy::operator=
TObjectRefSpy & operator=(const TObjectRefSpy &s)=delete
TObjectSpy::fObj
TObject * fObj
Definition: TObjectSpy.h:37
TObjectRefSpy::GetObject
TObject * GetObject() const
Definition: TObjectSpy.h:67
TObject.h
TObjectRefSpy::fResetMustCleanupBit
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:60
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TObjectSpy::fResetMustCleanupBit
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:38
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TObjectRefSpy::TObjectRefSpy
TObjectRefSpy(const TObjectRefSpy &s)=delete
TObjectRefSpy
Definition: TObjectSpy.h:52
TObjectSpy::GetObject
TObject * GetObject() const
Definition: TObjectSpy.h:45