92 using Vec_t = std::decay_t<
decltype(*c)>;
96 WithCont(p, [](
auto *
c, std::size_t) {
delete c; });
106 Warning(
"DeleteArray",
"Cannot properly delete emulated array of %s at %p, I don't know how many elements it has!",
fClass->GetName(), p);
108 ::operator
delete(p);
124 std::vector<std::string> inside;
129 if ( inside[0].find(
"stdext::hash_") != std::string::npos ) {
130 inside[0].replace(3,10,
"::");
132 if ( inside[0].find(
"__gnu_cxx::hash_") != std::string::npos ) {
133 inside[0].replace(0,16,
"std::");
139 auto alignedSize = [](
size_t in,
TClass *align_cl) {
140 size_t align = align_cl ? align_cl->GetClassAlignment() :
alignof(std::max_align_t);
141 return in + (align - in % align) % align;
143 struct GenerateTemporaryTEnum {
144 TEnum *fTemporaryTEnum =
nullptr;
146 GenerateTemporaryTEnum(
UInt_t typecase,
const std::string &enumname)
149 fTemporaryTEnum =
new TEnum();
150 fTemporaryTEnum->
SetName(enumname.c_str());
151 gROOT->GetListOfEnums()->Add(fTemporaryTEnum);
155 ~GenerateTemporaryTEnum()
157 if (fTemporaryTEnum) {
158 gROOT->GetListOfEnums()->Remove(fTemporaryTEnum);
159 delete fTemporaryTEnum;
166 nam =
"pair<"+inside[1]+
","+inside[2];
167 nam += (nam[nam.length()-1]==
'>') ?
" >" :
">";
182 GenerateTemporaryTEnum keyEnum(
fKey->fCase, inside[1]);
183 GenerateTemporaryTEnum valueEnum(
fVal->fCase, inside[2]);
191 if ( !(*fValue).IsValid() || !
fKey->IsValid() || !
fVal->IsValid() ) {
199 fValOffset = alignedSize(
fKey->fSize, (*fValue).fType.GetClass());
204 if (num > 3 && !inside[3].empty()) {
216 if ( !(*fValue).IsValid() || !
fVal->IsValid() ) {
224 if (num > 2 && !inside[2].empty()) {
238 Fatal(
"TEmulatedCollectionProxy",
"Components of %s not analysed!",cl->
GetName());
240 Fatal(
"TEmulatedCollectionProxy",
"Collection class %s not found!",
fTypeinfo.name());
257 Fatal(
"TEmulatedCollectionProxy",
"Size> Logic error - no proxy object set.");
264 Resize(0, opt && *opt==
'f');
271 typedef std::string String_t;
279 switch(
fKey->fCase) {
284 for( i=
fKey->fType ? left : nCurr; i<nCurr; ++i, addr +=
fValDiff ) {
290 for( i=left; i<nCurr; ++i, addr +=
fValDiff ) {
291 ((std::string*)addr)->~String_t();
295 for( i=left; i<nCurr; ++i, addr +=
fValDiff ) {
299 void* ptr =
h->ptr();
300 if (force)
fKey->fType->Destructor(ptr);
305 for( i=nCurr; i<left; ++i, addr +=
fValDiff ) {
309 if (force)
delete (std::string*)
h->ptr();
314 for( i=nCurr; i<left; ++i, addr +=
fValDiff ) {
316 if (force)
delete (
TString*)
h->ptr();
326 switch(
fVal->fCase ) {
331 for( i=left; i<nCurr; ++i, addr +=
fValDiff ) {
337 for( i=left; i<nCurr; ++i, addr +=
fValDiff )
338 ((std::string*)addr)->~String_t();
341 for( i=left; i<nCurr; ++i, addr +=
fValDiff ) {
345 fVal->fType->Destructor(p);
351 for( i=nCurr; i<left; ++i, addr +=
fValDiff ) {
353 if (force)
delete (std::string*)
h->ptr();
358 for( i=nCurr; i<left; ++i, addr +=
fValDiff ) {
360 if (force)
delete (
TString*)
h->ptr();
366 WithCont(
fEnv->fObject, [&](
auto *
c, std::size_t alignmentElemSize) {
367 assert(fValDiff % alignmentElemSize == 0);
368 c->resize(left * fValDiff / alignmentElemSize);
369 fEnv->fStart = left > 0 ? c->data() : nullptr;
378 void *oldstart =
fEnv->fStart;
379 WithCont(
fEnv->fObject, [&](
auto *
c, std::size_t alignmentElemSize) {
380 assert(fValDiff % alignmentElemSize == 0);
381 c->resize(left * fValDiff / alignmentElemSize);
382 fEnv->fStart = left > 0 ? c->data() : nullptr;
389 switch(
fKey->fCase) {
394 if (oldstart && oldstart !=
fEnv->fStart) {
396 for( i=0; i<=nCurr; ++i, offset +=
fValDiff ) {
400 fKey->fType->Move(((
char*)oldstart)+offset,((
char*)
fEnv->fStart)+offset);
403 for( i=nCurr; i<left; ++i, addr +=
fValDiff )
404 fKey->fType->New(addr);
407 for( i=nCurr; i<left; ++i, addr +=
fValDiff )
408 ::new(addr) std::string();
413 for( i=nCurr; i<left; ++i, addr +=
fValDiff )
422 switch(
fVal->fCase) {
427 if (oldstart && oldstart !=
fEnv->fStart) {
429 for( i=0; i<=nCurr; ++i, offset +=
fValDiff ) {
433 fVal->fType->Move(((
char*)oldstart)+offset,((
char*)
fEnv->fStart)+offset);
436 for( i=nCurr; i<left; ++i, addr +=
fValDiff ) {
437 fVal->fType->New(addr);
441 for( i=nCurr; i<left; ++i, addr +=
fValDiff )
442 ::new(addr) std::string();
447 for( i=nCurr; i<left; ++i, addr +=
fValDiff )
460 size_t nCurr =
Size();
462 fEnv->fStart = nCurr > 0 ?
c->data() : 0;
463 if ( left == nCurr ) {
466 else if ( left < nCurr ) {
467 Shrink(nCurr, left, force);
473 Fatal(
"TEmulatedCollectionProxy",
"Resize> Logic error - no proxy object set.");
481 size_t s =
c->size();
487 Fatal(
"TEmulatedCollectionProxy",
"At> Logic error - no proxy object set.");
496 return fEnv->fObject;
505 Fatal(
"Insert",
"Not yet implemented, require copy of objects.");
515 Bool_t vsn3 =
b.GetInfo() &&
b.GetInfo()->GetOldVersion()<=3;
517 switch (
fVal->fCase) {
520 switch(
int(
fVal->fKind) ) {
524 case kInt_t:
b.ReadFastArray(&itm->
s_int , nElements);
break;
527 case kFloat_t:
b.ReadFastArray(&itm->
flt , nElements);
break;
528 case kFloat16_t:
b.ReadFastArrayFloat16(&itm->
flt, nElements);
break;
529 case kDouble_t:
b.ReadFastArray(&itm->
dbl , nElements);
break;
532 case kUInt_t:
b.ReadFastArray(&itm->
u_int , nElements);
break;
539 Error(
"TEmulatedCollectionProxy",
"fType %d is not supported yet!\n",
fVal->fKind);
543#define DOLOOP(x) {int idx=0; while(idx<nElements) {StreamHelper* i=(StreamHelper*)(((char*)itm) + fValDiff*idx); { x ;} ++idx;} break;}
548 DOLOOP( i->read_std_string(
b) );
552 DOLOOP( i->read_std_string_pointer(
b) );
554 DOLOOP( i->read_tstring_pointer(vsn3,
b) );
565 switch (
fVal->fCase) {
569 switch(
int(
fVal->fKind) ) {
573 case kInt_t:
b.WriteFastArray(&itm->
s_int , nElements);
break;
576 case kFloat_t:
b.WriteFastArray(&itm->
flt , nElements);
break;
577 case kFloat16_t:
b.WriteFastArrayFloat16(&itm->
flt, nElements);
break;
578 case kDouble_t:
b.WriteFastArray(&itm->
dbl , nElements);
break;
581 case kUInt_t:
b.WriteFastArray(&itm->
u_int , nElements);
break;
588 Error(
"TEmulatedCollectionProxy",
"fType %d is not supported yet!\n",
fVal->fKind);
591#define DOLOOP(x) {int idx=0; while(idx<nElements) {StreamHelper* i=(StreamHelper*)(((char*)itm) + fValDiff*idx); { x ;} ++idx;} break;}
599 DOLOOP( i->write_std_string_pointer(
b) );
601 DOLOOP( i->write_tstring_pointer(
b) );
621 if (
fEnv->fObject ) {
624 if ( nElements > 0 ) {
632 if (
b.IsReading() ) {
635 if (
fEnv->fObject ) {
638 if ( nElements > 0 ) {
643 int nElements =
fEnv->fObject ?
Size() : 0;
645 if ( nElements > 0 ) {
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
externTVirtualMutex * gInterpreterMutex
#define R__LOCKGUARD(mutex)
Buffer base class used for serializing objects.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
UInt_t Size() const override
Return the current number of elements in the container.
void Insert(const void *data, void *container, size_t size) override
Insert data into the container where data is a C-style array of the actual type contained in the coll...
TGenCollectionProxy * InitializeEx(Bool_t silent) override
Proxy initializer.
void * Allocate(UInt_t n, Bool_t forceDelete) override
Allocates space for storing at least n elements.
void Expand(UInt_t nCurr, UInt_t left)
void WriteItems(int nElements, TBuffer &b)
TVirtualCollectionProxy * Generate() const override
Returns a clean object of the actual class that derives from TVirtualCollectionProxy.
std::vector< char > Cont_t
void Commit(void *env) override
Commits pending elements in a staging area (see Allocate() for more information).
~TEmulatedCollectionProxy() override
void Clear(const char *opt="") override
Clear the container.
void Shrink(UInt_t nCurr, UInt_t left, Bool_t force)
void * At(UInt_t idx) override
Return the address of the value at index idx.
void ReadItems(int nElements, TBuffer &b)
void WithCont(void *obj, F &&fn) const
Invoke fn(typed_ptr, elemSize) where typed_ptr is the container pointer cast to the correct AlignedSt...
void Destructor(void *p, Bool_t dtorOnly=kFALSE) const override
Execute the container destructor.
void ReadBuffer(TBuffer &buff, void *pObj) override
void Streamer(TBuffer &refBuffer) override
Streamer Function.
void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const override
Execute the container array destructor.
TEmulatedCollectionProxy(const TEmulatedCollectionProxy ©)
void Resize(UInt_t n, Bool_t force_delete) override
Resize the container.
The TEnum class implements the enum type.
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
std::atomic< Value * > fValue
Descriptor of the container value type.
Bool_t fPointers
Flag to indicate if containee has pointers (key or value).
Info_t fTypeinfo
Type information.
int fValOffset
Offset from key to value (in maps).
EnvironBase_t * fEnv
Address of the currently proxied object.
TGenCollectionProxy * Initialize(Bool_t silent) const
Proxy initializer.
std::string fName
Name of the class being proxied.
int fSTL_type
STL container type.
Value * fKey
Descriptor of the key_type.
Method0 fCreateEnv
Method to allocate an Environment holder.
Value * fVal
Descriptor of the Value_type.
virtual void SetOnFileClass(TClass *cl)
int fValDiff
Offset between two consecutive value_types (memory layout).
const char * GetName() const override
Returns name of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void Streamer(TBuffer &)
Stream a string object.
RAII helper class that ensures that PushProxy() / PopProxy() are called when entering / leaving a C++...
@ kCustomAlloc
The collection has a custom allocator.
@ kNeedDelete
The collection contains directly or indirectly (via other collection) some pointers that need explici...
TVirtualCollectionProxy(const TVirtualCollectionProxy &)=delete
virtual TVirtualStreamerInfo * GenerateInfoForPair(const std::string &pairclassname, bool silent, size_t hint_pair_offset, size_t hint_pair_size)=0
Generate the TClass and TStreamerInfo for the requested pair.
static TVirtualStreamerInfo * Factory()
Static function returning a pointer to a new TVirtualStreamerInfo object.
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
bool IsDefAlloc(const char *alloc, const char *classname)
return whether or not 'allocname' is the STL default allocator for type 'classname'
Small helper to describe the Value_type or the key_type of an STL container.
Helper class to facilitate I/O.