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*/
23
24class RAnyObjectHolder : public RHolder {
25 TClass *fClass{nullptr}; ///<! object class
26 void *fObj{nullptr}; ///<! plain holder without IO
27 bool fOwner{false}; ///<! is object owner
28protected:
29 void *AccessObject() final { return fOwner ? nullptr : fObj; }
30
32 {
33 if (!fOwner)
34 return nullptr;
35 auto res = fObj;
36 fObj = nullptr;
37 fOwner = false;
38 return res;
39 }
40
42 {
43 if (fOwner || !fObj || !fClass) return nullptr;
44 return new RAnyObjectHolder(fClass, fObj, false);
45 }
46
47public:
48 RAnyObjectHolder(TClass *cl, void *obj, bool owner = false) { fClass = cl; fObj = obj; fOwner = owner; }
50 {
51 if (fOwner)
53 }
54
56 {
57 fClass = nullptr;
58 fObj = nullptr;
59 fOwner = false;
60 }
61
62 const TClass *GetClass() const final { return fClass; }
63 const void *GetObject() const final { return fObj; }
64};
65
66
67} // namespace Browsable
68} // namespace ROOT
69
70
71#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:32
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5470