Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RShared.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT7_Browsable_RShared
10#define ROOT7_Browsable_RShared
11
13
14namespace ROOT {
15namespace Browsable {
16
17/** \class RShared<T>
18\ingroup rbrowser
19\brief Holder of with shared_ptr<T> instance. Should be used to transfer shared_ptr<T> in browsable methods
20\author Sergey Linev <S.Linev@gsi.de>
21\date 2019-10-19
22\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
23*/
24
25template<class T>
26class RShared : public RHolder {
27 std::shared_ptr<T> fShared; ///<! holder without IO
28protected:
29 void *GetShared() const final { return &fShared; }
30 RHolder* DoCopy() const final { return new RShared<T>(fShared); }
31public:
32 RShared(T *obj) { fShared.reset(obj); }
33 RShared(std::shared_ptr<T> obj) { fShared = obj; }
34 RShared(std::shared_ptr<T> &&obj) { fShared = std::move(obj); }
35 virtual ~RShared() = default;
36
37 const TClass *GetClass() const final { return TClass::GetClass<T>(); }
38 const void *GetObject() const final { return fShared.get(); }
39};
40
41} // namespace Browsable
42} // namespace ROOT
43
44
45#endif
Basic class for object holder of any kind.
Definition RHolder.hxx:35
void * GetShared() const final
Returns pointer on existing shared_ptr<T>
Definition RShared.hxx:29
RShared(std::shared_ptr< T > &&obj)
Definition RShared.hxx:34
std::shared_ptr< T > fShared
! holder without IO
Definition RShared.hxx:27
RShared(std::shared_ptr< T > obj)
Definition RShared.hxx:33
const TClass * GetClass() const final
Returns class of contained object.
Definition RShared.hxx:37
virtual ~RShared()=default
const void * GetObject() const final
Returns direct (temporary) object pointer.
Definition RShared.hxx:38
RHolder * DoCopy() const final
Create copy of container, works only when pointer can be shared.
Definition RShared.hxx:30
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.