Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*************************************************************************
0002  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0003  * All rights reserved.                                                  *
0004  *                                                                       *
0005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0007  *************************************************************************/
0008 
0009 #ifndef ROOT7_Browsable_TObjectHolder
0010 #define ROOT7_Browsable_TObjectHolder
0011 
0012 #include <ROOT/Browsable/RHolder.hxx>
0013 
0014 namespace ROOT {
0015 namespace Browsable {
0016 
0017 /** \class TObjectHolder
0018 \ingroup rbrowser
0019 \brief Holder of TObject instance. Should not be used very often, while ownership is undefined for it
0020 \author Sergey Linev <S.Linev@gsi.de>
0021 \date 2019-10-19
0022 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0023 */
0024 
0025 class TObjectHolder : public RHolder {
0026    TObject *fObj{nullptr};   ///<! plain holder without IO
0027    void *fAdjusted{nullptr}; ///<! pointer on real class returned by fObj->IsA()
0028    bool fOwner{false};       ///<! is TObject owner
0029 protected:
0030    void *AccessObject() final { return fOwner ? nullptr : fObj; }
0031    void *TakeObject() final;
0032    RHolder *DoCopy() const final { return new TObjectHolder(fObj); }
0033    void ClearROOTOwnership(TObject *obj);
0034 public:
0035    TObjectHolder(TObject *obj, bool owner = false)
0036    {
0037       fAdjusted = fObj = obj;
0038       fOwner = owner;
0039       if (fOwner && fObj)
0040          ClearROOTOwnership(fObj);
0041       if (fAdjusted) {
0042          auto offset = fObj->IsA()->GetBaseClassOffset(TObject::Class());
0043          if (offset > 0)
0044             fAdjusted = (char *) fAdjusted - offset;
0045       }
0046    }
0047 
0048    virtual ~TObjectHolder()
0049    {
0050       if (fOwner) delete fObj;
0051    }
0052 
0053    void Forget() final
0054    {
0055       fAdjusted = fObj = nullptr;
0056       fOwner = false;
0057    }
0058 
0059    const TClass *GetClass() const final { return fObj ? fObj->IsA() : nullptr; }
0060    const void *GetObject() const final { return fAdjusted; }
0061 };
0062 
0063 
0064 } // namespace Browsable
0065 } // namespace ROOT
0066 
0067 
0068 #endif