Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
30Streamer around a map container. For optimization reasons this functionality
31is 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
48TEmulatedMapProxy::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
214void 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}
double
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
const Bool_t kFALSE
Definition RtypesCore.h:101
@ kNoType_t
Definition TDataType.h:33
@ kFloat_t
Definition TDataType.h:31
@ kULong64_t
Definition TDataType.h:32
@ kInt_t
Definition TDataType.h:30
@ kchar
Definition TDataType.h:31
@ kLong_t
Definition TDataType.h:30
@ kDouble32_t
Definition TDataType.h:31
@ kShort_t
Definition TDataType.h:29
@ kBool_t
Definition TDataType.h:32
@ kULong_t
Definition TDataType.h:30
@ kLong64_t
Definition TDataType.h:32
@ kUShort_t
Definition TDataType.h:29
@ kDouble_t
Definition TDataType.h:31
@ kChar_t
Definition TDataType.h:29
@ kUChar_t
Definition TDataType.h:29
@ kUInt_t
Definition TDataType.h:30
@ kFloat16_t
Definition TDataType.h:33
@ kOther_t
Definition TDataType.h:32
@ kIsPointer
Definition TDictionary.h:78
@ kIsClass
Definition TDictionary.h:65
@ kIsEnum
Definition TDictionary.h:68
@ kIsFundamental
Definition TDictionary.h:70
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
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
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
Streamer around an arbitrary STL like container, which implements basic container functionality.
virtual void Resize(UInt_t n, Bool_t force_delete)
Resize the container.
Streamer around a map container.
virtual void * At(UInt_t idx)
Return the address of the value at index 'idx'.
void ReadMap(UInt_t nElements, TBuffer &b)
virtual UInt_t Size() const
Return the current size of the container.
virtual void ReadBuffer(TBuffer &buff, void *pObj)
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
virtual TVirtualCollectionProxy * Generate() const
Virtual copy constructor.
TEmulatedMapProxy(const TEmulatedMapProxy &copy)
void WriteMap(UInt_t nElements, TBuffer &b)
int fValOffset
Offset from key to value (in maps)
EnvironBase_t * fEnv
Address of the currently proxied object.
TGenCollectionProxy * Initialize(Bool_t silent) const
Proxy initializer.
std::string fName
Name of the class being proxied.
int fSTL_type
STL container type.
Value * fKey
Descriptor of the key_type.
Value * fVal
Descriptor of the Value_type.
virtual void SetOnFileClass(TClass *cl)
int fValDiff
Offset between two consecutive value_types (memory layout).
Basic string class.
Definition TString.h:136
@ kSTLmap
Definition ESTLType.h:33
@ kSTLmultimap
Definition ESTLType.h:34
Small helper to describe the Value_type or the key_type of an STL container.
Helper class to facilitate I/O.
void read_tstring_pointer(Bool_t vsn3, TBuffer &b)