Logo ROOT   6.08/02
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TGenCollectionProxy.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-2004, 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 #include "TGenCollectionProxy.h"
13 #include "TVirtualStreamerInfo.h"
14 #include "TStreamerElement.h"
15 #include "TClassEdit.h"
16 #include "TClass.h"
17 #include "TError.h"
18 #include "TROOT.h"
19 #include "TInterpreter.h"
20 #include "Riostream.h"
21 #include "TVirtualMutex.h"
22 #include "TStreamerInfoActions.h"
23 #include "THashTable.h"
24 #include "THashList.h"
25 #include <stdlib.h>
26 
27 #include "TInterpreter.h" // For gInterpreterMutex
28 
29 #define MESSAGE(which,text)
30 
31 /**
32 \class TGenVectorProxy
33 \ingroup IO
34 Local optimization class.
35 
36 Collection proxies get copied. On copy we switch the type of the
37 proxy to the concrete STL type. The concrete types are optimized
38 for element access.
39 */
40 
41 class TGenVectorProxy : public TGenCollectionProxy {
42 public:
43  // Standard Destructor
44  TGenVectorProxy(const TGenCollectionProxy& c) : TGenCollectionProxy(c)
45  {
46  }
47  // Standard Destructor
48  virtual ~TGenVectorProxy()
49 {
50  }
51  // Return the address of the value at index 'idx'
52  virtual void* At(UInt_t idx)
53 {
54  if ( fEnv && fEnv->fObject ) {
55  fEnv->fIdx = idx;
56  switch( idx ) {
57  case 0:
58  return fEnv->fStart = fFirst.invoke(fEnv);
59  default:
60  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
61  return ((char*)fEnv->fStart) + fValDiff*idx;
62  }
63  }
64  Fatal("TGenVectorProxy","At> Logic error - no proxy object set.");
65  return 0;
66  }
67  // Call to delete/destruct individual item
68  virtual void DeleteItem(Bool_t force, void* ptr) const
69  {
70  if ( force && ptr ) {
71  if ( fVal->fProperties&kNeedDelete) {
73  TPushPop helper(proxy,ptr);
74  proxy->Clear("force");
75  }
76  fVal->DeleteItem(ptr);
77  }
78  }
79 };
80 
81 /**
82 \class TGenVectorBoolProxy
83 \ingroup IO
84 Local optimization class.
85 
86 Collection proxies get copied. On copy we switch the type of the
87 proxy to the concrete STL type. The concrete types are optimized
88 for element access.
89 */
90 class TGenVectorBoolProxy : public TGenCollectionProxy {
91  Bool_t fLastValue;
92 
93 public:
94  TGenVectorBoolProxy(const TGenCollectionProxy& c) : TGenCollectionProxy(c), fLastValue(false)
95  {
96  // Standard Constructor.
97  }
98  virtual ~TGenVectorBoolProxy()
99  {
100  // Standard Destructor.
101  }
102  virtual void* At(UInt_t idx)
103  {
104  // Return the address of the value at index 'idx'
105 
106  // However we can 'take' the address of the content of std::vector<bool>.
107  if ( fEnv && fEnv->fObject ) {
108  switch( idx ) {
109  case 0:
110  fEnv->fStart = fFirst.invoke(fEnv);
111  fEnv->fIdx = idx;
112  break;
113  default:
114  fEnv->fIdx = idx - fEnv->fIdx;
115  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
116  fNext.invoke(fEnv);
117  fEnv->fIdx = idx;
118  break;
119  }
120  typedef ROOT::TCollectionProxyInfo::Type<std::vector<Bool_t> >::Env_t EnvType_t;
121  EnvType_t *e = (EnvType_t*)fEnv;
122  fLastValue = *(e->iter());
123  return &fLastValue;
124  }
125  Fatal("TGenVectorProxy","At> Logic error - no proxy object set.");
126  return 0;
127  }
128 
129  virtual void DeleteItem(Bool_t force, void* ptr) const
130  {
131  // Call to delete/destruct individual item
132  if ( force && ptr ) {
133  fVal->DeleteItem(ptr);
134  }
135  }
136 };
137 
138 //////////////////////////////////////////////////////////////////////////
139 // //
140 // class TGenBitsetProxy
141 //
142 // Local optimization class.
143 //
144 // Collection proxies get copied. On copy we switch the type of the
145 // proxy to the concrete STL type. The concrete types are optimized
146 // for element access.
147 //
148 //////////////////////////////////////////////////////////////////////////
149 class TGenBitsetProxy : public TGenCollectionProxy {
150 
151 public:
152  TGenBitsetProxy(const TGenCollectionProxy& c) : TGenCollectionProxy(c)
153  {
154  // Standard Constructor.
155  }
156  virtual ~TGenBitsetProxy()
157  {
158  // Standard Destructor.
159  }
160  virtual void* At(UInt_t idx)
161  {
162  // Return the address of the value at index 'idx'
163 
164  // However we can 'take' the address of the content of std::vector<bool>.
165  if ( fEnv && fEnv->fObject ) {
166  switch( idx ) {
167  case 0:
168  fEnv->fStart = fFirst.invoke(fEnv);
169  fEnv->fIdx = idx;
170  break;
171  default:
172  fEnv->fIdx = idx - fEnv->fIdx;
173  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
174  fNext.invoke(fEnv);
175  fEnv->fIdx = idx;
176  break;
177  }
178  typedef ROOT::TCollectionProxyInfo::Environ<std::pair<size_t,Bool_t> > EnvType_t;
179  EnvType_t *e = (EnvType_t*)fEnv;
180  return &(e->fIterator.second);
181  }
182  Fatal("TGenVectorProxy","At> Logic error - no proxy object set.");
183  return 0;
184  }
185 
186  virtual void DeleteItem(Bool_t force, void* ptr) const
187  {
188  // Call to delete/destruct individual item
189  if ( force && ptr ) {
190  fVal->DeleteItem(ptr);
191  }
192  }
193 };
194 
195 /*
196 \class TGenListProxy
197 \ingroup IO
198 Local optimization class.
199 
200 Collection proxies get copied. On copy we switch the type of the
201 proxy to the concrete STL type. The concrete types are optimized
202 for element access.
203 **/
204 
205 class TGenListProxy : public TGenVectorProxy {
206 public:
207  // Standard Destructor
208  TGenListProxy(const TGenCollectionProxy& c) : TGenVectorProxy(c)
209 {
210  }
211  // Standard Destructor
212  virtual ~TGenListProxy()
213 {
214  }
215  // Return the address of the value at index 'idx'
216  void* At(UInt_t idx)
217 {
218  if ( fEnv && fEnv->fObject ) {
219  switch( idx ) {
220  case 0:
221  fEnv->fIdx = idx;
222  return fEnv->fStart = fFirst.invoke(fEnv);
223  default: {
224  fEnv->fIdx = idx - fEnv->fIdx;
225  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
226  void* result = fNext.invoke(fEnv);
227  fEnv->fIdx = idx;
228  return result;
229  }
230  }
231  }
232  Fatal("TGenListProxy","At> Logic error - no proxy object set.");
233  return 0;
234  }
235 };
236 
237 /**
238 \class TGenSetProxy
239 \ingroup IO
240 Localoptimization class.
241 
242 Collection proxies get copied. On copy we switch the type of the
243 proxy to the concrete STL type. The concrete types are optimized
244 for element access.
245 */
246 
247 class TGenSetProxy : public TGenVectorProxy {
248 public:
249  // Standard Destructor
250  TGenSetProxy(const TGenCollectionProxy& c) : TGenVectorProxy(c)
251 {
252  }
253  // Standard Destructor
254  virtual ~TGenSetProxy()
255 {
256  }
257  // Return the address of the value at index 'idx'
258  void* At(UInt_t idx)
259 {
260  if ( fEnv && fEnv->fObject ) {
261  if ( fEnv->fUseTemp ) {
262  return (((char*)fEnv->fTemp)+idx*fValDiff);
263  }
264  switch( idx ) {
265  case 0:
266  fEnv->fIdx = idx;
267  return fEnv->fStart = fFirst.invoke(fEnv);
268  default: {
269  fEnv->fIdx = idx - fEnv->fIdx;
270  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
271  void* result = fNext.invoke(fEnv);
272  fEnv->fIdx = idx;
273  return result;
274  }
275  }
276  }
277  Fatal("TGenSetProxy","At> Logic error - no proxy object set.");
278  return 0;
279  }
280 };
281 
282 /**
283 \class TGenMapProxy
284 \ingroup IO
285 Localoptimization class.
286 
287 Collection proxies get copied. On copy we switch the type of the
288 proxy to the concrete STL type. The concrete types are optimized
289 for element access.
290 */
291 
292 class TGenMapProxy : public TGenSetProxy {
293 public:
294  // Standard Destructor
295  TGenMapProxy(const TGenCollectionProxy& c) : TGenSetProxy(c)
296 {
297  }
298  // Standard Destructor
299  virtual ~TGenMapProxy()
300 {
301  }
302  // Call to delete/destruct individual item
303  virtual void DeleteItem(Bool_t force, void* ptr) const
304  {
305  if (force) {
306  if ( fKey->fProperties&kNeedDelete) {
308  TPushPop helper(proxy,fKey->fCase&kIsPointer ? *(void**)ptr : ptr);
309  proxy->Clear("force");
310  }
311  if ( fVal->fProperties&kNeedDelete) {
313  char *addr = ((char*)ptr)+fValOffset;
314  TPushPop helper(proxy,fVal->fCase&kIsPointer ? *(void**)addr : addr);
315  proxy->Clear("force");
316  }
317  }
318  if ( fKey->fCase&kIsPointer ) {
319  fKey->DeleteItem(*(void**)ptr);
320  }
321  if ( fVal->fCase&kIsPointer ) {
322  char *addr = ((char*)ptr)+fValOffset;
323  fVal->DeleteItem(*(void**)addr);
324  }
325  }
326 };
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 /// Constructor.
330 
331 TGenCollectionProxy::Value::Value(const std::string& inside_type, Bool_t silent)
332 {
333  std::string inside = (inside_type.find("const ")==0) ? inside_type.substr(6) : inside_type;
334  fCase = 0;
335  fProperties = 0;
336  fCtor = 0;
337  fDtor = 0;
338  fDelete = 0;
339  fSize = std::string::npos;
340  fKind = kNoType_t;
341  std::string intype = TClassEdit::ShortType(inside.c_str(),TClassEdit::kDropTrailStar );
342  if ( inside.substr(0,6) == "string" || inside.substr(0,11) == "std::string" ) {
344  fType = TClass::GetClass("string");
345  fCtor = fType->GetNew();
347  fDelete = fType->GetDelete();
348  switch(inside[inside.length()-1]) {
349  case '*':
350  fCase |= kIsPointer;
351  fSize = sizeof(void*);
352  break;
353  default:
354  fSize = sizeof(std::string);
355  break;
356  }
357  }
358  else {
359  // In the case where we have an emulated class,
360  // if the class is nested (in a class or a namespace),
361  // calling G__TypeInfo ti(inside.c_str());
362  // might fail because CINT does not known the nesting
363  // scope, so let's first look for an emulated class:
364 
365  fType = TClass::GetClass(intype.c_str(),kTRUE,silent);
366 
367  if (fType) {
368  if (intype != inside) {
369  fCase |= kIsPointer;
370  fSize = sizeof(void*);
371  if (fType == TString::Class()) {
373  }
374  }
375  fCase |= kIsClass;
376  fCtor = fType->GetNew();
378  fDelete = fType->GetDelete();
379  } else {
381 
382  // Try to avoid autoparsing.
383 
384  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
385  THashList *enumTable = dynamic_cast<THashList*>( gROOT->GetListOfEnums() );
386 
387  assert(typeTable && "The type of the list of type has changed");
388  assert(enumTable && "The type of the list of enum has changed");
389 
390  TDataType *fundType = (TDataType *)typeTable->THashTable::FindObject( intype.c_str() );
391  if (fundType && fundType->GetType() < 0x17 && fundType->GetType() > 0) {
392  fKind = (EDataType)fundType->GetType();
393  if ( 0 == strcmp("bool",fundType->GetFullTypeName()) ) {
395  }
396  // R__ASSERT((fKind>0 && fKind<0x17) || (fKind==-1&&(prop&kIsPointer)) );
397 
399  if (intype != inside) {
400  fCase |= kIsPointer;
401  fSize = sizeof(void*);
402  } else {
403  fSize = fundType->Size();
404  }
405  } else if (enumTable->THashList::FindObject( intype.c_str() ) ) {
406  // This is a known enum.
407  fCase = kIsEnum;
408  fSize = sizeof(Int_t);
409  fKind = kInt_t;
410  if (intype != inside) {
411  fCase |= kIsPointer;
412  fSize = sizeof(void*);
413  }
414  } else {
415  // This fallback solution should be hardly used ...
416  // One of the common use case is to 'discover' that this is a
417  // collection for the content of which we do not have a dictionary
418  // which can happen at least in the following cases:
419  // - empty emulated collection
420  // - emulated collection of enums
421  // In those two cases there is no StreamerInfo stored in the file
422  // for the content.
423 
424  // R__ASSERT("FallBack, should be hardly used.");
425 
426  TypeInfo_t *ti = gCling->TypeInfo_Factory();
427  gCling->TypeInfo_Init(ti,inside.c_str());
428  if ( !gCling->TypeInfo_IsValid(ti) ) {
429  if (intype != inside) {
430  fCase |= kIsPointer;
431  fSize = sizeof(void*);
432  }
433  // Since we already search for GetClass earlier, this should
434  // never be true.
435 // fType = TClass::GetClass(intype.c_str(),kTRUE,silent);
436 // if (fType) {
437 // fCase |= kIsClass;
438 // fCtor = fType->GetNew();
439 // fDtor = fType->GetDestructor();
440 // fDelete = fType->GetDelete();
441 // }
442 // else {
443  // either we have an Emulated enum or a really unknown class!
444  // let's just claim its an enum :(
445  fCase = kIsEnum;
446  fSize = sizeof(Int_t);
447  fKind = kInt_t;
448 // }
449  }
450  else {
451  Long_t prop = gCling->TypeInfo_Property(ti);
452  if ( prop&kIsPointer ) {
453  fSize = sizeof(void*);
454  }
455  if ( prop&kIsStruct ) {
456  prop |= kIsClass;
457  }
458  // Since we already searched GetClass earlier, this should
459  // never be true.
460  R__ASSERT(! (prop&kIsClass) && "Impossible code path" );
461 // if ( prop&kIsClass ) {
462 // fType = TClass::GetClass(intype.c_str(),kTRUE,silent);
463 // R__ASSERT(fType);
464 // fCtor = fType->GetNew();
465 // fDtor = fType->GetDestructor();
466 // fDelete = fType->GetDelete();
467 // }
468 // else
469  if ( prop&kIsFundamental ) {
470  fundType = gROOT->GetType( intype.c_str() );
471  if (fundType==0) {
472  if (intype != "long double") {
473  Error("TGenCollectionProxy","Unknown fundamental type %s",intype.c_str());
474  }
475  fSize = sizeof(int);
476  fKind = kInt_t;
477  } else {
478  fKind = (EDataType)fundType->GetType();
479  if ( 0 == strcmp("bool",fundType->GetFullTypeName()) ) {
481  }
482  fSize = gCling->TypeInfo_Size(ti);
483  R__ASSERT((fKind>0 && fKind<0x17) || (fKind==-1&&(prop&kIsPointer)) );
484  }
485  }
486  else if ( prop&kIsEnum ) {
487  fSize = sizeof(int);
488  fKind = kInt_t;
489  }
490  fCase = prop & (kIsPointer|kIsFundamental|kIsEnum|kIsClass);
491  if (fType == TString::Class() && (fCase&kIsPointer)) {
493  }
494  }
495  gCling->TypeInfo_Delete(ti);
496  }
497  }
498  if (fType) {
500  if (proxy && (proxy->GetProperties() & kNeedDelete)) {
502  }
503  }
504  }
505  if ( fSize == std::string::npos ) {
506  if ( fType == 0 ) {
507  // The caller should check the validity by calling IsValid()
508  } else {
509  fSize = fType->Size();
510  }
511  }
512 }
513 
514 ////////////////////////////////////////////////////////////////////////////////
515 /// Return true if the Value has been properly initialized.
516 
518 {
519 
520 
521  return fSize != std::string::npos;
522 }
523 
525 {
526  // Delete an item.
527 
528  if ( ptr && fCase&kIsPointer ) {
529  if ( fDelete ) {
530  (*fDelete)(ptr);
531  }
532  else if ( fType ) {
533  fType->Destructor(ptr);
534  }
535  else {
536  ::operator delete(ptr);
537  }
538  }
539 }
540 
541 /**
542  \class TGenCollectionProxy TGenCollectionProxy.cxx
543  \ingroup IO
544 
545  Proxy around an arbitrary container, which implements basic
546  functionality and iteration.
547 
548  The purpose of this implementation
549  is to shield any generated dictionary implementation from the
550  underlying streamer/proxy implementation and only expose
551  the creation functions.
552 
553  In particular this is used to implement splitting and abstract
554  element access of any container. Access to compiled code is necessary
555  to implement the abstract iteration sequence and functionality like
556  size(), clear(), resize(). resize() may be a void operation.
557 */
558 
559 ////////////////////////////////////////////////////////////////////////////////
560 /// Build a proxy for an emulated container.
561 
564  fTypeinfo(copy.fTypeinfo)
565 {
566  fEnv = 0;
567  fName = copy.fName;
568  fPointers = copy.fPointers;
569  fSTL_type = copy.fSTL_type;
570  fSize.call = copy.fSize.call;
571  fNext.call = copy.fNext.call;
572  fFirst.call = copy.fFirst.call;
573  fClear.call = copy.fClear.call;
574  fResize = copy.fResize;
575  fDestruct = copy.fDestruct;
576  fConstruct = copy.fConstruct;
577  fFeed = copy.fFeed;
578  fCollect = copy.fCollect;
580  fValOffset = copy.fValOffset;
581  fValDiff = copy.fValDiff;
582  fValue = copy.fValue.load() ? new Value(*copy.fValue) : 0;
583  fVal = copy.fVal ? new Value(*copy.fVal) : 0;
584  fKey = copy.fKey ? new Value(*copy.fKey) : 0;
585  fOnFileClass = copy.fOnFileClass;
588  fWriteMemberWise = 0;
589  fProperties = copy.fProperties;
595 }
596 
597 ////////////////////////////////////////////////////////////////////////////////
598 /// Build a proxy for a collection whose type is described by 'collectionClass'.
599 
602  fTypeinfo(info)
603 {
604  fEnv = 0;
605  fSize.call = 0;
606  fFirst.call = 0;
607  fNext.call = 0;
608  fClear.call = 0;
609  fResize = 0;
610  fDestruct = 0;
611  fConstruct = 0;
612  fCollect = 0;
613  fCreateEnv.call = 0;
614  fFeed = 0;
615  fValue = 0;
616  fKey = 0;
617  fVal = 0;
618  fValOffset = 0;
619  fValDiff = 0;
620  fPointers = false;
621  fOnFileClass = 0;
623  Env_t e;
624  if ( iter_size > sizeof(e.fIterator) ) {
625  Fatal("TGenCollectionProxy",
626  "%s %s are too large:%ld bytes. Maximum is:%ld bytes",
627  "Iterators for collection",
628  fClass->GetName(),
629  (Long_t)iter_size,
630  (Long_t)sizeof(e.fIterator));
631  }
634  fWriteMemberWise = 0;
640 }
641 
642 ////////////////////////////////////////////////////////////////////////////////
643 /// Build a proxy for a collection whose type is described by 'collectionClass'.
644 
647  fTypeinfo(info.fInfo), fOnFileClass(0)
648 {
649  fEnv = 0;
650  fValDiff = info.fValueDiff;
651  fValOffset = info.fValueOffset;
652  fSize.call = info.fSizeFunc;
653  fResize = info.fResizeFunc;
654  fNext.call = info.fNextFunc;
655  fFirst.call = info.fFirstFunc;
656  fClear.call = info.fClearFunc;
657  fConstruct = info.fConstructFunc;
658  fDestruct = info.fDestructFunc;
659  fFeed = info.fFeedFunc;
660  fCollect = info.fCollectFunc;
661  fCreateEnv.call = info.fCreateEnv;
662 
663  if (cl) {
664  fName = cl->GetName();
665  }
666  CheckFunctions();
667 
668  fValue = 0;
669  fKey = 0;
670  fVal = 0;
671  fPointers = false;
673 
674  Env_t e;
675  if ( info.fIterSize > sizeof(e.fIterator) ) {
676  Fatal("TGenCollectionProxy",
677  "%s %s are too large:%ld bytes. Maximum is:%ld bytes",
678  "Iterators for collection",
679  fClass->GetName(),
680  (Long_t)info.fIterSize,
681  (Long_t)sizeof(e.fIterator));
682  }
685  fWriteMemberWise = 0;
691 }
692 
693 namespace {
694  template <class vec>
695  void clearVector(vec& v)
696  {
697  // Clear out the proxies.
698 
699  for(typename vec::iterator i=v.begin(); i != v.end(); ++i) {
700  typename vec::value_type e = *i;
701  if ( e ) {
702  delete e;
703  }
704  }
705  v.clear();
706  }
707 }
708 ////////////////////////////////////////////////////////////////////////////////
709 /// Standard destructor
710 
712 {
713  clearVector(fProxyList);
714  clearVector(fProxyKept);
715  clearVector(fStaged);
716 
717  if ( fValue.load() ) delete fValue.load();
718  if ( fVal ) delete fVal;
719  if ( fKey ) delete fKey;
720 
721  delete fReadMemberWise;
723  std::map<std::string, TObjArray*>::iterator it;
724  std::map<std::string, TObjArray*>::iterator end = fConversionReadMemberWise->end();
725  for( it = fConversionReadMemberWise->begin(); it != end; ++it ) {
726  delete it->second;
727  }
730  }
731  delete fWriteMemberWise;
732 }
733 
734 ////////////////////////////////////////////////////////////////////////////////
735 /// Virtual copy constructor
736 
738 {
739  if ( !fValue.load() ) Initialize(kFALSE);
740 
741  if( fPointers )
742  return new TGenCollectionProxy(*this);
743 
744  switch(fSTL_type) {
745  case ROOT::kSTLbitset: {
746  return new TGenBitsetProxy(*this);
747  }
748  case ROOT::kSTLvector: {
749  if ((*fValue).fKind == (EDataType)kBOOL_t) {
750  return new TGenVectorBoolProxy(*this);
751  } else {
752  return new TGenVectorProxy(*this);
753  }
754  }
755  case ROOT::kSTLlist:
757  return new TGenListProxy(*this);
758  case ROOT::kSTLmap:
760  case ROOT::kSTLmultimap:
762  return new TGenMapProxy(*this);
763  case ROOT::kSTLset:
765  case ROOT::kSTLmultiset:
767  return new TGenSetProxy(*this);
768  default:
769  return new TGenCollectionProxy(*this);
770  }
771 }
772 
773 ////////////////////////////////////////////////////////////////////////////////
774 /// Proxy initializer
775 
777 {
778  TGenCollectionProxy* p = const_cast<TGenCollectionProxy*>(this);
779  if ( fValue.load() ) return p;
780  return p->InitializeEx(silent);
781 }
782 
783 ////////////////////////////////////////////////////////////////////////////////
784 /// Check existence of function pointers
785 
787 {
788  if ( 0 == fSize.call ) {
789  Fatal("TGenCollectionProxy","No 'size' function pointer for class %s present.",fName.c_str());
790  }
791  if ( 0 == fResize ) {
792  Fatal("TGenCollectionProxy","No 'resize' function for class %s present.",fName.c_str());
793  }
794  if ( 0 == fNext.call ) {
795  Fatal("TGenCollectionProxy","No 'next' function for class %s present.",fName.c_str());
796  }
797  if ( 0 == fFirst.call ) {
798  Fatal("TGenCollectionProxy","No 'begin' function for class %s present.",fName.c_str());
799  }
800  if ( 0 == fClear.call ) {
801  Fatal("TGenCollectionProxy","No 'clear' function for class %s present.",fName.c_str());
802  }
803  if ( 0 == fConstruct ) {
804  Fatal("TGenCollectionProxy","No 'block constructor' function for class %s present.",fName.c_str());
805  }
806  if ( 0 == fDestruct ) {
807  Fatal("TGenCollectionProxy","No 'block destructor' function for class %s present.",fName.c_str());
808  }
809  if ( 0 == fFeed ) {
810  Fatal("TGenCollectionProxy","No 'data feed' function for class %s present.",fName.c_str());
811  }
812  if ( 0 == fCollect ) {
813  Fatal("TGenCollectionProxy","No 'data collect' function for class %s present.",fName.c_str());
814  }
815  if (0 == fCreateEnv.call ) {
816  Fatal("TGenCollectionProxy","No 'environment creation' function for class %s present.",fName.c_str());
817  }
818 }
819 
820 ////////////////////////////////////////////////////////////////////////////////
821 /// Utility routine to issue a Fatal error is the Value object is not valid
822 
823 static TGenCollectionProxy::Value *R__CreateValue(const std::string &name, Bool_t silent)
824 {
825  TGenCollectionProxy::Value *val = new TGenCollectionProxy::Value( name, silent );
826  if ( !val->IsValid() ) {
827  Fatal("TGenCollectionProxy","Could not find %s!",name.c_str());
828  }
829  return val;
830 }
831 
832 ////////////////////////////////////////////////////////////////////////////////
833 /// Proxy initializer
834 
836 {
838  if (fValue.load()) return this;
839 
841  if ( cl ) {
842  fEnv = 0;
843  fName = cl->GetName();
844  fPointers = false;
845  int nested = 0;
846  std::vector<std::string> inside;
847  int num = TClassEdit::GetSplit(cl->GetName(),inside,nested);
848  if ( num > 1 ) {
849  std::string nam;
850  Value* newfValue = nullptr;
851  if ( inside[0].find("stdext::hash_") != std::string::npos )
852  inside[0].replace(3,10,"::");
853  if ( inside[0].find("__gnu_cxx::hash_") != std::string::npos )
854  inside[0].replace(0,16,"std::");
855  fSTL_type = TClassEdit::STLKind(inside[0].c_str());
856  switch ( fSTL_type ) {
857  case ROOT::kSTLmap:
859  case ROOT::kSTLmultimap:
861  case ROOT::kSTLset:
863  case ROOT::kSTLmultiset:
865  case ROOT::kSTLbitset: // not really an associate container but it has no real iterator.
867  break;
868  };
869 
870  int slong = sizeof(void*);
871  switch ( fSTL_type ) {
872  case ROOT::kSTLmap:
874  case ROOT::kSTLmultimap:
876  nam = "pair<"+inside[1]+","+inside[2];
877  nam += (nam[nam.length()-1]=='>') ? " >" : ">";
878  newfValue = R__CreateValue(nam, silent);
879 
880  fVal = R__CreateValue(inside[2], silent);
881  fKey = R__CreateValue(inside[1], silent);
882  fPointers = (0 != (fKey->fCase&kIsPointer));
883  if (fPointers || (0 != (fKey->fProperties&kNeedDelete))) {
885  }
886  if ( 0 == fValDiff ) {
887  fValDiff = fKey->fSize + fVal->fSize;
888  fValDiff += (slong - fKey->fSize%slong)%slong;
889  fValDiff += (slong - fValDiff%slong)%slong;
890  }
891  if ( 0 == fValOffset ) {
892  fValOffset = fKey->fSize;
893  fValOffset += (slong - fKey->fSize%slong)%slong;
894  }
895  break;
896  case ROOT::kSTLbitset:
897  inside[1] = "bool";
898  // Intentional fall through
899  default:
900  newfValue = R__CreateValue(inside[1], silent);
901 
902  fVal = new Value(*newfValue);
903  if ( 0 == fValDiff ) {
904  fValDiff = fVal->fSize;
905  fValDiff += (slong - fValDiff%slong)%slong;
906  }
907  break;
908  }
909 
910  fPointers = fPointers || (0 != (fVal->fCase&kIsPointer));
911  if (fPointers || (0 != (fVal->fProperties&kNeedDelete))) {
913  }
914  fClass = cl;
915  //fValue must be set last since we use it to indicate that we are initialized
916  fValue = newfValue;
917  return this;
918  }
919  Fatal("TGenCollectionProxy","Components of %s not analysed!",cl->GetName());
920  }
921  Fatal("TGenCollectionProxy","Collection class %s not found!",fTypeinfo.name());
922  return 0;
923 }
924 
925 ////////////////////////////////////////////////////////////////////////////////
926 /// Return a pointer to the TClass representing the container
927 
929 {
930  return fClass ? fClass : Initialize(kFALSE)->fClass;
931 }
932 
933 ////////////////////////////////////////////////////////////////////////////////
934 /// Return the type of collection see TClassEdit::ESTLType
935 
937 {
938  if (!fValue.load()) {
940  }
941  return fSTL_type;
942 }
943 
944 ////////////////////////////////////////////////////////////////////////////////
945 /// Return the offset between two consecutive value_types (memory layout).
946 
948  if (!fValue.load()) {
950  }
951  return fValDiff;
952 }
953 
954 ////////////////////////////////////////////////////////////////////////////////
955 /// Return the sizeof the collection object.
956 
958 {
959  return fClass->Size();
960 }
961 
962 ////////////////////////////////////////////////////////////////////////////////
963 /// Return true if the content is of type 'pointer to'
964 
966 {
967  // Initialize proxy in case it hasn't been initialized yet
968  if( !fValue.load() )
970 
971  // The content of a map and multimap is always a 'pair' and hence
972  // fPointers means "Flag to indicate if containee has pointers (key or value)"
973  // so we need to ignore its value for map and multimap;
976 }
977 
978 ////////////////////////////////////////////////////////////////////////////////
979 /// Return a pointer to the TClass representing the content.
980 
982 {
983  if (!fValue.load()) Initialize(kFALSE);
984  return fValue.load() ? (*fValue).fType.GetClass() : 0;
985 }
986 
987 ////////////////////////////////////////////////////////////////////////////////
988 /// Update the internal ValueClass when a TClass constructor need to
989 /// replace an emulated TClass by the real TClass.
990 
991 void TGenCollectionProxy::UpdateValueClass(const TClass *oldValueType, TClass *newValueType)
992 {
993  // Note that we do not need to update anything if we have not yet been
994  // initialized. In addition (see ROOT-6040) doing an initialization here
995  // might hence a nested dlopen (due to autoloading).
996  if (fValue.load() && (*fValue).fType == oldValueType) {
997  // Set pointer to the TClass representing the content.
998  (*fValue).fType = newValueType;
999  }
1000 }
1001 
1002 ////////////////////////////////////////////////////////////////////////////////
1003 /// If the content is a simple numerical value, return its type (see TDataType)
1004 
1006 {
1007  if ( !fValue.load() ) Initialize(kFALSE);
1008  return (*fValue).fKind;
1009 }
1010 
1011 ////////////////////////////////////////////////////////////////////////////////
1012 /// Return the address of the value at index 'idx'
1013 
1015 {
1016  if ( fEnv && fEnv->fObject ) {
1017  switch (fSTL_type) {
1018  case ROOT::kSTLvector:
1019  fEnv->fIdx = idx;
1020  switch( idx ) {
1021  case 0:
1022  return fEnv->fStart = fFirst.invoke(fEnv);
1023  default:
1024  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
1025  return ((char*)fEnv->fStart) + fValDiff*idx;
1026  }
1027  case ROOT::kSTLset:
1029  case ROOT::kSTLmultiset:
1031  case ROOT::kSTLmap:
1033  case ROOT::kSTLmultimap:
1035  if ( fEnv->fUseTemp ) {
1036  return (((char*)fEnv->fTemp)+idx*fValDiff);
1037  }
1038  // Intentional fall through.
1039  default:
1040  switch( idx ) {
1041  case 0:
1042  fEnv->fIdx = idx;
1043  return fEnv->fStart = fFirst.invoke(fEnv);
1044  default: {
1045  fEnv->fIdx = idx - fEnv->fIdx;
1046  if (! fEnv->fStart ) fEnv->fStart = fFirst.invoke(fEnv);
1047  void* result = fNext.invoke(fEnv);
1048  fEnv->fIdx = idx;
1049  return result;
1050  }
1051  }
1052  }
1053  }
1054  Fatal("TGenCollectionProxy","At> Logic error - no proxy object set.");
1055  return 0;
1056 }
1057 
1058 ////////////////////////////////////////////////////////////////////////////////
1059 /// Clear the emulated collection.
1060 
1061 void TGenCollectionProxy::Clear(const char* opt)
1062 {
1063  if ( fEnv && fEnv->fObject ) {
1064  if ( (fProperties & kNeedDelete) && opt && *opt=='f' ) {
1065  size_t i, n = *(size_t*)fSize.invoke(fEnv);
1066  if ( n > 0 ) {
1067  for (i=0; i<n; ++i)
1069  }
1070  }
1071  fClear.invoke(fEnv);
1072  }
1073 }
1074 
1075 ////////////////////////////////////////////////////////////////////////////////
1076 /// Return the current size of the container
1077 
1079 {
1080  if ( fEnv && fEnv->fObject ) {
1081  if (fEnv->fUseTemp) {
1082  return fEnv->fSize;
1083  } else {
1084  return *(size_t*)fSize.invoke(fEnv);
1085  }
1086  }
1087  Fatal("TGenCollectionProxy","Size> Logic error - no proxy object set.");
1088  return 0;
1089 }
1090 
1091 ////////////////////////////////////////////////////////////////////////////////
1092 /// Resize the container
1093 
1095 {
1096  if ( fEnv && fEnv->fObject ) {
1097  if ( force && fPointers ) {
1098  size_t i, nold = *(size_t*)fSize.invoke(fEnv);
1099  if ( n != nold ) {
1100  for (i=n; i<nold; ++i)
1101  DeleteItem(true, *(void**)TGenCollectionProxy::At(i));
1102  }
1103  }
1104  MESSAGE(3, "Resize(n)" );
1105  fEnv->fSize = n;
1107  return;
1108  }
1109  Fatal("TGenCollectionProxy","Resize> Logic error - no proxy object set.");
1110 }
1111 
1112 ////////////////////////////////////////////////////////////////////////////////
1113 /// Allocate the needed space.
1114 /// For associative collection, this returns a TStaging object that
1115 /// need to be deleted manually __or__ returned by calling Commit(TStaging*)
1116 
1117 void* TGenCollectionProxy::Allocate(UInt_t n, Bool_t /* forceDelete */ )
1118 {
1119  if ( fEnv && fEnv->fObject ) {
1120  switch ( fSTL_type ) {
1121  case ROOT::kSTLset:
1123  case ROOT::kSTLmultiset:
1125  case ROOT::kSTLmap:
1127  case ROOT::kSTLmultimap:
1129  if ( (fProperties & kNeedDelete) )
1130  Clear("force");
1131  else
1132  fClear.invoke(fEnv);
1133  // Commit no longer use the environment and thus no longer decrease
1134  // the count. Consequently we no longer should increase it here.
1135  // ++fEnv->fRefCount;
1136  fEnv->fSize = n;
1137 
1138  TStaging *s;
1139  if (fStaged.empty()) {
1140  s = new TStaging(n,fValDiff);
1141  } else {
1142  s = fStaged.back();
1143  fStaged.pop_back();
1144  s->Resize(n);
1145  }
1146  fConstruct(s->GetContent(),s->GetSize());
1147 
1148  s->SetTarget(fEnv->fObject);
1149 
1150  fEnv->fTemp = s->GetContent();
1151  fEnv->fUseTemp = kTRUE;
1152  fEnv->fStart = fEnv->fTemp;
1153 
1154  return s;
1155  }
1156  case ROOT::kSTLvector:
1157  case ROOT::kSTLlist:
1158  case ROOT::kSTLforwardlist:
1159  case ROOT::kSTLdeque:
1160  if( (fProperties & kNeedDelete) ) {
1161  Clear("force");
1162  }
1163  fEnv->fSize = n;
1164  fResize(fEnv->fObject,n);
1165  return fEnv->fObject;
1166 
1167  case ROOT::kSTLbitset: {
1168  TStaging *s;
1169  if (fStaged.empty()) {
1170  s = new TStaging(n,fValDiff);
1171  } else {
1172  s = fStaged.back();
1173  fStaged.pop_back();
1174  s->Resize(n);
1175  }
1176  s->SetTarget(fEnv->fObject);
1177 
1178  fEnv->fTemp = s->GetContent();
1179  fEnv->fUseTemp = kTRUE;
1180  fEnv->fStart = fEnv->fTemp;
1181 
1182  return s;
1183  }
1184  }
1185  }
1186  return 0;
1187 }
1188 
1189 ////////////////////////////////////////////////////////////////////////////////
1190 /// Insert data into the container where data is a C-style array of the actual type contained in the collection
1191 /// of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
1192 
1193 void TGenCollectionProxy::Insert(const void *data, void *container, size_t size)
1194 {
1195  fFeed((void*)data,container,size);
1196 }
1197 
1198 ////////////////////////////////////////////////////////////////////////////////
1199 /// Commit the change.
1200 
1202 {
1203  if (fProperties & kIsAssociative) {
1204 // case ROOT::kSTLmap:
1205 // case ROOT::kSTLmultimap:
1206 // case ROOT::kSTLset:
1207 // case ROOT::kSTLmultiset:
1208  if ( from ) {
1209  TStaging *s = (TStaging*) from;
1210  if ( s->GetTarget() ) {
1211  fFeed(s->GetContent(),s->GetTarget(),s->GetSize());
1212  }
1213  fDestruct(s->GetContent(),s->GetSize());
1214  s->SetTarget(0);
1215  fStaged.push_back(s);
1216  }
1217  }
1218 }
1219 
1220 ////////////////////////////////////////////////////////////////////////////////
1221 /// Add an object.
1222 
1224 {
1225  if ( !fValue.load() ) Initialize(kFALSE);
1226  if ( !fProxyList.empty() ) {
1227  EnvironBase_t* back = fProxyList.back();
1228  if ( back->fObject == objstart ) {
1229  ++back->fRefCount;
1230  fProxyList.push_back(back);
1231  fEnv = back;
1232  return;
1233  }
1234  }
1235  EnvironBase_t* e = 0;
1236  if ( fProxyKept.empty() ) {
1238  e->fTemp = 0;
1239  e->fUseTemp = kFALSE;
1240  }
1241  else {
1242  e = fProxyKept.back();
1243  fProxyKept.pop_back();
1244  }
1245  e->fSize = 0;
1246  e->fRefCount = 1;
1247  e->fObject = objstart;
1248  e->fStart = 0;
1249  e->fIdx = 0;
1250  // ::memset(e->buff,0,sizeof(e->buff));
1251  fProxyList.push_back(e);
1252  fEnv = e;
1253 }
1254 
1255 ////////////////////////////////////////////////////////////////////////////////
1256 /// Remove the last object.
1257 
1259 {
1260  if ( !fProxyList.empty() ) {
1261  EnvironBase_t* e = fProxyList.back();
1262  if ( --e->fRefCount <= 0 ) {
1263  fProxyKept.push_back(e);
1264  e->fUseTemp = kFALSE;
1265  }
1266  fProxyList.pop_back();
1267  }
1268  fEnv = fProxyList.empty() ? 0 : fProxyList.back();
1269 }
1270 
1271 ////////////////////////////////////////////////////////////////////////////////
1272 /// Call to delete/destruct individual item.
1273 
1274 void TGenCollectionProxy::DeleteItem(Bool_t force, void* ptr) const
1275 {
1276  if ( force && ptr ) {
1277  switch (fSTL_type) {
1278  case ROOT::kSTLmap:
1280  case ROOT::kSTLmultimap:
1282  if ( fKey->fCase&kIsPointer ) {
1283  if (fKey->fProperties&kNeedDelete) {
1285  TPushPop helper(proxy,*(void**)ptr);
1286  proxy->Clear("force");
1287  }
1288  fKey->DeleteItem(*(void**)ptr);
1289  } else {
1290  if (fKey->fProperties&kNeedDelete) {
1292  TPushPop helper(proxy,ptr);
1293  proxy->Clear("force");
1294  }
1295  }
1296  char *addr = ((char*)ptr)+fValOffset;
1297  if ( fVal->fCase&kIsPointer ) {
1298  if ( fVal->fProperties&kNeedDelete) {
1300  TPushPop helper(proxy,*(void**)addr);
1301  proxy->Clear("force");
1302  }
1303  fVal->DeleteItem(*(void**)addr);
1304  } else {
1305  if ( fVal->fProperties&kNeedDelete) {
1307  TPushPop helper(proxy,addr);
1308  proxy->Clear("force");
1309  }
1310  }
1311  break;
1312  }
1313  default: {
1314  if ( fVal->fCase&kIsPointer ) {
1315  if (fVal->fProperties&kNeedDelete) {
1317  TPushPop helper(proxy,*(void**)ptr);
1318  proxy->Clear("force");
1319  }
1320  fVal->DeleteItem(*(void**)ptr);
1321  } else {
1322  if (fVal->fProperties&kNeedDelete) {
1324  TPushPop helper(proxy,ptr);
1325  proxy->Clear("force");
1326  }
1327  }
1328  break;
1329  }
1330  }
1331  }
1332 }
1333 
1334 ////////////////////////////////////////////////////////////////////////////////
1335 
1336 void TGenCollectionProxy::ReadBuffer(TBuffer & /* b */, void * /* obj */, const TClass * /* onfileClass */)
1337 {
1338  MayNotUse("TGenCollectionProxy::ReadBuffer(TBuffer &, void *, const TClass *)");
1339 }
1340 
1341 ////////////////////////////////////////////////////////////////////////////////
1342 
1343 void TGenCollectionProxy::ReadBuffer(TBuffer & /* b */, void * /* obj */)
1344 {
1345  MayNotUse("TGenCollectionProxy::ReadBuffer(TBuffer &, void *)");
1346 }
1347 
1348 ////////////////////////////////////////////////////////////////////////////////
1349 /// Streamer Function.
1350 
1352 {
1353  if ( fEnv ) {
1354  GetCollectionClass()->Streamer( fEnv->fObject, buff );
1355  return;
1356  }
1357  Fatal("TGenCollectionProxy","Streamer> Logic error - no proxy object set.");
1358 }
1359 
1360 ////////////////////////////////////////////////////////////////////////////////
1361 /// Streamer I/O overload
1362 
1363 void TGenCollectionProxy::Streamer(TBuffer &buff, void *objp, int /* siz */ )
1364 {
1365  TPushPop env(this, objp);
1366  Streamer(buff);
1367 }
1368 
1369 ////////////////////////////////////////////////////////////////////////////////
1370 /// TClassStreamer IO overload
1371 
1373 {
1374  Streamer(b, objp, 0);
1375 }
1376 
1377 
1378 struct TGenCollectionProxy__SlowIterator {
1379  TVirtualCollectionProxy *fProxy;
1380  UInt_t fIndex;
1381  TGenCollectionProxy__SlowIterator(TVirtualCollectionProxy *proxy) : fProxy(proxy), fIndex(0) {}
1382 };
1383 
1384 ////////////////////////////////////////////////////////////////////////////////
1385 
1386 void TGenCollectionProxy__SlowCreateIterators(void * /* collection */, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
1387 {
1388  new (*begin_arena) TGenCollectionProxy__SlowIterator(proxy);
1389  *(UInt_t*)*end_arena = proxy->Size();
1390 }
1391 
1392 ////////////////////////////////////////////////////////////////////////////////
1393 
1394 void *TGenCollectionProxy__SlowNext(void *iter, const void *end)
1395 {
1396  TGenCollectionProxy__SlowIterator *iterator = (TGenCollectionProxy__SlowIterator*)iter;
1397  if (iterator->fIndex != *(UInt_t*)end) {
1398  void *result = iterator->fProxy->At(iterator->fIndex);
1399  ++(iterator->fIndex);
1400  return result;
1401  } else {
1402  return 0;
1403  }
1404 }
1405 
1406 ////////////////////////////////////////////////////////////////////////////////
1407 
1408 void * TGenCollectionProxy__SlowCopyIterator(void *dest, const void *source)
1409 {
1410  *(TGenCollectionProxy__SlowIterator*)dest = *(TGenCollectionProxy__SlowIterator*)source;
1411  return dest;
1412 }
1413 
1414 ////////////////////////////////////////////////////////////////////////////////
1415 /// Nothing to do
1416 
1418 {
1419 }
1420 
1421 ////////////////////////////////////////////////////////////////////////////////
1422 /// Nothing to do
1423 
1425 {
1426 }
1427 
1428 
1429 ////////////////////////////////////////////////////////////////////////////////
1430 /// We can safely assume that the std::vector layout does not really depend on
1431 /// the content!
1432 
1433 void TGenCollectionProxy__VectorCreateIterators(void *obj, void **begin_arena, void **end_arena, TVirtualCollectionProxy*)
1434 {
1435  std::vector<char> *vec = (std::vector<char>*)obj;
1436  if (vec->empty()) {
1437  *begin_arena = 0;
1438  *end_arena = 0;
1439  return;
1440  }
1441  *begin_arena = &(*vec->begin());
1442 #ifdef R__VISUAL_CPLUSPLUS
1443  *end_arena = &(*(vec->end()-1)) + 1; // On windows we can not dererence the end iterator at all.
1444 #else
1445  // coverity[past_the_end] Safe on other platforms
1446  *end_arena = &(*vec->end());
1447 #endif
1448 
1449 }
1450 
1451 ////////////////////////////////////////////////////////////////////////////////
1452 /// Should not be used.
1453 
1454 void *TGenCollectionProxy__VectorNext(void *, const void *)
1455 {
1456  R__ASSERT(0);
1457  return 0;
1458 }
1459 
1460 ////////////////////////////////////////////////////////////////////////////////
1461 
1462 void *TGenCollectionProxy__VectorCopyIterator(void *dest, const void *source)
1463 {
1464  *(void**)dest = *(void**)source;
1465  return dest;
1466 }
1467 
1468 ////////////////////////////////////////////////////////////////////////////////
1469 /// Nothing to do
1470 
1472 {
1473 }
1474 
1475 ////////////////////////////////////////////////////////////////////////////////
1476 /// Nothing to do
1477 
1479 {
1480 }
1481 
1482 
1483 
1484 ////////////////////////////////////////////////////////////////////////////////
1485 
1486 void TGenCollectionProxy__StagingCreateIterators(void *obj, void **begin_arena, void **end_arena, TVirtualCollectionProxy *)
1487 {
1489  *begin_arena = s->GetContent();
1490  *end_arena = s->GetEnd();
1491 }
1492 
1493 ////////////////////////////////////////////////////////////////////////////////
1494 /// Should not be used.
1495 
1496 void *TGenCollectionProxy__StagingNext(void *, const void *)
1497 {
1498  R__ASSERT(0);
1499  return 0;
1500 }
1501 
1502 ////////////////////////////////////////////////////////////////////////////////
1503 
1504 void *TGenCollectionProxy__StagingCopyIterator(void *dest, const void *source)
1505 {
1506  *(void**)dest = *(void**)source;
1507  return dest;
1508 }
1509 
1510 ////////////////////////////////////////////////////////////////////////////////
1511 /// Nothing to do
1512 
1514 {
1515 }
1516 
1517 ////////////////////////////////////////////////////////////////////////////////
1518 /// Nothing to do
1519 
1521 {
1522 }
1523 
1524 
1525 ////////////////////////////////////////////////////////////////////////////////
1526 /// See typedef void (*CreateIterators_t)(void *collection, void *&begin_arena, void *&end_arena);
1527 /// begin_arena and end_arena should contain the location of memory arena of size fgIteratorSize.
1528 /// If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
1529 /// Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
1530 
1532 {
1533  if (read) {
1534  if ( !fValue.load() ) InitializeEx(kFALSE);
1535  if ( (fProperties & kIsAssociative) && read)
1537  }
1538 
1540 
1541  if ( !fValue.load() ) InitializeEx(kFALSE);
1542 
1543 // fprintf(stderr,"GetFunctinCreateIterator for %s will give: ",fClass.GetClassName());
1544 // if (fSTL_type==ROOT::kSTLvector || (fProperties & kIsEmulated))
1545 // fprintf(stderr,"vector/emulated iterator\n");
1546 // else if ( (fProperties & kIsAssociative) && read)
1547 // fprintf(stderr,"an associative read iterator\n");
1548 // else
1549 // fprintf(stderr,"a generic iterator\n");
1550 
1553  else if ( (fProperties & kIsAssociative) && read)
1555  else
1557 }
1558 
1559 ////////////////////////////////////////////////////////////////////////////////
1560 /// See typedef void (*CopyIterator_t)(void *&dest, const void *source);
1561 /// Copy the iterator source, into dest. dest should contain should contain the location of memory arena of size fgIteratorSize.
1562 /// If the collection iterator are of that size or less, the iterator will be constructed in place in this location (new with placement)
1563 /// Otherwise the iterator will be allocated via a regular new and its address returned by modifying the value of dest.
1564 
1566 {
1567  if (read) {
1568  if ( !fValue.load() ) InitializeEx(kFALSE);
1569  if ( (fProperties & kIsAssociative) && read)
1571  }
1572 
1574 
1575  if ( !fValue.load() ) InitializeEx(kFALSE);
1576 
1579  else if ( (fProperties & kIsAssociative) && read)
1581  else
1583 }
1584 
1585 ////////////////////////////////////////////////////////////////////////////////
1586 /// See typedef void* (*Next_t)(void *iter, void *end);
1587 /// iter and end should be pointer to respectively an iterator to be incremented and the result of colleciton.end()
1588 /// 'Next' will increment the iterator 'iter' and return 0 if the iterator reached the end.
1589 /// If the end is not reached, 'Next' will return the address of the content unless the collection contains pointers in
1590 /// which case 'Next' will return the value of the pointer.
1591 
1593 {
1594  if (read) {
1595  if ( !fValue.load() ) InitializeEx(kFALSE);
1596  if ( (fProperties & kIsAssociative) && read)
1598  }
1599 
1601 
1602  if ( !fValue.load() ) InitializeEx(kFALSE);
1603 
1606  else if ( (fProperties & kIsAssociative) && read)
1608  else
1610 }
1611 
1612 ////////////////////////////////////////////////////////////////////////////////
1613 /// See typedef void (*DeleteIterator_t)(void *iter);
1614 /// If the sizeof iterator is greater than fgIteratorArenaSize, call delete on the addresses,
1615 /// Otherwise just call the iterator's destructor.
1616 
1618 {
1619  if (read) {
1620  if ( !fValue.load() ) InitializeEx(kFALSE);
1621  if ( (fProperties & kIsAssociative) && read)
1623  }
1624 
1626 
1627  if ( !fValue.load() ) InitializeEx(kFALSE);
1628 
1631  else if ( (fProperties & kIsAssociative) && read)
1633  else
1635 }
1636 
1637 ////////////////////////////////////////////////////////////////////////////////
1638 /// See typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
1639 /// If the sizeof iterator is greater than fgIteratorArenaSize, call delete on the addresses,
1640 /// Otherwise just call the iterator's destructor.
1641 
1643 {
1644  if (read) {
1645  if ( !fValue.load() ) InitializeEx(kFALSE);
1646  if ( (fProperties & kIsAssociative) && read)
1648  }
1649 
1651 
1652  if ( !fValue.load() ) InitializeEx(kFALSE);
1653 
1656  else if ( (fProperties & kIsAssociative) && read)
1658  else
1660 }
1661 
1662 ////////////////////////////////////////////////////////////////////////////////
1663 /// Return the set of action necessary to stream in this collection member-wise coming from
1664 /// the old value class layout refered to by 'version'.
1665 
1667 {
1668  if (oldClass == 0) {
1669  return 0;
1670  }
1671  TObjArray* arr = 0;
1674  std::map<std::string, TObjArray*>::iterator it;
1675 
1676  it = fConversionReadMemberWise->find( oldClass->GetName() );
1677 
1678  if( it != fConversionReadMemberWise->end() ) {
1679  arr = it->second;
1680  }
1681 
1682  if (arr) {
1683  result = (TStreamerInfoActions::TActionSequence *)arr->At(version);
1684  if (result) {
1685  return result;
1686  }
1687  }
1688  }
1689 
1690  // Need to create it.
1691  TClass *valueClass = GetValueClass();
1692  if (valueClass == 0) {
1693  return 0;
1694  }
1695  TVirtualStreamerInfo *info = valueClass->GetConversionStreamerInfo(oldClass,version);
1696  if (info == 0) {
1697  return 0;
1698  }
1700 
1701  if (!arr) {
1702  arr = new TObjArray(version+10, -1);
1704  fConversionReadMemberWise = new std::map<std::string, TObjArray*>();
1705  }
1706  (*fConversionReadMemberWise)[oldClass->GetName()] = arr;
1707  }
1708  arr->AddAtAndExpand( result, version );
1709 
1710  return result;
1711 }
1712 
1713 ////////////////////////////////////////////////////////////////////////////////
1714 /// Return the set of action necessary to stream in this collection member-wise coming from
1715 /// the old value class layout refered to by 'version'.
1716 
1718 {
1720  if (version < (fReadMemberWise->GetSize()-1)) { // -1 because the 'index' starts at -1
1722  }
1723  if (result == 0) {
1724  // Need to create it.
1725  TClass *valueClass = GetValueClass();
1726  TVirtualStreamerInfo *info = 0;
1727  if (valueClass) {
1728  info = valueClass->GetStreamerInfo(version);
1729  }
1731  fReadMemberWise->AddAtAndExpand(result,version);
1732  }
1733  return result;
1734 }
1735 
1736 ////////////////////////////////////////////////////////////////////////////////
1737 /// Return the set of action necessary to stream out this collection member-wise.
1738 
1740 {
1742  if (result == 0) {
1743  // Need to create it.
1744  TClass *valueClass = GetValueClass();
1745  TVirtualStreamerInfo *info = 0;
1746  if (valueClass) {
1747  info = valueClass->GetStreamerInfo();
1748  }
1751  }
1752  return result;
1753 }
Method fSize
Container accessors: size of container.
void(* DeleteIterator_t)(void *iter)
double read(const std::string &file_name)
reading
void *(* fNext)(void *iter, const void *end)
void * TGenCollectionProxy__StagingCopyIterator(void *dest, const void *source)
DeleteIterator_t fFunctionDeleteIterator
void TGenCollectionProxy__StagingDeleteSingleIterators(void *)
Nothing to do.
ROOT::DelFunc_t fDelete
Method cache for containee delete.
An array of TObjects.
Definition: TObjArray.h:39
void(* fDeleteTwoIterators)(void *begin, void *end)
ROOT::NewFunc_t fCtor
Method cache for containee constructor.
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)
Return the set of action necessary to stream in this collection member-wise coming from the old value...
virtual Int_t GetProperties() const
Proxies_t fProxyKept
Optimization: Keep proxies once they were created.
virtual TVirtualCollectionProxy * Generate() const
Virtual copy constructor.
DeleteTwoIterators_t fFunctionDeleteTwoIterators
void * invoke(void *obj) const
UInt_t fProperties
Additional properties of the value type (kNeedDelete)
void *(* fCollectFunc)(void *, void *)
void TGenCollectionProxy__VectorDeleteTwoIterators(void *, void *)
Nothing to do.
virtual void UpdateValueClass(const TClass *oldcl, TClass *newcl)
Update the internal ValueClass when a TClass constructor need to replace an emulated TClass by the re...
Int_t GetType() const
Definition: TDataType.h:70
void Fatal(const char *location, const char *msgfmt,...)
Bool_t fPointers
Flag to indicate if containee has pointers (key or value)
std::map< std::string, TObjArray * > * fConversionReadMemberWise
Array of bundle of TStreamerInfoActions to stream out (read) derived from another class...
TGenCollectionProxy * Initialize(Bool_t silent) const
Proxy initializer.
return c
Collectfunc_t fCollect
Method to collect objects from container.
ROOT::DesFunc_t GetDestructor() const
std::string fName
Name of the class being proxied.
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
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
void *(* fCopyIterator)(void *dest, const void *source)
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()
Return the set of action necessary to stream out this collection member-wise.
virtual void PopProxy()
Remove the last object.
const char * GetFullTypeName() const
Get full type description of typedef, e,g.: &quot;class TDirectory*&quot;.
Definition: TDataType.cxx:175
void *(* fFeedFunc)(void *, void *, size_t)
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...
Method fFirst
Container accessors: generic iteration: first.
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
#define R__ASSERT(e)
Definition: TError.h:98
#define gROOT
Definition: TROOT.h:379
virtual TypeInfo_t * TypeInfo_Factory() const
Definition: TInterpreter.h:481
TClass * fOnFileClass
On file class.
Feedfunc_t fFeed
Container accessors: block feed.
int Int_t
Definition: RtypesCore.h:41
ROOT::NewFunc_t GetNew() const
bool Bool_t
Definition: RtypesCore.h:59
virtual void Clear(const char *opt="")=0
const Bool_t kFALSE
Definition: Rtypes.h:92
#define MESSAGE(which, text)
const char * Class
Definition: TXMLSetup.cxx:64
UInt_t fCase
type of data of Value_type
virtual Bool_t HasPointers() const
Return true if the content is of type &#39;pointer to&#39;.
void * TGenCollectionProxy__StagingNext(void *, const void *)
Should not be used.
virtual ULong_t GetIncrement() const
Return the offset between two consecutive value_types (memory layout).
Sizing_t fResize
Container accessors: resize container.
void *(* CopyIterator_t)(void *dest, const void *source)
static TActionSequence * CreateReadMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy)
Create the bundle of the actions necessary for the streaming memberwise of the content described by &#39;...
size_t fSize
fSize of the contained object
virtual int TypeInfo_Size(TypeInfo_t *) const
Definition: TInterpreter.h:489
virtual Int_t GetCollectionType() const
Return the type of collection see TClassEdit::ESTLType.
virtual void DeleteItem(Bool_t force, void *ptr) const
Call to delete/destruct individual item.
void * TGenCollectionProxy__SlowNext(void *iter, const void *end)
void * TGenCollectionProxy__VectorNext(void *, const void *)
Should not be used.
TObjArray * fReadMemberWise
Array of bundle of TStreamerInfoActions to stream out (read)
CopyIterator_t fFunctionCopyIterator
THashTable implements a hash table to store TObject&#39;s.
Definition: THashTable.h:39
void TGenCollectionProxy__SlowCreateIterators(void *, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
static TGenCollectionProxy::Value * R__CreateValue(const std::string &name, Bool_t silent)
Utility routine to issue a Fatal error is the Value object is not valid.
virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read=kTRUE)
See typedef void (*CreateIterators_t)(void *collection, void *&amp;begin_arena, void *&amp;end_arena); begin_...
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)
Return the set of action necessary to stream in this collection member-wise coming from the old value...
virtual void TypeInfo_Delete(TypeInfo_t *) const
Definition: TInterpreter.h:480
void TGenCollectionProxy__SlowDeleteTwoIterators(void *, void *)
Nothing to do.
virtual Bool_t TypeInfo_IsValid(TypeInfo_t *) const
Definition: TInterpreter.h:485
void *(* fConstructFunc)(void *, size_t)
virtual UInt_t Size() const
Return the current size of the container.
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
Definition: TClassEdit.cxx:468
Proxies_t fProxyList
Stack of recursive proxies.
Method fClear
Method cache for container accessors: clear container.
Method0 fCreateEnv
Method to allocate an Environment holder.
ArrIterfunc_t fConstruct
Container accessors: block construct.
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
void Error(const char *location, const char *msgfmt,...)
EDataType fKind
kind of ROOT-fundamental type
ROOT::DelFunc_t GetDelete() const
Staged_t fStaged
Optimization: Keep staged array once they were created.
void MayNotUse(const char *method)
This function can be used in classes that should override a certain function, but in the inherited cl...
Definition: TError.cxx:269
void TGenCollectionProxy__StagingDeleteTwoIterators(void *, void *)
Nothing to do.
virtual EDataType GetType() const
If the content is a simple numerical value, return its type (see TDataType)
int fValOffset
Offset from key to value (in maps)
Small helper to save proxy environment in the event of recursive calls.
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:222
int fSTL_type
STL container type.
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:4346
SVector< double, 2 > v
Definition: Dict.h:5
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:46
virtual void TypeInfo_Init(TypeInfo_t *, const char *) const
Definition: TInterpreter.h:484
TVirtualStreamerInfo * GetConversionStreamerInfo(const char *onfile_classname, Int_t version) const
Return a Conversion StreamerInfo from the class &#39;classname&#39; for version number &#39;version&#39; to this clas...
Definition: TClass.cxx:6623
virtual void Commit(void *env)
Commit the change.
static TActionSequence * CreateWriteMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy)
Create the bundle of the actions necessary for the streaming memberwise of the content described by &#39;...
void(* fCreateIterators)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Long_t TypeInfo_Property(TypeInfo_t *) const
Definition: TInterpreter.h:487
virtual void PushProxy(void *objstart)
Add an object.
virtual Next_t GetFunctionNext(Bool_t read=kTRUE)
See typedef void* (*Next_t)(void *iter, void *end); iter and end should be pointer to respectively an...
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
CreateIterators_t fFunctionCreateIterators
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
int fValDiff
Offset between two consecutive value_types (memory layout).
void TGenCollectionProxy__SlowDeleteSingleIterators(void *)
Nothing to do.
#define R__LOCKGUARD2(mutex)
PyObject * fType
long Long_t
Definition: RtypesCore.h:50
virtual void Resize(UInt_t n, Bool_t force_delete)
Resize the container.
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read=kTRUE)
See typedef void (*DeleteIterator_t)(void *iter); If the sizeof iterator is greater than fgIteratorAr...
virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read=kTRUE)
See typedef void (*DeleteTwoIterators_t)(void *begin, void *end); If the sizeof iterator is greater t...
virtual TGenCollectionProxy * InitializeEx(Bool_t silent)
Proxy initializer.
void(* CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
unsigned long ULong_t
Definition: RtypesCore.h:51
void *(* Next_t)(void *iter, const void *end)
void TGenCollectionProxy__StagingCreateIterators(void *obj, void **begin_arena, void **end_arena, TVirtualCollectionProxy *)
EDataType
Definition: TDataType.h:30
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
void CheckFunctions() const
Check existence of function pointers.
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:2872
std::atomic< Value * > fValue
Descriptor of the container value type.
TClassRef fType
TClass reference of Value_type in collection.
virtual void Clear(const char *opt="")
Clear the emulated collection.
virtual void ReadBuffer(TBuffer &b, void *obj)
virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read=kTRUE)
See typedef void (*CopyIterator_t)(void *&amp;dest, const void *source); Copy the iterator source...
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2801
virtual TClass * GetValueClass() const
Return a pointer to the TClass representing the content.
Value(const std::string &info, Bool_t silent)
Constructor.
virtual void * At(UInt_t idx)
Return the address of the value at index &#39;idx&#39;.
Int_t Size() const
Get size of basic typedef&#39;ed type.
Definition: TDataType.cxx:366
void * TGenCollectionProxy__VectorCopyIterator(void *dest, const void *source)
TClass * GetClass() const
Definition: TClassRef.h:75
virtual UInt_t Size() const =0
Value * fKey
Descriptor of the key_type.
virtual void operator()(TBuffer &refBuffer, void *pObject)
TClassStreamer IO overload.
void * TGenCollectionProxy__SlowCopyIterator(void *dest, const void *source)
Small helper to stage the content of an associative container when reading and before inserting it in...
#define dest(otri, vertexptr)
Definition: triangle.c:1040
Proxy around an arbitrary container, which implements basic functionality and iteration.
EnvironBase_t * fEnv
Address of the currently proxied object.
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
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
Sizing_t fDestruct
Container accessors: block destruct.
void TGenCollectionProxy__VectorCreateIterators(void *obj, void **begin_arena, void **end_arena, TVirtualCollectionProxy *)
We can safely assume that the std::vector layout does not really depend on the content! ...
Bool_t IsValid()
Return true if the Value has been properly initialized.
Method fNext
Container accessors: generic iteration: next.
void(* DeleteTwoIterators_t)(void *begin, void *end)
double result[121]
Info_t fTypeinfo
Type information.
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:519
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=0) const
Definition: TClass.h:540
Abstract Interface class describing Streamer information for one class.
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual TClass * GetCollectionClass() const
Return a pointer to the TClass representing the container.
virtual UInt_t Sizeof() const
Return the sizeof the collection object.
const std::type_info & Info_t
const Int_t n
Definition: legend1.C:16
TStreamerInfoActions::TActionSequence * fWriteMemberWise
char name[80]
Definition: TGX11.cxx:109
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5334
Small helper to describe the Value_type or the key_type of an STL container.
void TGenCollectionProxy__VectorDeleteSingleIterators(void *)
Nothing to do.
const char * Value
Definition: TXMLSetup.cxx:73
virtual ~TGenCollectionProxy()
Standard destructor.
virtual void * Allocate(UInt_t n, Bool_t forceDelete)
Allocate the needed space.
Value * fVal
Descriptor of the Value_type.
T1 fFirst
Definition: X11Events.mm:86
ROOT::DesFunc_t fDtor
Method cache for containee destructor.