Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RAnyObjectHolder.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_RAnyObjectHolder
10#define ROOT7_Browsable_RAnyObjectHolder
11
13
14namespace ROOT {
15namespace Experimental {
16namespace Browsable {
17
18/** \class RAnyObjectHolder
19\ingroup rbrowser
20\brief Holder of any object instance. Normally used with TFile, where any object can be read. Normally RShread or RUnique should be used
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
26class RAnyObjectHolder : public RHolder {
27 TClass *fClass{nullptr}; ///<! object class
28 void *fObj{nullptr}; ///<! plain holder without IO
29 bool fOwner{false}; ///<! is object owner
30protected:
31 void *AccessObject() final { return fOwner ? nullptr : fObj; }
32
33 void *TakeObject() final
34 {
35 if (!fOwner)
36 return nullptr;
37 auto res = fObj;
38 fObj = nullptr;
39 fOwner = false;
40 return res;
41 }
42
43 RHolder* DoCopy() const final
44 {
45 if (fOwner || !fObj || !fClass) return nullptr;
46 return new RAnyObjectHolder(fClass, fObj, false);
47 }
48
49public:
50 RAnyObjectHolder(TClass *cl, void *obj, bool owner = false) { fClass = cl; fObj = obj; fOwner = owner; }
52 {
53 if (fOwner)
55 }
56
57 const TClass *GetClass() const final { return fClass; }
58 const void *GetObject() const final { return fObj; }
59};
60
61
62} // namespace Browsable
63} // namespace Experimental
64} // namespace ROOT
65
66
67#endif
void * TakeObject() final
Returns pointer with ownership, normally via unique_ptr<T>::release() or tobj->Clone()
void * AccessObject() final
Returns plain object pointer without care about ownership, should not be used often.
const TClass * GetClass() const final
Returns class of contained object.
RHolder * DoCopy() const final
Create copy of container, works only when pointer can be shared.
RAnyObjectHolder(TClass *cl, void *obj, bool owner=false)
const void * GetObject() const final
Returns direct (temporary) object pointer.
Basic class for object holder of any kind.
Definition RHolder.hxx:33
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5386
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...