File indexing completed on 2025-01-18 10:10:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_Browsable_TObjectHolder
0010 #define ROOT7_Browsable_TObjectHolder
0011
0012 #include <ROOT/Browsable/RHolder.hxx>
0013
0014 namespace ROOT {
0015 namespace Browsable {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 class TObjectHolder : public RHolder {
0026 TObject *fObj{nullptr};
0027 void *fAdjusted{nullptr};
0028 bool fOwner{false};
0029 protected:
0030 void *AccessObject() final { return fOwner ? nullptr : fObj; }
0031 void *TakeObject() final;
0032 RHolder *DoCopy() const final { return new TObjectHolder(fObj); }
0033 void ClearROOTOwnership(TObject *obj);
0034 public:
0035 TObjectHolder(TObject *obj, bool owner = false)
0036 {
0037 fAdjusted = fObj = obj;
0038 fOwner = owner;
0039 if (fOwner && fObj)
0040 ClearROOTOwnership(fObj);
0041 if (fAdjusted) {
0042 auto offset = fObj->IsA()->GetBaseClassOffset(TObject::Class());
0043 if (offset > 0)
0044 fAdjusted = (char *) fAdjusted - offset;
0045 }
0046 }
0047
0048 virtual ~TObjectHolder()
0049 {
0050 if (fOwner) delete fObj;
0051 }
0052
0053 void Forget() final
0054 {
0055 fAdjusted = fObj = nullptr;
0056 fOwner = false;
0057 }
0058
0059 const TClass *GetClass() const final { return fObj ? fObj->IsA() : nullptr; }
0060 const void *GetObject() const final { return fAdjusted; }
0061 };
0062
0063
0064 }
0065 }
0066
0067
0068 #endif