Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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) = delete;
34 TObjectSpy& operator=(const TObjectSpy& s) = delete;
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 = 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
52class TObjectRefSpy : public TObject {
53
54private:
55 TObjectRefSpy(const TObjectRefSpy& s) = delete;
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:63
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:325
TObject * GetObject() const
Definition TObjectSpy.h:67
TObject *& fObj
Definition TObjectSpy.h:59
TObjectRefSpy & operator=(const TObjectRefSpy &s)=delete
TObjectRefSpy(const TObjectRefSpy &s)=delete
virtual ~TObjectRefSpy()
Cleanup.
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.
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
Bool_t fResetMustCleanupBit
Definition TObjectSpy.h:38
TObject * fObj
Definition TObjectSpy.h:37
TObjectSpy & operator=(const TObjectSpy &s)=delete
virtual ~TObjectSpy()
Cleanup.
TObjectSpy(const TObjectSpy &s)=delete
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
virtual void RecursiveRemove(TObject *obj)
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
Mother of all ROOT objects.
Definition TObject.h:41