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 Experimental {
16namespace Browsable {
17
18/** \class RShared<T>
19\ingroup rbrowser
20\brief Holder of with shared_ptr<T> instance. Should be used to transfer shared_ptr<T> in browsable methods
21\author Sergey Linev <S.Linev@gsi.de>
22\date 2019-10-19
23\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
24*/
25
26template<class T>
27class RShared : public RHolder {
28 std::shared_ptr<T> fShared; ///<! holder without IO
29protected:
30 void *GetShared() const final { return &fShared; }
31 RHolder* DoCopy() const final { return new RShared<T>(fShared); }
32public:
33 RShared(T *obj) { fShared.reset(obj); }
34 RShared(std::shared_ptr<T> obj) { fShared = obj; }
35 RShared(std::shared_ptr<T> &&obj) { fShared = std::move(obj); }
36 virtual ~RShared() = default;
37
38 const TClass *GetClass() const final { return TClass::GetClass<T>(); }
39 const void *GetObject() const final { return fShared.get(); }
40};
41
42} // namespace Browsable
43} // namespace Experimental
44} // namespace ROOT
45
46
47#endif
Basic class for object holder of any kind.
Definition RHolder.hxx:33
std::shared_ptr< T > fShared
! holder without IO
Definition RShared.hxx:28
const void * GetObject() const final
Returns direct (temporary) object pointer.
Definition RShared.hxx:39
void * GetShared() const final
Returns pointer on existing shared_ptr<T>
Definition RShared.hxx:30
RHolder * DoCopy() const final
Create copy of container, works only when pointer can be shared.
Definition RShared.hxx:31
RShared(std::shared_ptr< T > obj)
Definition RShared.hxx:34
const TClass * GetClass() const final
Returns class of contained object.
Definition RShared.hxx:38
RShared(std::shared_ptr< T > &&obj)
Definition RShared.hxx:35
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.