Logo ROOT   6.08/07
Reference Guide
TEmulatedCollectionProxy.cxx
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Markus Frank 28/10/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /**
13  \class TEmulatedCollectionProxy
14  \ingroup IO
15 
16 Streamer around an arbitrary STL like container, which implements basic
17 container functionality.
18 
19 ### Note:
20 Although this class contains all the setup necessary to deal
21 with maps, the map-like functionality is NOT supported.
22 For optimization reasons this functionality is put into
23 the class TEmulatedMapProxy.
24 */
25 
27 #include "TStreamerElement.h"
28 #include "TStreamerInfo.h"
29 #include "TClassEdit.h"
30 #include "TError.h"
31 #include "TROOT.h"
32 #include "Riostream.h"
33 
34 #include "TVirtualMutex.h" // For R__LOCKGUARD
35 #include "TInterpreter.h" // For gInterpreterMutex
36 
37 //
38 // Utility function to allow the creation of a TClass for a std::pair without
39 // a dictionary (See end of file for implementation
40 //
41 
42 static TStreamerElement* R__CreateEmulatedElement(const char *dmName, const char *dmFull, Int_t offset);
43 static TStreamerInfo *R__GenerateTClassForPair(const std::string &f, const std::string &s);
44 
46  : TGenCollectionProxy(copy)
47 {
48  // Build a Streamer for an emulated vector whose type is 'name'.
50 }
51 
53  : TGenCollectionProxy(typeid(std::vector<char>), sizeof(std::vector<char>::iterator))
54 {
55  // Build a Streamer for a collection whose type is described by 'collectionClass'.
56 
57  fName = cl_name;
58  if ( this->TEmulatedCollectionProxy::InitializeEx(silent) ) {
60  }
62 }
63 
65 {
66  // Standard destructor
67  if ( fEnv && fEnv->fObject ) {
68  Clear();
69  }
70 }
71 
73 {
74  // Virtual copy constructor
75 
76  if ( !fClass ) Initialize(kFALSE);
77  return new TEmulatedCollectionProxy(*this);
78 }
79 
80 void TEmulatedCollectionProxy::Destructor(void* p, Bool_t dtorOnly) const
81 {
82  // Virtual destructor
83 
84  if (!p) return;
85  if (!fEnv || fEnv->fObject != p) { // Envoid the cost of TPushPop if we don't need it
86  // FIXME: This is not thread safe.
87  TVirtualCollectionProxy::TPushPop env(const_cast<TEmulatedCollectionProxy*>(this), p);
88  const_cast<TEmulatedCollectionProxy*>(this)->Clear("force");
89  } else {
90  const_cast<TEmulatedCollectionProxy*>(this)->Clear("force");
91  }
92  if (dtorOnly) {
93  ((Cont_t*)p)->~Cont_t();
94  } else {
95  delete (Cont_t*) p;
96  }
97 }
98 
99 void TEmulatedCollectionProxy::DeleteArray(void* p, Bool_t dtorOnly) const
100 {
101  // Virtual array destructor
102 
103  // Cannot implement this properly, we do not know
104  // how many elements are in the array.
105  Warning("DeleteArray", "Cannot properly delete emulated array of %s at %p, I don't know how many elements it has!", fClass->GetName(), p);
106  if (!dtorOnly) {
107  delete[] (Cont_t*) p;
108  }
109 }
110 
112 {
113  // Proxy initializer
115  if (fClass) return this;
116 
117 
118  TClass *cl = TClass::GetClass(fName.c_str());
119  fEnv = 0;
120  fKey = 0;
121  if ( cl ) {
122  int nested = 0;
123  std::vector<std::string> inside;
124  fPointers = false;
125  int num = TClassEdit::GetSplit(fName.c_str(),inside,nested);
126  if ( num > 1 ) {
127  std::string nam;
128  if ( inside[0].find("stdext::hash_") != std::string::npos ) {
129  inside[0].replace(3,10,"::");
130  }
131  if ( inside[0].find("__gnu_cxx::hash_") != std::string::npos ) {
132  inside[0].replace(0,16,"std::");
133  }
134  fSTL_type = TClassEdit::STLKind(inside[0].c_str());
135  // Note: an emulated collection proxy is never really associative
136  // since under-neath is actually an array.
137 
138  // std::cout << "Initialized " << typeid(*this).name() << ":" << fName << std::endl;
139  auto alignedSize = [](size_t in) {
140  constexpr size_t kSizeOfPtr = sizeof(void*);
141  return in + (kSizeOfPtr - in%kSizeOfPtr)%kSizeOfPtr;
142  };
143  switch ( fSTL_type ) {
144  case ROOT::kSTLmap:
145  case ROOT::kSTLmultimap:
146  nam = "pair<"+inside[1]+","+inside[2];
147  nam += (nam[nam.length()-1]=='>') ? " >" : ">";
148  if (0==TClass::GetClass(nam.c_str())) {
149  // We need to emulate the pair
150  R__GenerateTClassForPair(inside[1],inside[2]);
151  }
152  fValue = new Value(nam,silent);
153  fKey = new Value(inside[1],silent);
154  fVal = new Value(inside[2],silent);
155  if ( !(*fValue).IsValid() || !fKey->IsValid() || !fVal->IsValid() ) {
156  return 0;
157  }
158  fPointers |= 0 != (fKey->fCase&kIsPointer);
159  if (fPointers || (0 != (fKey->fProperties&kNeedDelete))) {
161  }
162  if ( 0 == fValOffset ) {
163  fValOffset = alignedSize(fKey->fSize);
164  }
165  if ( 0 == fValDiff ) {
166  fValDiff = alignedSize(fValOffset + fVal->fSize);
167  }
168  break;
169  case ROOT::kSTLbitset:
170  inside[1] = "bool";
171  // Intentional fall through
172  default:
173  fValue = new Value(inside[1],silent);
174  fVal = new Value(*fValue);
175  if ( !(*fValue).IsValid() || !fVal->IsValid() ) {
176  return 0;
177  }
178  if ( 0 == fValDiff ) {
179  fValDiff = fVal->fSize;
180  // No need to align, the size even for a class should already
181  // be correctly padded for use in a vector.
182  }
183  break;
184  }
185  fPointers |= 0 != (fVal->fCase&kIsPointer);
186  if (fPointers || (0 != (fVal->fProperties&kNeedDelete))) {
188  }
189  fClass = cl;
190  return this;
191  }
192  Fatal("TEmulatedCollectionProxy","Components of %s not analysed!",cl->GetName());
193  }
194  Fatal("TEmulatedCollectionProxy","Collection class %s not found!",fTypeinfo.name());
195  return 0;
196 }
197 
199 {
200  // Return true if the collection proxy was well initialized.
201  return (0 != fCreateEnv.call);
202 }
203 
205 {
206  // Return the current size of the container
207 
208  if ( fEnv && fEnv->fObject ) {
209  return fEnv->fSize = PCont_t(fEnv->fObject)->size()/fValDiff;
210  }
211  Fatal("TEmulatedCollectionProxy","Size> Logic error - no proxy object set.");
212  return 0;
213 }
214 
215 void TEmulatedCollectionProxy::Clear(const char* opt)
216 {
217  // Clear the emulated collection.
218  Resize(0, opt && *opt=='f');
219 }
220 
222 {
223  // Shrink the container
224 
225  typedef std::string String_t;
227  char* addr = ((char*)fEnv->fStart) + fValDiff*left;
228  size_t i;
229 
230  switch ( fSTL_type ) {
231  case ROOT::kSTLmap:
232  case ROOT::kSTLmultimap:
233  addr = ((char*)fEnv->fStart) + fValDiff*left;
234  switch(fKey->fCase) {
235  case kIsFundamental: // Only handle primitives this way
236  case kIsEnum:
237  break;
238  case kIsClass:
239  for( i= fKey->fType ? left : nCurr; i<nCurr; ++i, addr += fValDiff ) {
240  // Call emulation in case non-compiled content
241  fKey->fType->Destructor(addr, kTRUE);
242  }
243  break;
244  case kBIT_ISSTRING:
245  for( i=left; i<nCurr; ++i, addr += fValDiff ) {
246  ((std::string*)addr)->~String_t();
247  }
248  break;
249  case kIsPointer|kIsClass:
250  for( i=left; i<nCurr; ++i, addr += fValDiff ) {
251  StreamHelper* h = (StreamHelper*)addr;
252  //Eventually we'll need to delete this
253  //(but only when needed).
254  void* ptr = h->ptr();
255  if (force) fKey->fType->Destructor(ptr);
256  h->set(0);
257  }
258  break;
260  for( i=nCurr; i<left; ++i, addr += fValDiff ) {
261  StreamHelper* h = (StreamHelper*)addr;
262  //Eventually we'll need to delete this
263  //(but only when needed).
264  if (force) delete (std::string*)h->ptr();
265  h->set(0);
266  }
267  break;
269  for( i=nCurr; i<left; ++i, addr += fValDiff ) {
270  StreamHelper* h = (StreamHelper*)addr;
271  if (force) delete (TString*)h->ptr();
272  h->set(0);
273  }
274  break;
275  }
276  addr = ((char*)fEnv->fStart)+fValOffset+fValDiff*left;
277  // DO NOT break; just continue
278 
279  // General case for all values
280  default:
281  switch( fVal->fCase ) {
282  case kIsFundamental: // Only handle primitives this way
283  case kIsEnum:
284  break;
285  case kIsClass:
286  for( i=left; i<nCurr; ++i, addr += fValDiff ) {
287  // Call emulation in case non-compiled content
288  fVal->fType->Destructor(addr,kTRUE);
289  }
290  break;
291  case kBIT_ISSTRING:
292  for( i=left; i<nCurr; ++i, addr += fValDiff )
293  ((std::string*)addr)->~String_t();
294  break;
295  case kIsPointer|kIsClass:
296  for( i=left; i<nCurr; ++i, addr += fValDiff ) {
297  StreamHelper* h = (StreamHelper*)addr;
298  void* p = h->ptr();
299  if ( p && force ) {
300  fVal->fType->Destructor(p);
301  }
302  h->set(0);
303  }
304  break;
306  for( i=nCurr; i<left; ++i, addr += fValDiff ) {
307  StreamHelper* h = (StreamHelper*)addr;
308  if (force) delete (std::string*)h->ptr();
309  h->set(0);
310  }
311  break;
313  for( i=nCurr; i<left; ++i, addr += fValDiff ) {
314  StreamHelper* h = (StreamHelper*)addr;
315  if (force) delete (TString*)h->ptr();
316  h->set(0);
317  }
318  break;
319  }
320  }
321  c->resize(left*fValDiff,0);
322  fEnv->fStart = left>0 ? &(*c->begin()) : 0;
323  return;
324 }
325 
327 {
328  // Expand the container
329  size_t i;
331  c->resize(left*fValDiff,0);
332  void *oldstart = fEnv->fStart;
333  fEnv->fStart = left>0 ? &(*c->begin()) : 0;
334 
335  char* addr = ((char*)fEnv->fStart) + fValDiff*nCurr;
336  switch ( fSTL_type ) {
337  case ROOT::kSTLmap:
338  case ROOT::kSTLmultimap:
339  switch(fKey->fCase) {
340  case kIsFundamental: // Only handle primitives this way
341  case kIsEnum:
342  break;
343  case kIsClass:
344  if (oldstart && oldstart != fEnv->fStart) {
345  Long_t offset = 0;
346  for( i=0; i<=nCurr; ++i, offset += fValDiff ) {
347  // For now 'Move' only register the change of location
348  // so per se this is wrong since the object are copied via memcpy
349  // rather than a copy (or move) constructor.
350  fKey->fType->Move(((char*)oldstart)+offset,((char*)fEnv->fStart)+offset);
351  }
352  }
353  for( i=nCurr; i<left; ++i, addr += fValDiff )
354  fKey->fType->New(addr);
355  break;
356  case kBIT_ISSTRING:
357  for( i=nCurr; i<left; ++i, addr += fValDiff )
358  ::new(addr) std::string();
359  break;
360  case kIsPointer|kIsClass:
363  for( i=nCurr; i<left; ++i, addr += fValDiff )
364  *(void**)addr = 0;
365  break;
366  }
367  addr = ((char*)fEnv->fStart)+fValOffset+fValDiff*nCurr;
368  // DO NOT break; just continue
369 
370  // General case for all values
371  default:
372  switch(fVal->fCase) {
373  case kIsFundamental: // Only handle primitives this way
374  case kIsEnum:
375  break;
376  case kIsClass:
377  if (oldstart && oldstart != fEnv->fStart) {
378  Long_t offset = 0;
379  for( i=0; i<=nCurr; ++i, offset += fValDiff ) {
380  // For now 'Move' only register the change of location
381  // so per se this is wrong since the object are copied via memcpy
382  // rather than a copy (or move) constructor.
383  fVal->fType->Move(((char*)oldstart)+offset,((char*)fEnv->fStart)+offset);
384  }
385  }
386  for( i=nCurr; i<left; ++i, addr += fValDiff ) {
387  fVal->fType->New(addr);
388  }
389  break;
390  case kBIT_ISSTRING:
391  for( i=nCurr; i<left; ++i, addr += fValDiff )
392  ::new(addr) std::string();
393  break;
394  case kIsPointer|kIsClass:
397  for( i=nCurr; i<left; ++i, addr += fValDiff )
398  *(void**)addr = 0;
399  break;
400  }
401  break;
402  }
403 }
404 
406 {
407  // Resize the container
408 
409  if ( fEnv && fEnv->fObject ) {
410  size_t nCurr = Size();
412  fEnv->fStart = nCurr>0 ? &(*c->begin()) : 0;
413  if ( left == nCurr ) {
414  return;
415  }
416  else if ( left < nCurr ) {
417  Shrink(nCurr, left, force);
418  return;
419  }
420  Expand(nCurr, left);
421  return;
422  }
423  Fatal("TEmulatedCollectionProxy","Resize> Logic error - no proxy object set.");
424 }
425 
427 {
428  // Return the address of the value at index 'idx'
429  if ( fEnv && fEnv->fObject ) {
431  size_t s = c->size();
432  if ( idx >= (s/fValDiff) ) {
433  return 0;
434  }
435  return idx<(s/fValDiff) ? ((char*)&(*c->begin()))+idx*fValDiff : 0;
436  }
437  Fatal("TEmulatedCollectionProxy","At> Logic error - no proxy object set.");
438  return 0;
439 }
440 
442 {
443  // Allocate the necessary space.
444 
445  Resize(n, forceDelete);
446  return fEnv->fObject;
447 }
448 
449 ////////////////////////////////////////////////////////////////////////////////
450 /// Insert data into the container where data is a C-style array of the actual type contained in the collection
451 /// of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
452 
453 void TEmulatedCollectionProxy::Insert(const void * /* data */, void * /*container*/, size_t /*size*/)
454 {
455  Fatal("Insert","Not yet implemented, require copy of objects.");
456 }
457 
458 void TEmulatedCollectionProxy::Commit(void* /* env */ )
459 {
460 }
461 
463 {
464  // Object input streamer
465  Bool_t vsn3 = b.GetInfo() && b.GetInfo()->GetOldVersion()<=3;
466  StreamHelper* itm = (StreamHelper*)At(0);
467  switch (fVal->fCase) {
468  case kIsFundamental: // Only handle primitives this way
469  case kIsEnum:
470  switch( int(fVal->fKind) ) {
471  case kBool_t: b.ReadFastArray(&itm->boolean , nElements); break;
472  case kChar_t: b.ReadFastArray(&itm->s_char , nElements); break;
473  case kShort_t: b.ReadFastArray(&itm->s_short , nElements); break;
474  case kInt_t: b.ReadFastArray(&itm->s_int , nElements); break;
475  case kLong_t: b.ReadFastArray(&itm->s_long , nElements); break;
476  case kLong64_t: b.ReadFastArray(&itm->s_longlong, nElements); break;
477  case kFloat_t: b.ReadFastArray(&itm->flt , nElements); break;
478  case kFloat16_t: b.ReadFastArrayFloat16(&itm->flt, nElements); break;
479  case kDouble_t: b.ReadFastArray(&itm->dbl , nElements); break;
480  case kUChar_t: b.ReadFastArray(&itm->u_char , nElements); break;
481  case kUShort_t: b.ReadFastArray(&itm->u_short , nElements); break;
482  case kUInt_t: b.ReadFastArray(&itm->u_int , nElements); break;
483  case kULong_t: b.ReadFastArray(&itm->u_long , nElements); break;
484  case kULong64_t: b.ReadFastArray(&itm->u_longlong, nElements); break;
485  case kDouble32_t:b.ReadFastArrayDouble32(&itm->dbl,nElements); break;
486  case kchar:
487  case kNoType_t:
488  case kOther_t:
489  Error("TEmulatedCollectionProxy","fType %d is not supported yet!\n",fVal->fKind);
490  }
491  break;
492 
493 #define DOLOOP(x) {int idx=0; while(idx<nElements) {StreamHelper* i=(StreamHelper*)(((char*)itm) + fValDiff*idx); { x ;} ++idx;} break;}
494 
495  case kIsClass:
496  DOLOOP( b.StreamObject(i,fVal->fType) );
497  case kBIT_ISSTRING:
498  DOLOOP( i->read_std_string(b) );
499  case kIsPointer|kIsClass:
500  DOLOOP( i->read_any_object(fVal,b) );
502  DOLOOP( i->read_std_string_pointer(b) );
504  DOLOOP( i->read_tstring_pointer(vsn3,b) );
505  }
506 
507 #undef DOLOOP
508 
509 }
510 
512 {
513  // Object output streamer
514  StreamHelper* itm = (StreamHelper*)At(0);
515  switch (fVal->fCase) {
516  case kIsFundamental: // Only handle primitives this way
517  case kIsEnum:
518  itm = (StreamHelper*)At(0);
519  switch( int(fVal->fKind) ) {
520  case kBool_t: b.WriteFastArray(&itm->boolean , nElements); break;
521  case kChar_t: b.WriteFastArray(&itm->s_char , nElements); break;
522  case kShort_t: b.WriteFastArray(&itm->s_short , nElements); break;
523  case kInt_t: b.WriteFastArray(&itm->s_int , nElements); break;
524  case kLong_t: b.WriteFastArray(&itm->s_long , nElements); break;
525  case kLong64_t: b.WriteFastArray(&itm->s_longlong, nElements); break;
526  case kFloat_t: b.WriteFastArray(&itm->flt , nElements); break;
527  case kFloat16_t: b.WriteFastArrayFloat16(&itm->flt, nElements); break;
528  case kDouble_t: b.WriteFastArray(&itm->dbl , nElements); break;
529  case kUChar_t: b.WriteFastArray(&itm->u_char , nElements); break;
530  case kUShort_t: b.WriteFastArray(&itm->u_short , nElements); break;
531  case kUInt_t: b.WriteFastArray(&itm->u_int , nElements); break;
532  case kULong_t: b.WriteFastArray(&itm->u_long , nElements); break;
533  case kULong64_t: b.WriteFastArray(&itm->u_longlong, nElements); break;
534  case kDouble32_t:b.WriteFastArrayDouble32(&itm->dbl,nElements); break;
535  case kchar:
536  case kNoType_t:
537  case kOther_t:
538  Error("TEmulatedCollectionProxy","fType %d is not supported yet!\n",fVal->fKind);
539  }
540  break;
541 #define DOLOOP(x) {int idx=0; while(idx<nElements) {StreamHelper* i=(StreamHelper*)(((char*)itm) + fValDiff*idx); { x ;} ++idx;} break;}
542  case kIsClass:
543  DOLOOP( b.StreamObject(i,fVal->fType) );
544  case kBIT_ISSTRING:
545  DOLOOP( TString(i->c_str()).Streamer(b) );
546  case kIsPointer|kIsClass:
547  DOLOOP( b.WriteObjectAny(i->ptr(),fVal->fType) );
549  DOLOOP( i->write_std_string_pointer(b) );
551  DOLOOP( i->write_tstring_pointer(b) );
552  }
553 #undef DOLOOP
554 }
555 
556 void TEmulatedCollectionProxy::ReadBuffer(TBuffer &b, void *obj, const TClass *onfileClass)
557 {
558  // Read portion of the streamer.
559 
560  SetOnFileClass((TClass*)onfileClass);
561  ReadBuffer(b,obj);
562 }
563 
565 {
566  // Read portion of the streamer.
567 
568  TPushPop env(this,obj);
569  int nElements = 0;
570  b >> nElements;
571  if ( fEnv->fObject ) {
572  Resize(nElements,true);
573  }
574  if ( nElements > 0 ) {
575  ReadItems(nElements, b);
576  }
577 }
578 
580 {
581  // TClassStreamer IO overload
582  if ( b.IsReading() ) { //Read mode
583  int nElements = 0;
584  b >> nElements;
585  if ( fEnv->fObject ) {
586  Resize(nElements,true);
587  }
588  if ( nElements > 0 ) {
589  ReadItems(nElements, b);
590  }
591  }
592  else { // Write case
593  int nElements = fEnv->fObject ? Size() : 0;
594  b << nElements;
595  if ( nElements > 0 ) {
596  WriteItems(nElements, b);
597  }
598  }
599 }
600 
601 //
602 // Utility functions
603 //
604 static TStreamerElement* R__CreateEmulatedElement(const char *dmName, const char *dmFull, Int_t offset)
605 {
606  // Create a TStreamerElement for the type 'dmFull' and whose data member name is 'dmName'.
607 
608  TString s1( TClassEdit::ShortType(dmFull,0) );
609  TString dmType( TClassEdit::ShortType(dmFull,1) );
610  Bool_t dmIsPtr = (s1 != dmType);
611  const char *dmTitle = "Emulation";
612 
613  TDataType *dt = gROOT->GetType(dmType);
614  if (dt && dt->GetType() > 0 ) { // found a basic type
615  Int_t dsize,dtype;
616  dtype = dt->GetType();
617  dsize = dt->Size();
618  if (dmIsPtr && dtype != kCharStar) {
619  Error("Pair Emulation Building","%s is not yet supported in pair emulation",
620  dmFull);
621  return 0;
622  } else {
623  TStreamerElement *el = new TStreamerBasicType(dmName,dmTitle,offset,dtype,dmFull);
624  el->SetSize(dsize);
625  return el;
626  }
627  } else {
628 
629  static const char *full_string_name = "basic_string<char,char_traits<char>,allocator<char> >";
630  if (strcmp(dmType,"string") == 0 || strcmp(dmType,"std::string") == 0 || strcmp(dmType,full_string_name)==0 ) {
631  return new TStreamerSTLstring(dmName,dmTitle,offset,dmFull,dmIsPtr);
632  }
633  if (TClassEdit::IsSTLCont(dmType)) {
634  return new TStreamerSTL(dmName,dmTitle,offset,dmFull,dmFull,dmIsPtr);
635  }
636  TClass *clm = TClass::GetClass(dmType);
637  if (!clm) {
638  // either we have an Emulated enum or a really unknown class!
639  // let's just claim its an enum :(
640  Int_t dtype = kInt_t;
641  return new TStreamerBasicType(dmName,dmTitle,offset,dtype,dmFull);
642  }
643  // a pointer to a class
644  if ( dmIsPtr ) {
645  if (clm->IsTObject()) {
646  return new TStreamerObjectPointer(dmName,dmTitle,offset,dmFull);
647  } else {
648  return new TStreamerObjectAnyPointer(dmName,dmTitle,offset,dmFull);
649  }
650  }
651  // a class
652  if (clm->IsTObject()) {
653  return new TStreamerObject(dmName,dmTitle,offset,dmFull);
654  } else if(clm == TString::Class() && !dmIsPtr) {
655  return new TStreamerString(dmName,dmTitle,offset);
656  } else {
657  return new TStreamerObjectAny(dmName,dmTitle,offset,dmFull);
658  }
659  }
660 }
661 
662 
663 static TStreamerInfo *R__GenerateTClassForPair(const std::string &fname, const std::string &sname)
664 {
665  // Generate a TStreamerInfo for a std::pair<fname,sname>
666  // This TStreamerInfo is then used as if it was read from a file to generate
667  // and emulated TClass.
668 
669  TStreamerInfo *i = (TStreamerInfo*)TClass::GetClass("pair<const int,int>")->GetStreamerInfo()->Clone();
670  std::string pname = "pair<"+fname+","+sname;
671  pname += (pname[pname.length()-1]=='>') ? " >" : ">";
672  i->SetName(pname.c_str());
673  i->SetClass(0);
674  i->GetElements()->Delete();
675  TStreamerElement *fel = R__CreateEmulatedElement("first", fname.c_str(), 0);
676  Int_t size = 0;
677  if (fel) {
678  i->GetElements()->Add( fel );
679 
680  size = fel->GetSize();
681  Int_t sp = sizeof(void *);
682  //align the non-basic data types (required on alpha and IRIX!!)
683  if (size%sp != 0) size = size - size%sp + sp;
684  } else {
685  delete i;
686  return 0;
687  }
688  TStreamerElement *second = R__CreateEmulatedElement("second", sname.c_str(), size);
689  if (second) {
690  i->GetElements()->Add( second );
691  } else {
692  delete i;
693  return 0;
694  }
695  Int_t oldlevel = gErrorIgnoreLevel;
696  // Hide the warning about the missing pair dictionary.
698  i->BuildCheck();
699  gErrorIgnoreLevel = oldlevel;
700  i->BuildOld();
701  return i;
702 }
virtual UInt_t Size() const
Return the current size of the container.
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
void Expand(UInt_t nCurr, UInt_t left)
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual void WriteFastArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=0)=0
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
UInt_t fProperties
Additional properties of the value type (kNeedDelete)
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
void Fatal(const char *location, const char *msgfmt,...)
virtual void SetSize(Int_t dsize)
Bool_t fPointers
Flag to indicate if containee has pointers (key or value)
return c
std::string fName
Name of the class being proxied.
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:329
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.
Definition: TClassEdit.cxx:938
static TStreamerElement * R__CreateEmulatedElement(const char *dmName, const char *dmFull, Int_t offset)
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass)=0
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
TH1 * h
Definition: legend2.C:5
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist...
Definition: TClass.cxx:4368
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
#define DOLOOP(x)
const char * Class
Definition: TXMLSetup.cxx:64
UInt_t fCase
type of data of Value_type
Streamer around an arbitrary STL like container, which implements basic container functionality...
virtual TVirtualStreamerInfo * GetInfo()=0
size_t fSize
fSize of the contained object
void Move(void *arenaFrom, void *arenaTo) const
Register the fact that an object was moved from the memory location &#39;arenaFrom&#39; to the memory locatio...
Definition: TClass.cxx:4092
TEmulatedCollectionProxy(const TEmulatedCollectionProxy &copy)
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
Definition: TClassEdit.cxx:468
void SetClass(TClass *cl)
virtual void * Allocate(UInt_t n, Bool_t forceDelete)
Allocate the needed space.
Method0 fCreateEnv
Method to allocate an Environment holder.
void Error(const char *location, const char *msgfmt,...)
EDataType fKind
kind of ROOT-fundamental type
virtual void Resize(UInt_t n, Bool_t force_delete)
Resize the container.
Int_t GetType() const
Definition: TDataType.h:70
int fValOffset
Offset from key to value (in maps)
TGenCollectionProxy * Initialize(Bool_t silent) const
Proxy initializer.
virtual TVirtualCollectionProxy * Generate() const
Virtual copy constructor.
void BuildOld()
rebuild the TStreamerInfo structure
virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=0)=0
int fSTL_type
STL container type.
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:46
virtual void Clear(const char *opt="")
Clear the emulated collection.
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition: TClass.cxx:5071
virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=0)=0
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual TGenCollectionProxy * InitializeEx(Bool_t silent)
Proxy initializer.
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
const std::string sname
Definition: testIO.cxx:45
void Warning(const char *location, const char *msgfmt,...)
void WriteItems(int nElements, TBuffer &b)
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
int fValDiff
Offset between two consecutive value_types (memory layout).
#define R__LOCKGUARD2(mutex)
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
long Long_t
Definition: RtypesCore.h:50
virtual void Commit(void *env)
Commit the change.
double f(double x)
virtual Int_t GetSize() const
Returns size of this element in bytes.
virtual void Insert(const void *data, void *container, size_t size)
Insert data into the container where data is a C-style array of the actual type contained in the coll...
void Shrink(UInt_t nCurr, UInt_t left, Bool_t force)
virtual Version_t GetOldVersion() const =0
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.
Definition: TClass.cxx:2893
std::atomic< Value * > fValue
Descriptor of the container value type.
TClassRef fType
TClass reference of Value_type in collection.
virtual void SetOnFileClass(TClass *cl)
static TStreamerInfo * R__GenerateTClassForPair(const std::string &f, const std::string &s)
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:65
TObjArray * GetElements() const
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition: TClass.cxx:5583
Value * fKey
Descriptor of the key_type.
void ReadItems(int nElements, TBuffer &b)
void BuildCheck(TFile *file=0)
Check if built and consistent with the class dictionary.
virtual void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const
Helper class to facilitate I/O.
Proxy around an arbitrary container, which implements basic functionality and iteration.
Int_t Size() const
Get size of basic typedef&#39;ed type.
Definition: TDataType.cxx:366
EnvironBase_t * fEnv
Address of the currently proxied object.
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
const Int_t kError
Definition: TError.h:41
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual void * At(UInt_t idx)
Return the address of the value at index &#39;idx&#39;.
Bool_t IsValid()
Return true if the Value has been properly initialized.
void Add(TObject *obj)
Definition: TObjArray.h:75
virtual void ReadBuffer(TBuffer &buff, void *pObj)
Info_t fTypeinfo
Type information.
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0)=0
const char * Value
Definition: TXMLSetup.cxx:73
Value * fVal
Descriptor of the Value_type.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4714