Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:18

0001 // @(#)root/base:$Id$
0002 // Author: Matevz Tadel   16/08/2006
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TObjectSpy
0013 #define ROOT_TObjectSpy
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TObjectSpy, TObjectRefSpy                                            //
0018 //                                                                      //
0019 // Monitors objects for deletion and reflects the deletion by reverting //
0020 // the internal pointer to zero. When this pointer is zero we know the  //
0021 // object has been deleted. This avoids the unsafe TestBit(kNotDeleted) //
0022 // hack. The spied object must have the kMustCleanup bit set otherwise  //
0023 // you will get an error.                                               //
0024 //                                                                      //
0025 //////////////////////////////////////////////////////////////////////////
0026 
0027 #include "TObject.h"
0028 
0029 
0030 class TObjectSpy : public TObject {
0031 
0032 private:
0033    TObjectSpy(const TObjectSpy& s) = delete;
0034    TObjectSpy& operator=(const TObjectSpy& s) = delete;
0035 
0036 protected:
0037    TObject  *fObj;                 // object being spied
0038    Bool_t    fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
0039 
0040 public:
0041    TObjectSpy(TObject *obj = nullptr, Bool_t fixMustCleanupBit=kTRUE);
0042    virtual ~TObjectSpy();
0043 
0044    void          RecursiveRemove(TObject *obj) override;
0045    TObject      *GetObject() const { return fObj; }
0046    void          SetObject(TObject *obj, Bool_t fixMustCleanupBit = kTRUE);
0047 
0048    ClassDefOverride(TObjectSpy, 0);  // Spy object pointer for deletion
0049 };
0050 
0051 
0052 class TObjectRefSpy : public TObject {
0053 
0054 private:
0055    TObjectRefSpy(const TObjectRefSpy& s) = delete;
0056    TObjectRefSpy& operator=(const TObjectRefSpy& s) = delete;
0057 
0058 protected:
0059    TObject  *&fObj;                // object being spied
0060    Bool_t    fResetMustCleanupBit; // flag saying that kMustCleanup needs to be reset in dtor
0061 
0062 public:
0063    TObjectRefSpy(TObject *&obj, Bool_t fixMustCleanupBit=kTRUE);
0064    virtual ~TObjectRefSpy();
0065 
0066    void          RecursiveRemove(TObject *obj) override;
0067    TObject      *GetObject() const { return fObj; }
0068 
0069    ClassDefOverride(TObjectRefSpy, 0);  // Spy object reference for deletion
0070 };
0071 
0072 #endif