inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_wroot_element 00005 #define inlib_wroot_element 00006 00007 #include "buffer" 00008 #include "named" 00009 00010 namespace inlib { 00011 namespace wroot { 00012 00013 namespace streamer_info { 00014 00015 enum Type { // sizeof : 00016 BASE = 0, // x 00017 ARRAY = 20, // ? 00018 POINTER = 40, // 4 00019 POINTER_INT = 43, // 4 00020 POINTER_FLOAT = 45, // 4 00021 POINTER_DOUBLE = 48, // 4 00022 COUNTER = 6, // 4 00023 CHAR = 1, // 1 00024 SHORT = 2, // 2 00025 INT = 3, // 4 00026 FLOAT = 5, // 4 00027 DOUBLE = 8, // 8 00028 UNSIGNED_CHAR = 11, // 1 00029 UNSIGNED_SHORT = 12, // 2 00030 UNSIGNED_INT = 13, // 4 00031 BOOL = 18, // 1 ? 00032 OBJECT = 61, // ? 00033 OBJECT_ANY = 62, // ? 00034 OBJECT_ARROW = 63, // ? 00035 OBJECT_POINTER = 64, // ? 00036 TSTRING = 65, // 8 00037 TOBJECT = 66, // 12 00038 TNAMED = 67 // 28 00039 }; 00040 } 00041 00042 00043 class streamer_element : public virtual ibo { 00044 static const std::string& s_class() { 00045 static const std::string s_v("inlib::wroot::streamer_element"); 00046 return s_v; 00047 } 00048 public: //ibo 00049 virtual const std::string& store_cls() const { 00050 static const std::string s_v("TStreamerElement"); 00051 return s_v; 00052 } 00053 virtual bool stream(buffer& aBuffer) const { 00054 unsigned int c; 00055 if(!aBuffer.write_version(2,c)) return false; 00056 if(!Named_stream(aBuffer,fName,fTitle)) return false; 00057 if(!aBuffer.write(fType)) return false; 00058 if(!aBuffer.write(fSize)) return false; 00059 if(!aBuffer.write(fArrayLength)) return false; 00060 if(!aBuffer.write(fArrayDim)) return false; 00061 if(!aBuffer.write_fast_array<int>(fMaxIndex,5)) return false; 00062 if(!aBuffer.write(fTypeName)) return false; 00063 if(!aBuffer.set_byte_count(c)) return false; 00064 return true; 00065 } 00066 public: 00067 virtual streamer_element* copy() const = 0; 00068 public: 00069 virtual void out(std::ostream& aOut) const { 00070 char s[128]; 00071 #ifdef WIN32 00072 _snprintf(s,sizeof(s)," %-14s%-15s offset=%3d type=%2d %-20s",fTypeName.c_str(),fullName().c_str(),fOffset,fType,fTitle.c_str()); 00073 #else 00074 ::snprintf(s,sizeof(s)," %-14s%-15s offset=%3d type=%2d %-20s",fTypeName.c_str(),fullName().c_str(),fOffset,fType,fTitle.c_str()); 00075 #endif 00076 aOut << s << std::endl; 00077 } 00078 public: 00079 streamer_element(const std::string& aName,const std::string& aTitle, 00080 int aOffset,int aType,const std::string& aTypeName) 00081 :fName(aName),fTitle(aTitle),fType(aType) 00082 ,fSize(0),fArrayLength(0),fArrayDim(0),fOffset(aOffset) 00083 ,fTypeName(aTypeName){ 00084 #ifdef INLIB_MEM 00085 mem::increment(s_class().c_str()); 00086 #endif 00087 for(int i=0;i<5;i++) fMaxIndex[i] = 0; 00088 } 00089 virtual ~streamer_element(){ 00090 #ifdef INLIB_MEM 00091 mem::decrement(s_class().c_str()); 00092 #endif 00093 } 00094 protected: 00095 streamer_element(const streamer_element& a_from) 00096 :ibo(a_from) 00097 ,fName(a_from.fName),fTitle(a_from.fTitle) 00098 ,fType(a_from.fType),fSize(a_from.fSize) 00099 ,fArrayLength(a_from.fArrayLength) 00100 ,fArrayDim(a_from.fArrayDim),fOffset(a_from.fOffset) 00101 ,fTypeName(a_from.fTypeName){ 00102 #ifdef INLIB_MEM 00103 mem::increment(s_class().c_str()); 00104 #endif 00105 for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i]; 00106 } 00107 streamer_element& operator=(const streamer_element& a_from){ 00108 fName = a_from.fName; 00109 fTitle = a_from.fTitle; 00110 fType = a_from.fType; 00111 fSize = a_from.fSize; 00112 fArrayLength = a_from.fArrayLength; 00113 fArrayDim = a_from.fArrayDim; 00114 fOffset = a_from.fOffset; 00115 fTypeName = a_from.fTypeName; 00116 for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i]; 00117 return *this; 00118 } 00119 public: 00120 virtual void setArrayDimension(int aDimension){ 00121 fArrayDim = aDimension; 00122 if(aDimension) fType += streamer_info::ARRAY; 00123 //fNewType = fType; 00124 } 00125 virtual void setMaxIndex(int aDimension,int aMaximum){ 00126 //set maximum index for array with dimension dim 00127 if (aDimension < 0 || aDimension > 4) return; 00128 fMaxIndex[aDimension] = aMaximum; 00129 if (fArrayLength == 0) fArrayLength = aMaximum; 00130 else fArrayLength *= aMaximum; 00131 } 00132 00133 virtual std::string fullName() const { 00134 std::string s = fName; 00135 for (int i=0;i<fArrayDim;i++) { 00136 char cdim[32]; 00137 #ifdef WIN32 00138 _snprintf(cdim,sizeof(cdim),"[%d]",fMaxIndex[i]); 00139 #else 00140 ::snprintf(cdim,sizeof(cdim),"[%d]",fMaxIndex[i]); 00141 #endif 00142 s += cdim; 00143 } 00144 return s; 00145 } 00146 protected: //Named 00147 std::string fName; 00148 std::string fTitle; 00149 protected: 00150 int fType; //element type 00151 int fSize; //sizeof element 00152 int fArrayLength; //cumulative size of all array dims 00153 int fArrayDim; //number of array dimensions 00154 int fMaxIndex[5]; //Maximum array index for array dimension "dim" 00155 int fOffset; 00156 //FIXME Int_t fNewType; //!new element type when reading 00157 std::string fTypeName; //Data type name of data member 00158 }; 00159 00160 class streamer_base : public streamer_element { 00161 public: //ibo 00162 virtual const std::string& store_cls() const { 00163 static const std::string s_v("TStreamerBase"); 00164 return s_v; 00165 } 00166 virtual bool stream(buffer& aBuffer) const { 00167 unsigned int c; 00168 if(!aBuffer.write_version(3,c)) return false; 00169 if(!streamer_element::stream(aBuffer)) return false; 00170 if(!aBuffer.write(fBaseVersion)) return false; 00171 if(!aBuffer.set_byte_count(c)) return false; 00172 return true; 00173 } 00174 public: //streamer_element 00175 virtual streamer_element* copy() const {return new streamer_base(*this);} 00176 public: 00177 streamer_base(const std::string& aName,const std::string& aTitle, 00178 int aOffset,int aBaseVersion) 00179 :streamer_element(aName,aTitle,aOffset,streamer_info::BASE,"BASE") 00180 ,fBaseVersion(aBaseVersion){ 00181 if (aName=="TObject") fType = streamer_info::TOBJECT; 00182 if (aName=="TNamed") fType = streamer_info::TNAMED; 00183 } 00184 virtual ~streamer_base(){} 00185 public: 00186 streamer_base(const streamer_base& a_from) 00187 :ibo(a_from) 00188 ,streamer_element(a_from) 00189 ,fBaseVersion(a_from.fBaseVersion) 00190 {} 00191 streamer_base& operator=(const streamer_base& a_from){ 00192 streamer_element::operator=(a_from); 00193 fBaseVersion = a_from.fBaseVersion; 00194 return *this; 00195 } 00196 protected: 00197 int fBaseVersion; //version number of the base class 00198 }; 00199 00200 class streamer_basic_type : public streamer_element { 00201 public: //ibo 00202 virtual const std::string& store_cls() const { 00203 static const std::string s_v("TStreamerBasicType"); 00204 return s_v; 00205 } 00206 virtual bool stream(buffer& aBuffer) const { 00207 unsigned int c; 00208 if(!aBuffer.write_version(2,c)) return false; 00209 if(!streamer_element::stream(aBuffer)) return false; 00210 if(!aBuffer.set_byte_count(c)) return false; 00211 return true; 00212 } 00213 public: //streamer_element 00214 virtual streamer_element* copy() const { 00215 return new streamer_basic_type(*this); 00216 } 00217 public: 00218 streamer_basic_type(const std::string& aName,const std::string& aTitle, 00219 int aOffset,int aType,const std::string& aTypeName) 00220 :streamer_element(aName,aTitle,aOffset,aType,aTypeName) 00221 {} 00222 virtual ~streamer_basic_type(){} 00223 public: 00224 streamer_basic_type(const streamer_basic_type& a_from) 00225 :ibo(a_from),streamer_element(a_from) 00226 {} 00227 streamer_basic_type& operator=(const streamer_basic_type& a_from){ 00228 streamer_element::operator=(a_from); 00229 return *this; 00230 } 00231 }; 00232 00233 class streamer_basic_pointer : public streamer_element { 00234 public: //ibo 00235 virtual const std::string& store_cls() const { 00236 static const std::string s_v("TStreamerBasicPointer"); 00237 return s_v; 00238 } 00239 virtual bool stream(buffer& aBuffer) const { 00240 unsigned int c; 00241 if(!aBuffer.write_version(2,c)) return false; 00242 if(!streamer_element::stream(aBuffer)) return false; 00243 if(!aBuffer.write(fCountVersion)) return false; 00244 if(!aBuffer.write(fCountName)) return false; 00245 if(!aBuffer.write(fCountClass)) return false; 00246 if(!aBuffer.set_byte_count(c)) return false; 00247 return true; 00248 } 00249 public: //streamer_element 00250 virtual streamer_element* copy() const { 00251 return new streamer_basic_pointer(*this); 00252 } 00253 public: 00254 streamer_basic_pointer(const std::string& aName,const std::string& aTitle, 00255 int aOffset,int aType, 00256 const std::string& aCountName, 00257 const std::string& aCountClass, 00258 int aCountVersion, 00259 const std::string& aTypeName) 00260 :streamer_element(aName,aTitle,aOffset, 00261 aType+streamer_info::POINTER,aTypeName) 00262 ,fCountVersion(aCountVersion) 00263 ,fCountName(aCountName) 00264 ,fCountClass(aCountClass) 00265 {} 00266 virtual ~streamer_basic_pointer(){} 00267 public: 00268 streamer_basic_pointer(const streamer_basic_pointer& a_from) 00269 :ibo(a_from),streamer_element(a_from) 00270 ,fCountVersion(a_from.fCountVersion) 00271 ,fCountName(a_from.fCountName) 00272 ,fCountClass(a_from.fCountClass) 00273 {} 00274 streamer_basic_pointer& operator=(const streamer_basic_pointer& a_from){ 00275 streamer_element::operator=(a_from); 00276 fCountVersion = a_from.fCountVersion; 00277 fCountName = a_from.fCountName; 00278 fCountClass = a_from.fCountClass; 00279 return *this; 00280 } 00281 protected: 00282 int fCountVersion; //version number of the class with the counter 00283 std::string fCountName; //name of data member holding the array count 00284 std::string fCountClass; //name of the class with the counter 00285 }; 00286 00287 class streamer_string : public streamer_element { 00288 public: //ibo 00289 virtual const std::string& store_cls() const { 00290 static const std::string s_v("TStreamerString"); 00291 return s_v; 00292 } 00293 virtual bool stream(buffer& aBuffer) const { 00294 unsigned int c; 00295 if(!aBuffer.write_version(2,c)) return false; 00296 if(!streamer_element::stream(aBuffer)) return false; 00297 if(!aBuffer.set_byte_count(c)) return false; 00298 return true; 00299 } 00300 public: //streamer_element 00301 virtual streamer_element* copy() const { 00302 return new streamer_string(*this); 00303 } 00304 public: 00305 streamer_string(const std::string& aName,const std::string& aTitle, 00306 int aOffset) 00307 :streamer_element(aName,aTitle,aOffset,streamer_info::TSTRING,"TString") 00308 {} 00309 virtual ~streamer_string(){} 00310 public: 00311 streamer_string(const streamer_string& a_from) 00312 :ibo(a_from),streamer_element(a_from) 00313 {} 00314 streamer_string& operator=(const streamer_string& a_from){ 00315 streamer_element::operator=(a_from); 00316 return *this; 00317 } 00318 }; 00319 00320 00321 class streamer_object : public streamer_element { 00322 public: //ibo 00323 virtual const std::string& store_cls() const { 00324 static const std::string s_v("TStreamerObject"); 00325 return s_v; 00326 } 00327 virtual bool stream(buffer& aBuffer) const { 00328 unsigned int c; 00329 if(!aBuffer.write_version(2,c)) return false; 00330 if(!streamer_element::stream(aBuffer)) return false; 00331 if(!aBuffer.set_byte_count(c)) return false; 00332 return true; 00333 } 00334 public: //streamer_element 00335 virtual streamer_element* copy() const { 00336 return new streamer_object(*this); 00337 } 00338 public: 00339 streamer_object(const std::string& aName,const std::string& aTitle, 00340 int aOffset,const std::string& aTypeName) 00341 :streamer_element(aName,aTitle,aOffset,0,aTypeName){ 00342 fType = streamer_info::OBJECT; 00343 if (aName=="TObject") fType = streamer_info::TOBJECT; 00344 if (aName=="TNamed") fType = streamer_info::TNAMED; 00345 } 00346 virtual ~streamer_object(){} 00347 public: 00348 streamer_object(const streamer_object& a_from) 00349 :ibo(a_from),streamer_element(a_from){} 00350 streamer_object& operator=(const streamer_object& a_from){ 00351 streamer_element::operator=(a_from); 00352 return *this; 00353 } 00354 }; 00355 00356 class streamer_object_pointer : public streamer_element { 00357 public: //ibo 00358 virtual const std::string& store_cls() const { 00359 static const std::string s_v("TStreamerObjectPointer"); 00360 return s_v; 00361 } 00362 virtual bool stream(buffer& aBuffer) const { 00363 unsigned int c; 00364 if(!aBuffer.write_version(2,c)) return false; 00365 if(!streamer_element::stream(aBuffer)) return false; 00366 if(!aBuffer.set_byte_count(c)) return false; 00367 return true; 00368 } 00369 public: //streamer_element 00370 virtual streamer_element* copy() const { 00371 return new streamer_object_pointer(*this); 00372 } 00373 public: 00374 streamer_object_pointer(const std::string& aName,const std::string& aTitle, 00375 int aOffset,const std::string& aTypeName) 00376 :streamer_element(aName,aTitle,aOffset, 00377 streamer_info::OBJECT_POINTER,aTypeName){ 00378 if(aTitle.substr(0,2)=="->") fType = streamer_info::OBJECT_ARROW; 00379 } 00380 virtual ~streamer_object_pointer(){} 00381 public: 00382 streamer_object_pointer(const streamer_object_pointer& a_from) 00383 :ibo(a_from),streamer_element(a_from){} 00384 streamer_object_pointer& operator=(const streamer_object_pointer& a_from){ 00385 streamer_element::operator=(a_from); 00386 return *this; 00387 } 00388 }; 00389 00390 class streamer_object_any : public streamer_element { 00391 public: //ibo 00392 virtual const std::string& store_cls() const { 00393 static const std::string s_v("TStreamerObjectAny"); 00394 return s_v; 00395 } 00396 virtual bool stream(buffer& aBuffer) const { 00397 unsigned int c; 00398 if(!aBuffer.write_version(2,c)) return false; 00399 if(!streamer_element::stream(aBuffer)) return false; 00400 if(!aBuffer.set_byte_count(c)) return false; 00401 return true; 00402 } 00403 public: //streamer_element 00404 virtual streamer_element* copy() const { 00405 return new streamer_object_any(*this); 00406 } 00407 public: 00408 streamer_object_any(const std::string& aName,const std::string& aTitle, 00409 int aOffset,const std::string& aTypeName) 00410 :streamer_element(aName,aTitle,aOffset,streamer_info::OBJECT_ANY,aTypeName) 00411 {} 00412 virtual ~streamer_object_any(){} 00413 public: 00414 streamer_object_any(const streamer_object_any& a_from) 00415 :ibo(a_from),streamer_element(a_from){} 00416 streamer_object_any& operator=(const streamer_object_any& a_from){ 00417 streamer_element::operator=(a_from); 00418 return *this; 00419 } 00420 }; 00421 00422 00423 class streamer_STL : public streamer_element { 00424 public: //ibo 00425 virtual const std::string& store_cls() const { 00426 static const std::string s_v("TStreamerSTL"); 00427 return s_v; 00428 } 00429 virtual bool stream(buffer& aBuffer) const { 00430 unsigned int c; 00431 if(!aBuffer.write_version(2,c)) return false; 00432 if(!streamer_element::stream(aBuffer)) return false; 00433 if(!aBuffer.write(fSTLtype)) return false; 00434 if(!aBuffer.write(fCtype)) return false; 00435 if(!aBuffer.set_byte_count(c)) return false; 00436 return true; 00437 } 00438 public: //streamer_element 00439 virtual streamer_element* copy() const { 00440 return new streamer_STL(*this); 00441 } 00442 protected: 00443 enum ESTLtype { kSTL = 300, kSTLstring =365, kSTLvector = 1, 00444 kSTLlist = 2, kSTLdeque = 3, kSTLmap = 4, 00445 kSTLset = 5, kSTLmultimap=6, kSTLmultiset=7}; 00446 00447 // Instead of EDataType, we use the Streamer_Info::Type. 00448 //enum EDataType { 00449 // kChar_t = 1, kUChar_t = 11, kShort_t = 2, kUShort_t = 12, 00450 // kInt_t = 3, kUInt_t = 13, kLong_t = 4, kULong_t = 14, 00451 // kFloat_t = 5, kDouble_t = 8, kchar = 10, kOther_t = -1 00452 //}; 00453 public: 00454 streamer_STL(const std::string& aName,const std::string& aTitle, 00455 int aOffset, 00456 streamer_info::Type aType, //Must match TDataType/EDataType 00457 const std::string& aTypeName) 00458 :streamer_element(aName,aTitle,aOffset,kSTL,aTypeName){ 00459 fSTLtype = kSTLvector; 00460 fCtype = aType; 00461 } 00462 virtual ~streamer_STL(){} 00463 public: 00464 streamer_STL(const streamer_STL& a_from) 00465 :ibo(a_from),streamer_element(a_from) 00466 ,fSTLtype(a_from.fSTLtype) 00467 ,fCtype(a_from.fCtype) 00468 {} 00469 streamer_STL& operator=(const streamer_STL& a_from){ 00470 streamer_element::operator=(a_from); 00471 fSTLtype = a_from.fSTLtype; 00472 fCtype = a_from.fCtype; 00473 return *this; 00474 } 00475 protected: 00476 int fSTLtype; //type of STL vector 00477 int fCtype; //STL contained type 00478 }; 00479 00480 }} 00481 00482 #endif