File indexing completed on 2026-09-24 09:25:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOT_TGenCollectionProxy
0012 #define ROOT_TGenCollectionProxy
0013
0014 #include "TBuffer.h"
0015
0016 #include "TVirtualCollectionProxy.h"
0017
0018 #include "TCollectionProxyInfo.h"
0019
0020 #include "ROOT/RAlignmentUtils.hxx"
0021
0022 #include <atomic>
0023 #include <string>
0024 #include <map>
0025 #include <cstdlib>
0026 #include <cstddef>
0027 #include <vector>
0028 #include <new>
0029
0030 class TObjArray;
0031 class TCollectionProxyFactory;
0032
0033 class TGenCollectionProxy
0034 : public TVirtualCollectionProxy
0035 {
0036
0037
0038 friend class TCollectionProxyFactory;
0039
0040 public:
0041
0042 #ifdef R__HPUX
0043 typedef const std::type_info& Info_t;
0044 #else
0045 typedef const std::type_info& Info_t;
0046 #endif
0047
0048 enum {
0049
0050
0051 kBIT_ISSTRING = 0x20000000,
0052 kBIT_ISTSTRING = 0x40000000
0053 };
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 struct Value {
0065 ROOT::NewFunc_t fCtor;
0066 ROOT::DesFunc_t fDtor;
0067 ROOT::DelFunc_t fDelete;
0068 UInt_t fCase;
0069 UInt_t fProperties;
0070 TClassRef fType;
0071 EDataType fKind;
0072 size_t fSize;
0073
0074
0075
0076
0077 Value(const std::string& info, Bool_t silent, size_t hint_pair_offset = 0, size_t hint_pair_size = 0);
0078
0079 void DeleteItem(void* ptr);
0080
0081 Bool_t IsValid();
0082 };
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 union StreamHelper {
0093 Bool_t boolean;
0094 Char_t s_char;
0095 Short_t s_short;
0096 Int_t s_int;
0097 Long_t s_long;
0098 Long64_t s_longlong;
0099 Float_t flt;
0100 Double_t dbl;
0101 UChar_t u_char;
0102 UShort_t u_short;
0103 UInt_t u_int;
0104 ULong_t u_long;
0105 ULong64_t u_longlong;
0106 void* p_void;
0107 void** pp_void;
0108 char* kchar;
0109 TString* tstr;
0110 void* ptr() {
0111 return *(&this->p_void);
0112 }
0113 std::string* str() {
0114 return (std::string*)this;
0115 }
0116 const char* c_str() {
0117 return ((std::string*)this)->c_str();
0118 }
0119 const char* c_pstr() {
0120 return (*(std::string**)this)->c_str();
0121 }
0122 void set(void* p) {
0123 *(&this->p_void) = p;
0124 }
0125 void read_std_string(TBuffer& b) {
0126 TString s;
0127 s.Streamer(b);
0128 ((std::string*)this)->assign(s.Data());
0129 }
0130 void* read_tstring(TBuffer& b) {
0131 *((TString*)this) = "";
0132 ((TString*)this)->Streamer(b);
0133 return this;
0134 }
0135 void read_std_string_pointer(TBuffer& b) {
0136 TString s;
0137 std::string* str2 = (std::string*)ptr();
0138 if (!str2) str2 = new std::string();
0139 s.Streamer(b);
0140 *str2 = s;
0141 set(str2);
0142 }
0143 void write_std_string_pointer(TBuffer& b) {
0144 const char* c;
0145 if (ptr()) {
0146 std::string* strptr = (*(std::string**)this);
0147 c = (const char*)(strptr->c_str());
0148 } else c = "";
0149 TString(c).Streamer(b);
0150 }
0151 void read_any_object(Value* v, TBuffer& b) {
0152 void* p = ptr();
0153 if ( p ) {
0154 if ( v->fDelete ) {
0155 (*v->fDelete)(p);
0156 }
0157 else if ( v->fType ) {
0158 v->fType->Destructor(p);
0159 }
0160 else if ( v->fDtor ) {
0161 (*v->fDtor)(p);
0162 ::operator delete(p);
0163 }
0164 else {
0165 ::operator delete(p);
0166 }
0167 }
0168 set( b.ReadObjectAny(v->fType) );
0169 }
0170
0171 void read_tstring_pointer(Bool_t vsn3, TBuffer& b) {
0172 TString* s = (TString*)ptr();
0173 if ( vsn3 ) {
0174 if ( !s ) s = new TString();
0175 else s->Clear();
0176 s->Streamer(b);
0177 set(s);
0178 return;
0179 }
0180 if ( s ) delete s;
0181 set( b.ReadObjectAny(TString::Class()) );
0182 }
0183 void write_tstring_pointer(TBuffer& b) {
0184 b.WriteObjectAny(ptr(), TString::Class());
0185 }
0186 };
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 class Method {
0198 public:
0199 typedef void* (*Call_t)(void*);
0200 Call_t call;
0201 Method() : call(nullptr) { }
0202 Method(Call_t c) : call(c) { }
0203 Method(const Method& m) : call(m.call) { }
0204 Method &operator=(const Method& m) { call = m.call; return *this; }
0205 void* invoke(void* obj) const { return (*call)(obj); }
0206 };
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 class Method0 {
0218 public:
0219 typedef void* (*Call_t)();
0220 Call_t call;
0221 Method0() : call(nullptr) { }
0222 Method0(Call_t c) : call(c) { }
0223 Method0(const Method0& m) : call(m.call) { }
0224 Method0 &operator=(const Method0& m) { call = m.call; return *this; }
0225 void* invoke() const { return (*call)(); }
0226 };
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238 class TStaging {
0239 void *fTarget;
0240 void *fContent;
0241 size_t fReserved;
0242 size_t fSize;
0243 size_t fSizeOf;
0244
0245 TStaging(const TStaging&);
0246 TStaging &operator=(const TStaging&);
0247
0248 public:
0249 TStaging(size_t size, size_t size_of) : fTarget(nullptr), fContent(nullptr), fReserved(0), fSize(size), fSizeOf(size_of)
0250 {
0251
0252 fReserved = fSize;
0253 fContent = ::malloc(fReserved * fSizeOf);
0254 }
0255
0256 ~TStaging() {
0257
0258 ::free(fContent);
0259 }
0260
0261 void *GetContent() {
0262
0263 return fContent;
0264 }
0265 void *GetEnd() {
0266
0267 return ((char*)fContent) + fSize*fSizeOf;
0268 }
0269 size_t GetSize() {
0270
0271 return fSize;
0272 }
0273 void *GetTarget() {
0274
0275 return fTarget;
0276 }
0277 void Resize(size_t nelement) {
0278 if (fReserved < nelement) {
0279 fReserved = nelement;
0280 fContent = ::realloc(fContent,fReserved * fSizeOf);
0281 }
0282 fSize = nelement;
0283 }
0284 void SetTarget(void *target) {
0285
0286 fTarget = target;
0287 }
0288 };
0289
0290 protected:
0291 typedef ROOT::Detail::TCollectionProxyInfo::Environ<char[64]> Env_t;
0292 typedef ROOT::Detail::TCollectionProxyInfo::EnvironBase EnvironBase_t;
0293 typedef std::vector<TStaging*> Staged_t;
0294 typedef std::vector<EnvironBase_t*> Proxies_t;
0295 mutable TObjArray *fReadMemberWise;
0296 mutable std::map<std::string, TObjArray*> *fConversionReadMemberWise;
0297 mutable TStreamerInfoActions::TActionSequence *fWriteMemberWise;
0298 typedef void (*Sizing_t)(void *obj, size_t size);
0299 typedef void* (*Feedfunc_t)(void *from, void *to, size_t size);
0300 typedef void* (*Collectfunc_t)(void *from, void *to);
0301 typedef void* (*ArrIterfunc_t)(void *from, size_t size);
0302
0303 std::string fName;
0304 Bool_t fPointers;
0305 Method fClear;
0306 Method fSize;
0307 Sizing_t fResize;
0308 Method fFirst;
0309 Method fNext;
0310 ArrIterfunc_t fConstruct;
0311 Sizing_t fDestruct;
0312 Feedfunc_t fFeed;
0313 Collectfunc_t fCollect;
0314 Method0 fCreateEnv;
0315 std::atomic<Value*> fValue;
0316 Value* fVal;
0317 Value* fKey;
0318 EnvironBase_t*fEnv;
0319 int fValOffset;
0320 int fValDiff;
0321 Proxies_t fProxyList;
0322 Proxies_t fProxyKept;
0323 Staged_t fStaged;
0324 int fSTL_type;
0325 Info_t fTypeinfo;
0326 TClass* fOnFileClass;
0327
0328 CreateIterators_t fFunctionCreateIterators;
0329 CopyIterator_t fFunctionCopyIterator;
0330 Next_t fFunctionNextIterator;
0331 DeleteIterator_t fFunctionDeleteIterator;
0332 DeleteTwoIterators_t fFunctionDeleteTwoIterators;
0333
0334
0335 TGenCollectionProxy* Initialize(Bool_t silent) const;
0336
0337 virtual TGenCollectionProxy* InitializeEx(Bool_t silent);
0338
0339 virtual void DeleteItem(Bool_t force, void* ptr) const;
0340
0341 void CheckFunctions() const;
0342
0343 private:
0344 TGenCollectionProxy();
0345
0346 public:
0347
0348
0349 TVirtualCollectionProxy* Generate() const override;
0350
0351
0352 TGenCollectionProxy(const TGenCollectionProxy& copy);
0353
0354 private:
0355
0356 TGenCollectionProxy &operator=(const TGenCollectionProxy&);
0357
0358 public:
0359
0360 TGenCollectionProxy(Info_t typ, size_t iter_size);
0361 TGenCollectionProxy(const ROOT::Detail::TCollectionProxyInfo &info, TClass *cl);
0362
0363
0364 ~TGenCollectionProxy() override;
0365
0366
0367 Bool_t Reset() override;
0368
0369
0370 TClass *GetCollectionClass() const override;
0371
0372
0373 Int_t GetCollectionType() const override;
0374
0375
0376 ULong_t GetIncrement() const override;
0377
0378
0379 UInt_t Sizeof() const override;
0380
0381
0382 void PushProxy(void *objstart) override;
0383
0384
0385 void PopProxy() override;
0386
0387
0388 Bool_t HasPointers() const override;
0389
0390
0391 TClass *GetValueClass() const override;
0392
0393
0394 EDataType GetType() const override;
0395
0396
0397 void *At(UInt_t idx) override;
0398
0399
0400 void Clear(const char *opt = "") override;
0401
0402
0403 virtual void Resize(UInt_t n, Bool_t force_delete);
0404
0405
0406 UInt_t Size() const override;
0407
0408
0409 void* Allocate(UInt_t n, Bool_t forceDelete) override;
0410
0411
0412
0413 void Insert(const void *data, void *container, size_t size) override;
0414
0415
0416 void Commit(void* env) override;
0417
0418
0419 virtual void Streamer(TBuffer &refBuffer);
0420
0421
0422 virtual void Streamer(TBuffer &refBuffer, void *pObject, int siz);
0423
0424
0425 virtual void operator()(TBuffer &refBuffer, void *pObject);
0426
0427
0428 virtual void ReadBuffer(TBuffer &b, void *obj);
0429 virtual void ReadBuffer(TBuffer &b, void *obj, const TClass *onfileClass);
0430
0431 virtual void SetOnFileClass( TClass* cl ) { fOnFileClass = cl; }
0432 virtual TClass* GetOnFileClass() const { return fOnFileClass; }
0433
0434
0435 TStreamerInfoActions::TActionSequence *GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version) override;
0436 TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Int_t version) override;
0437 TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions() override;
0438
0439
0440
0441 CreateIterators_t GetFunctionCreateIterators(Bool_t read = kTRUE) override;
0442
0443
0444
0445
0446
0447 CopyIterator_t GetFunctionCopyIterator(Bool_t read = kTRUE) override;
0448
0449
0450
0451
0452
0453
0454 Next_t GetFunctionNext(Bool_t read = kTRUE) override;
0455
0456
0457
0458
0459
0460
0461
0462 DeleteIterator_t GetFunctionDeleteIterator(Bool_t read = kTRUE) override;
0463 DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read = kTRUE) override;
0464
0465
0466
0467
0468
0469 };
0470
0471 template <typename T>
0472 struct AnyCollectionProxy : public TGenCollectionProxy {
0473 AnyCollectionProxy()
0474 : TGenCollectionProxy(typeid(T::Cont_t),sizeof(T::Iter_t))
0475 {
0476
0477 fValDiff = sizeof(T::Value_t);
0478 fValOffset = T::value_offset();
0479 fSize.call = T::size;
0480 fResize = T::resize;
0481 fNext.call = T::next;
0482 fFirst.call = T::first;
0483 fClear.call = T::clear;
0484 fConstruct = T::construct;
0485 fDestruct = T::destruct;
0486 fFeed = T::feed;
0487 CheckFunctions();
0488 }
0489 ~AnyCollectionProxy() override { }
0490 };
0491
0492 #endif
0493