Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TObjectSpy.cxx
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#include "TObjectSpy.h"
13#include "TSeqCollection.h"
14#include "TROOT.h"
15#include "TVirtualMutex.h"
16
17/** \class TObjectRefSpy
18 \class TObjectSpy
19\ingroup Base
20
21Monitors objects for deletion and reflects the deletion by reverting
22the internal pointer to zero. When this pointer is zero we know the
23object has been deleted. This avoids the unsafe TestBit(kNotDeleted)
24hack. The spied object must have the kMustCleanup bit set otherwise
25you will get an error.
26*/
27
28
29////////////////////////////////////////////////////////////////////////////////
30/// Register the object that must be spied. The object must have the
31/// kMustCleanup bit set. If the object has been deleted during a
32/// RecusiveRemove() operation, GetObject() will return 0.
33
35 TObject(), fObj(obj), fResetMustCleanupBit(kFALSE)
36{
37 {
39 gROOT->GetListOfCleanups()->Add(this);
40 }
41 if (fObj && !fObj->TestBit(kMustCleanup)) {
45 } else {
46 Error("TObjectSpy", "spied object must have the kMustCleanup bit set");
47 }
48 }
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Cleanup.
53
55{
59 gROOT->GetListOfCleanups()->Remove(this);
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Sets the object pointer to zero if the object is deleted in the
64/// RecursiveRemove() operation.
65
67{
68 if (obj == fObj) {
69 fObj = nullptr;
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Set obj as the spy target.
76
78{
82
83 fObj = obj;
84
85 if (fObj && !fObj->TestBit(kMustCleanup)) {
89 } else {
90 Error("TObjectSpy", "spied object must have the kMustCleanup bit set");
91 }
92 }
93}
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Register the object that must be spied. The object must have the
98/// kMustCleanup bit set. If the object has been deleted during a
99/// RecusiveRemove() operation, GetObject() will return 0.
100
102 fObj(obj), fResetMustCleanupBit(kFALSE)
103{
104 {
106 gROOT->GetListOfCleanups()->Add(this);
107 }
108 if (fObj && !fObj->TestBit(kMustCleanup)) {
109 if (fixMustCleanupBit) {
112 } else {
113 Error("TObjectSpy", "spied object must have the kMustCleanup bit set");
114 }
115 }
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Cleanup.
120
122{
126 gROOT->GetListOfCleanups()->Remove(this);
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Sets the object pointer to zero if the object is deleted in the
131/// RecursiveRemove() operation.
132
134{
135 if (obj == fObj) {
136 fObj = nullptr;
138 }
139}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
#define R__LOCKGUARD(mutex)
TObject *& fObj
Definition TObjectSpy.h:59
TObjectRefSpy(const TObjectRefSpy &s)=delete
void RecursiveRemove(TObject *obj) override
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
virtual ~TObjectRefSpy()
Cleanup.
Bool_t fResetMustCleanupBit
Definition TObjectSpy.h:60
Bool_t fResetMustCleanupBit
Definition TObjectSpy.h:38
void RecursiveRemove(TObject *obj) override
Sets the object pointer to zero if the object is deleted in the RecursiveRemove() operation.
TObject * fObj
Definition TObjectSpy.h:37
virtual ~TObjectSpy()
Cleanup.
TObjectSpy(const TObjectSpy &s)=delete
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:70