Back to home page

EIC code displayed by LXR

 
 

    


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

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_RShared
0010 #define ROOT7_Browsable_RShared
0011 
0012 #include <ROOT/Browsable/RHolder.hxx>
0013 
0014 namespace ROOT {
0015 namespace Browsable {
0016 
0017 /** \class RShared<T>
0018 \ingroup rbrowser
0019 \brief Holder of with shared_ptr<T> instance. Should be used to transfer shared_ptr<T> in browsable methods
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 template<class T>
0026 class RShared : public RHolder {
0027    std::shared_ptr<T> fShared;   ///<! holder without IO
0028 protected:
0029    void *GetShared() const final { return &fShared; }
0030    RHolder* DoCopy() const final { return new RShared<T>(fShared); }
0031 public:
0032    RShared(T *obj) { fShared.reset(obj); }
0033    RShared(std::shared_ptr<T> obj) { fShared = obj; }
0034    RShared(std::shared_ptr<T> &&obj) { fShared = std::move(obj); }
0035    virtual ~RShared() = default;
0036 
0037    const TClass *GetClass() const final { return TClass::GetClass<T>(); }
0038    const void *GetObject() const final { return fShared.get(); }
0039 };
0040 
0041 } // namespace Browsable
0042 } // namespace ROOT
0043 
0044 
0045 #endif