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