Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*************************************************************************
0002  * Copyright (C) 1995-2020, 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_RAnyObjectHolder
0010 #define ROOT7_Browsable_RAnyObjectHolder
0011 
0012 #include <ROOT/Browsable/RHolder.hxx>
0013 
0014 namespace ROOT {
0015 namespace Browsable {
0016 
0017 /** \class RAnyObjectHolder
0018 \ingroup rbrowser
0019 \brief Holder of any object instance. Normally used with TFile, where any object can be read. Normally RShread or RUnique should be used
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 RAnyObjectHolder : public RHolder {
0026    TClass *fClass{nullptr};   ///<! object class
0027    void *fObj{nullptr};       ///<! plain holder without IO
0028    bool fOwner{false};        ///<! is object owner
0029 protected:
0030    void *AccessObject() final { return fOwner ? nullptr : fObj; }
0031 
0032    void *TakeObject() final
0033    {
0034       if (!fOwner)
0035          return nullptr;
0036       auto res = fObj;
0037       fObj = nullptr;
0038       fOwner = false;
0039       return res;
0040    }
0041 
0042    RHolder* DoCopy() const final
0043    {
0044       if (fOwner || !fObj || !fClass) return nullptr;
0045       return new RAnyObjectHolder(fClass, fObj, false);
0046    }
0047 
0048 public:
0049    RAnyObjectHolder(TClass *cl, void *obj, bool owner = false) { fClass = cl; fObj = obj; fOwner = owner; }
0050    virtual ~RAnyObjectHolder()
0051    {
0052       if (fOwner)
0053          fClass->Destructor(fObj);
0054    }
0055 
0056    void Forget() final
0057    {
0058       fClass = nullptr;
0059       fObj = nullptr;
0060       fOwner = false;
0061    }
0062 
0063    const TClass *GetClass() const final { return fClass; }
0064    const void *GetObject() const final { return fObj; }
0065 };
0066 
0067 
0068 } // namespace Browsable
0069 } // namespace ROOT
0070 
0071 
0072 #endif