Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TObjectHolder.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2019, 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_TObjectHolder
10#define ROOT7_Browsable_TObjectHolder
11
13
14namespace ROOT {
15namespace Browsable {
16
17/** \class TObjectHolder
18\ingroup rbrowser
19\brief Holder of TObject instance. Should not be used very often, while ownership is undefined for it
20\author Sergey Linev <S.Linev@gsi.de>
21\date 2019-10-19
22*/
23
24class TObjectHolder : public RHolder {
25 TObject *fObj{nullptr}; ///<! plain holder without IO
26 void *fAdjusted{nullptr}; ///<! pointer on real class returned by fObj->IsA()
27 bool fOwner{false}; ///<! is TObject owner
28protected:
29 void *AccessObject() final { return fOwner ? nullptr : fObj; }
30 void *TakeObject() final;
32 void ClearROOTOwnership(TObject *obj);
33public:
34 TObjectHolder(TObject *obj, bool owner = false)
35 {
36 fAdjusted = fObj = obj;
37 fOwner = owner;
38 if (fOwner && fObj)
40 if (fAdjusted) {
41 auto offset = fObj->IsA()->GetBaseClassOffset(TObject::Class());
42 if (offset > 0)
43 fAdjusted = (char *) fAdjusted - offset;
44 }
45 }
46
48 {
49 if (fOwner) delete fObj;
50 }
51
53 {
54 fAdjusted = fObj = nullptr;
55 fOwner = false;
56 }
57
58 const TClass *GetClass() const final { return fObj ? fObj->IsA() : nullptr; }
59 const void *GetObject() const final { return fAdjusted; }
60};
61
62
63} // namespace Browsable
64} // namespace ROOT
65
66
67#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Basic class for object holder of any kind.
Definition RHolder.hxx:32
Holder of TObject instance.
TObjectHolder(TObject *obj, bool owner=false)
RHolder * DoCopy() const final
Create copy of container, works only when pointer can be shared.
void Forget() final
Clear all pointers without performing cleanup.
const TClass * GetClass() const final
Returns class of contained object.
TObject * fObj
! plain holder without IO
const void * GetObject() const final
Returns direct (temporary) object pointer.
void * AccessObject() final
Returns plain object pointer without care about ownership, should not be used often.
void ClearROOTOwnership(TObject *obj)
Check if object is not registered in some global lists Prevent double deletion.
void * fAdjusted
! pointer on real class returned by fObj->IsA()
void * TakeObject() final
Return TObject instance with ownership If object is not owned by the holder, it will be cloned (excep...
bool fOwner
! is TObject owner
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Mother of all ROOT objects.
Definition TObject.h:42
static TClass * Class()
virtual TClass * IsA() const
Definition TObject.h:248