Logo ROOT  
Reference Guide
TEmulatedMapProxy.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 // //
14 // TEmulatedMapProxy
15 //
16 // Streamer around an arbitrary container, which implements basic
17 // functionality and iteration.
18 //
19 // In particular this is used to implement splitting and abstract
20 // element access of any container. Access to compiled code is necessary
21 // to implement the abstract iteration sequence and functionality like
22 // size(), clear(), resize(). resize() may be a void operation.
23 //
24 //////////////////////////////////////////////////////////////////////////
25 
26 /**
27  \class TEmulatedMapProxy
28  \ingroup IO
29 
30 Streamer around a map container. For optimization reasons this functionality
31 is separated from the TEmulatedProxy.
32 */
33 
34 #include "TEmulatedMapProxy.h"
35 #include "TClassEdit.h"
36 #include "TStreamerInfo.h"
37 #include "TError.h"
38 
41 {
42  // copy constructor
44  Fatal("TEmulatedMapProxy","Class %s is not a map-type!",fName.c_str());
45  }
46 }
47 
48 TEmulatedMapProxy::TEmulatedMapProxy(const char* cl_name, Bool_t silent)
49  : TEmulatedCollectionProxy(cl_name, silent)
50 {
51  // Build a Streamer for an emulated vector whose type is 'name'.
53  Fatal("TEmulatedMapProxy","Class %s is not a map-type!",fName.c_str());
54  }
55 }
56 
58 {
59  // Standard destructor.
60 }
61 
63 {
64  // Virtual copy constructor.
65  if ( !fClass ) Initialize(kFALSE);
66  return new TEmulatedMapProxy(*this);
67 }
68 
70 {
71  // Return the address of the value at index 'idx'.
72  if ( fEnv && fEnv->fObject ) {
74  return idx<(c->size()/fValDiff) ? ((char*)&(*c->begin())) + idx*fValDiff : 0;
75  }
76  Fatal("TEmulatedMapProxy","At> Logic error - no proxy object set.");
77  return 0;
78 }
79 
81 {
82  // Return the current size of the container.
83  if ( fEnv && fEnv->fObject ) {
85  return fEnv->fSize = (c->size()/fValDiff);
86  }
87  Fatal("TEmulatedMapProxy","Size> Logic error - no proxy object set.");
88  return 0;
89 }
90 
92 {
93  // Map input streamer.
94  Bool_t vsn3 = b.GetInfo() && b.GetInfo()->GetOldVersion()<=3;
95  UInt_t idx, loop;
96  Int_t off[2] = {0, fValOffset };
97  Value *v, *val[2] = { fKey, fVal };
98  StreamHelper* helper;
99  float f;
100  char* addr = 0;
101  char* temp = (char*)At(0);
102  for ( idx = 0; idx < nElements; ++idx ) {
103  addr = temp + idx*fValDiff;
104  for ( loop=0; loop<2; loop++) {
105  addr += off[loop];
106  helper = (StreamHelper*)addr;
107  v = val[loop];
108  switch (v->fCase) {
109  case kIsFundamental: // Only handle primitives this way
110  case kIsEnum:
111  switch( int(v->fKind) ) {
112  case kBool_t: b >> helper->boolean; break;
113  case kChar_t: b >> helper->s_char; break;
114  case kShort_t: b >> helper->s_short; break;
115  case kInt_t: b >> helper->s_int; break;
116  case kLong_t: b >> helper->s_long; break;
117  case kLong64_t: b >> helper->s_longlong; break;
118  case kFloat_t: b >> helper->flt; break;
119  case kFloat16_t: b >> f;
120  helper->flt = float(f); break;
121  case kDouble_t: b >> helper->dbl; break;
122  case kUChar_t: b >> helper->u_char; break;
123  case kUShort_t: b >> helper->u_short; break;
124  case kUInt_t: b >> helper->u_int; break;
125  case kULong_t: b >> helper->u_long; break;
126  case kULong64_t: b >> helper->u_longlong; break;
127  case kDouble32_t:b >> f;
128  helper->dbl = double(f); break;
129  case kchar:
130  case kNoType_t:
131  case kOther_t:
132  Error("TEmulatedMapProxy","fType %d is not supported yet!\n",v->fKind);
133  }
134  break;
135  case kIsClass:
136  b.StreamObject(helper,v->fType);
137  break;
138  case kBIT_ISSTRING:
139  helper->read_std_string(b);
140  break;
141  case kIsPointer|kIsClass:
142  helper->set(b.ReadObjectAny(v->fType));
143  break;
145  helper->read_std_string_pointer(b);
146  break;
148  helper->read_tstring_pointer(vsn3,b);
149  break;
150  }
151  }
152  }
153 }
154 
156 {
157  // Map output streamer.
158  Value *v, *val[2] = { fKey, fVal };
159  int off[2] = { 0, fValOffset };
160  StreamHelper* i;
161  char* addr = 0;
162  char* temp = (char*)At(0);
163  for (UInt_t loop, idx = 0; idx < nElements; ++idx ) {
164  addr = temp + idx*fValDiff;
165  for ( loop = 0; loop<2; ++loop ) {
166  addr += off[loop];
167  i = (StreamHelper*)addr;
168  v = val[loop];
169  switch (v->fCase) {
170  case kIsFundamental: // Only handle primitives this way
171  case kIsEnum:
172  switch( int(v->fKind) ) {
173  case kBool_t: b << i->boolean; break;
174  case kChar_t: b << i->s_char; break;
175  case kShort_t: b << i->s_short; break;
176  case kInt_t: b << i->s_int; break;
177  case kLong_t: b << i->s_long; break;
178  case kLong64_t: b << i->s_longlong; break;
179  case kFloat_t: b << i->flt; break;
180  case kFloat16_t: b << float(i->flt); break;
181  case kDouble_t: b << i->dbl; break;
182  case kUChar_t: b << i->u_char; break;
183  case kUShort_t: b << i->u_short; break;
184  case kUInt_t: b << i->u_int; break;
185  case kULong_t: b << i->u_long; break;
186  case kULong64_t: b << i->u_longlong; break;
187  case kDouble32_t:b << float(i->dbl); break;
188  case kchar:
189  case kNoType_t:
190  case kOther_t:
191  Error("TEmulatedMapProxy","fType %d is not supported yet!\n",v->fKind);
192  }
193  break;
194  case kIsClass:
195  b.StreamObject(i,v->fType);
196  break;
197  case kBIT_ISSTRING:
198  TString(i->c_str()).Streamer(b);
199  break;
200  case kIsPointer|kIsClass:
201  b.WriteObjectAny(i->ptr(),v->fType);
202  break;
205  break;
208  break;
209  }
210  }
211  }
212 }
213 
214 void TEmulatedMapProxy::ReadBuffer(TBuffer &b, void *obj, const TClass *onfileClass)
215 {
216  // Read portion of the streamer.
217 
218  SetOnFileClass((TClass*)onfileClass);
219  ReadBuffer(b,obj);
220 }
221 
223 {
224  // Read portion of the streamer.
225 
226  TPushPop env(this,obj);
227  int nElements = 0;
228  b >> nElements;
229  if ( fEnv->fObject ) {
230  Resize(nElements,true);
231  }
232  if ( nElements > 0 ) {
233  ReadMap(nElements, b);
234  }
235 }
236 
238 {
239  // TClassStreamer IO overload.
240  if ( b.IsReading() ) { //Read mode
241  UInt_t nElements = 0;
242  b >> nElements;
243  if ( fEnv->fObject ) {
244  Resize(nElements,true);
245  }
246  if ( nElements > 0 ) {
247  ReadMap(nElements, b);
248  }
249  }
250  else { // Write case
251  UInt_t nElements = fEnv->fObject ? Size() : 0;
252  b << nElements;
253  if ( nElements > 0 ) {
254  WriteMap(nElements, b);
255  }
256  }
257 }
TEmulatedCollectionProxy::PCont_t
Cont_t * PCont_t
Definition: TEmulatedCollectionProxy.h:27
kULong64_t
@ kULong64_t
Definition: TDataType.h:32
c
#define c(i)
Definition: RSha256.hxx:101
TEmulatedMapProxy
Streamer around a map container.
Definition: TEmulatedMapProxy.h:16
TGenCollectionProxy::StreamHelper::u_char
UChar_t u_char
Definition: TGenCollectionProxy.h:97
kDouble_t
@ kDouble_t
Definition: TDataType.h:31
kUChar_t
@ kUChar_t
Definition: TDataType.h:29
kInt_t
@ kInt_t
Definition: TDataType.h:30
TGenCollectionProxy::StreamHelper::u_short
UShort_t u_short
Definition: TGenCollectionProxy.h:98
TGenCollectionProxy::StreamHelper::ptr
void * ptr()
Definition: TGenCollectionProxy.h:106
TEmulatedMapProxy::WriteMap
void WriteMap(UInt_t nElements, TBuffer &b)
Definition: TEmulatedMapProxy.cxx:155
kIsClass
@ kIsClass
Definition: TDictionary.h:65
f
#define f(i)
Definition: RSha256.hxx:104
TEmulatedMapProxy::At
virtual void * At(UInt_t idx)
Return the address of the value at index 'idx'.
Definition: TEmulatedMapProxy.cxx:69
kNoType_t
@ kNoType_t
Definition: TDataType.h:33
TStreamerInfo.h
kLong_t
@ kLong_t
Definition: TDataType.h:30
kChar_t
@ kChar_t
Definition: TDataType.h:29
kULong_t
@ kULong_t
Definition: TDataType.h:30
TGenCollectionProxy::StreamHelper::s_short
Short_t s_short
Definition: TGenCollectionProxy.h:91
TGenCollectionProxy::StreamHelper::dbl
Double_t dbl
Definition: TGenCollectionProxy.h:96
TEmulatedMapProxy::ReadMap
void ReadMap(UInt_t nElements, TBuffer &b)
Definition: TEmulatedMapProxy.cxx:91
kIsPointer
@ kIsPointer
Definition: TDictionary.h:78
TGenCollectionProxy::StreamHelper::u_int
UInt_t u_int
Definition: TGenCollectionProxy.h:99
TGenCollectionProxy::fSTL_type
int fSTL_type
STL container type.
Definition: TGenCollectionProxy.h:320
TGenCollectionProxy::StreamHelper::u_longlong
ULong64_t u_longlong
Definition: TGenCollectionProxy.h:101
TEmulatedMapProxy::Size
virtual UInt_t Size() const
Return the current size of the container.
Definition: TEmulatedMapProxy.cxx:80
TGenCollectionProxy::StreamHelper::set
void set(void *p)
Definition: TGenCollectionProxy.h:118
TEmulatedMapProxy::Generate
virtual TVirtualCollectionProxy * Generate() const
Virtual copy constructor.
Definition: TEmulatedMapProxy.cxx:62
TEmulatedMapProxy::ReadBuffer
virtual void ReadBuffer(TBuffer &buff, void *pObj)
Definition: TEmulatedMapProxy.cxx:222
kUInt_t
@ kUInt_t
Definition: TDataType.h:30
TGenCollectionProxy::StreamHelper::read_std_string
void read_std_string(TBuffer &b)
Definition: TGenCollectionProxy.h:121
ROOT::Detail::TCollectionProxyInfo::EnvironBase::fSize
size_t fSize
Definition: TCollectionProxyInfo.h:229
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
kchar
@ kchar
Definition: TDataType.h:31
TGenCollectionProxy::StreamHelper::write_tstring_pointer
void write_tstring_pointer(TBuffer &b)
Definition: TGenCollectionProxy.h:179
TString
Basic string class.
Definition: TString.h:136
v
@ v
Definition: rootcling_impl.cxx:3643
b
#define b(i)
Definition: RSha256.hxx:100
bool
TGenCollectionProxy::StreamHelper::s_int
Int_t s_int
Definition: TGenCollectionProxy.h:92
TGenCollectionProxy::SetOnFileClass
virtual void SetOnFileClass(TClass *cl)
Definition: TGenCollectionProxy.h:424
kFloat16_t
@ kFloat16_t
Definition: TDataType.h:33
TGenCollectionProxy::fVal
Value * fVal
Descriptor of the Value_type.
Definition: TGenCollectionProxy.h:312
ROOT::kSTLmap
@ kSTLmap
Definition: ESTLType.h:33
TGenCollectionProxy::fKey
Value * fKey
Descriptor of the key_type.
Definition: TGenCollectionProxy.h:313
kDouble32_t
@ kDouble32_t
Definition: TDataType.h:31
TGenCollectionProxy::StreamHelper::read_std_string_pointer
void read_std_string_pointer(TBuffer &b)
Definition: TGenCollectionProxy.h:131
TEmulatedMapProxy.h
TGenCollectionProxy::Value
Small helper to describe the Value_type or the key_type of an STL container.
Definition: TGenCollectionProxy.h:60
TGenCollectionProxy::kBIT_ISSTRING
@ kBIT_ISSTRING
Definition: TGenCollectionProxy.h:47
ROOT::Detail::TCollectionProxyInfo::EnvironBase::fObject
void * fObject
Definition: TCollectionProxyInfo.h:230
TGenCollectionProxy::StreamHelper::c_str
const char * c_str()
Definition: TGenCollectionProxy.h:112
TEmulatedCollectionProxy
Streamer around an arbitrary STL like container, which implements basic container functionality.
Definition: TEmulatedCollectionProxy.h:18
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
Fatal
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition: TError.cxx:245
kUShort_t
@ kUShort_t
Definition: TDataType.h:29
TGenCollectionProxy::StreamHelper::flt
Float_t flt
Definition: TGenCollectionProxy.h:95
kIsFundamental
@ kIsFundamental
Definition: TDictionary.h:70
TGenCollectionProxy::StreamHelper::s_longlong
Long64_t s_longlong
Definition: TGenCollectionProxy.h:94
TGenCollectionProxy::StreamHelper::s_char
Char_t s_char
Definition: TGenCollectionProxy.h:90
ROOT::kSTLmultimap
@ kSTLmultimap
Definition: ESTLType.h:34
TGenCollectionProxy::StreamHelper::boolean
Bool_t boolean
Definition: TGenCollectionProxy.h:89
double
double
Definition: Converters.cxx:921
TGenCollectionProxy::kBIT_ISTSTRING
@ kBIT_ISTSTRING
Definition: TGenCollectionProxy.h:48
kLong64_t
@ kLong64_t
Definition: TDataType.h:32
kFloat_t
@ kFloat_t
Definition: TDataType.h:31
TGenCollectionProxy::Initialize
TGenCollectionProxy * Initialize(Bool_t silent) const
Proxy initializer.
Definition: TGenCollectionProxy.cxx:771
kOther_t
@ kOther_t
Definition: TDataType.h:32
unsigned int
TGenCollectionProxy::StreamHelper
Helper class to facilitate I/O.
Definition: TGenCollectionProxy.h:88
TGenCollectionProxy::fName
std::string fName
Name of the class being proxied.
Definition: TGenCollectionProxy.h:299
TClassEdit.h
kIsEnum
@ kIsEnum
Definition: TDictionary.h:68
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TVirtualCollectionProxy::TPushPop
Definition: TVirtualCollectionProxy.h:58
TGenCollectionProxy::fValDiff
int fValDiff
Offset between two consecutive value_types (memory layout).
Definition: TGenCollectionProxy.h:316
TGenCollectionProxy::StreamHelper::write_std_string_pointer
void write_std_string_pointer(TBuffer &b)
Definition: TGenCollectionProxy.h:139
TVirtualCollectionProxy::fClass
TClassRef fClass
Definition: TVirtualCollectionProxy.h:44
TEmulatedMapProxy::~TEmulatedMapProxy
virtual ~TEmulatedMapProxy()
Definition: TEmulatedMapProxy.cxx:57
TEmulatedCollectionProxy::Resize
virtual void Resize(UInt_t n, Bool_t force_delete)
Resize the container.
Definition: TEmulatedCollectionProxy.cxx:450
TGenCollectionProxy::fValOffset
int fValOffset
Offset from key to value (in maps)
Definition: TGenCollectionProxy.h:315
TGenCollectionProxy::StreamHelper::u_long
ULong_t u_long
Definition: TGenCollectionProxy.h:100
TGenCollectionProxy::StreamHelper::s_long
Long_t s_long
Definition: TGenCollectionProxy.h:93
TGenCollectionProxy::fEnv
EnvironBase_t * fEnv
Address of the currently proxied object.
Definition: TGenCollectionProxy.h:314
kShort_t
@ kShort_t
Definition: TDataType.h:29
kBool_t
@ kBool_t
Definition: TDataType.h:32
TEmulatedMapProxy::Streamer
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
Definition: TEmulatedMapProxy.cxx:237
TEmulatedMapProxy::TEmulatedMapProxy
TEmulatedMapProxy(const TEmulatedMapProxy &copy)
Definition: TEmulatedMapProxy.cxx:39
TGenCollectionProxy::StreamHelper::read_tstring_pointer
void read_tstring_pointer(Bool_t vsn3, TBuffer &b)
Definition: TGenCollectionProxy.h:167
TVirtualCollectionProxy
Definition: TVirtualCollectionProxy.h:38
int
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
TError.h