Logo ROOT   6.18/05
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
30class TObjectSpy : public TObject {
31
32private:
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
36protected:
37 TObject *fObj; // object being spied
38 Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
39
40public:
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
52class TObjectRefSpy : public TObject {
53
54private:
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
58protected:
59 TObject *&fObj; // object being spied
60 Bool_t fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
61
62public:
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
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
TObject * GetObject() const
Definition: TObjectSpy.h:67
TObjectRefSpy(const TObjectRefSpy &s)
TObject *& fObj
Definition: TObjectSpy.h:59
TObjectRefSpy & operator=(const TObjectRefSpy &s)
virtual ~TObjectRefSpy()
Cleanup.
Definition: TObjectSpy.cxx:122
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:60
virtual void RecursiveRemove(TObject *obj)
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
Definition: TObjectSpy.cxx:134
Monitors objects for deletion and reflects the deletion by reverting the internal pointer to zero.
Definition: TObjectSpy.h:30
TObject * GetObject() const
Definition: TObjectSpy.h:45
TObjectSpy & operator=(const TObjectSpy &s)
Bool_t fResetMustCleanupBit
Definition: TObjectSpy.h:38
TObjectSpy(const TObjectSpy &s)
TObject * fObj
Definition: TObjectSpy.h:37
virtual ~TObjectSpy()
Cleanup.
Definition: TObjectSpy.cxx:55
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
Definition: TObjectSpy.cxx:78
virtual void RecursiveRemove(TObject *obj)
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
Definition: TObjectSpy.cxx:67
Mother of all ROOT objects.
Definition: TObject.h:37
static constexpr double s