Changeset 2459 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Nov 22, 2003, 6:45:23 PM (22 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/basetools.h
r1620 r2459 14 14 #include "sophyainit.h" 15 15 #include "ppersist.h" 16 #include "ppfnametag.h" 16 17 #include "ndatablock.h" 17 18 #include "anydataobj.h" -
trunk/SophyaLib/BaseTools/ppersist.cc
r2441 r2459 347 347 //-- 348 348 { 349 if (!s.Goto Tag(tag))349 if (!s.GotoNameTag(tag)) 350 350 throw NotFoundExc("PPersist::ReadAtTag tag not found"); 351 351 Read(s); … … 401 401 //-- 402 402 { 403 s = new ifstream(flnm.c_str(),ios::in | IOS_BIN);403 s = new RawInFileStream(flnm.c_str()); 404 404 405 405 // Read and check header … … 444 444 filename = flnm; // keep the filename 445 445 seqread = true; // To flag non sequential reads 446 if (scan ) Scan();446 if (scan && s->isSeekable()) Scan(); 447 447 } 448 448 … … 472 472 473 473 unsigned char ppstype; 474 size_t debut; 475 #ifdef STREAMPOS_IS_CLASS 476 debut = s->tellg().offset(); 477 #else 474 int_8 debut; 478 475 debut = s->tellg(); 479 #endif 480 481 // Find tag entries at end of file 482 // if (defined(Linux) || defined(Darwin)) && defined(__GNUG__) && (__GNUC__ < 3) 483 #if defined(__GNUG__) && (__GNUC__ < 3) 484 // There seems to be a bug where seekg with ios::end under Linux with g++ 485 // prior to version gcc 3.1 486 // The bug seems to be there also with Darwin/MacOSX 487 // So, we use seek with ios::beg 488 s->seekg(0, ios::end); 489 int_8 tagpos = s->tellg() - (sizeof(int_8)+1); 490 s->seekg(tagpos, ios::beg); 491 #else 476 492 477 s->seekg(-(sizeof(int_8)+1), ios::end); 493 #endif494 478 495 479 GetTypeTag(ppstype); … … 499 483 int_8 pos; 500 484 GetRawI8(pos); 501 #if defined(Darwin)502 // Septembre 2003 - Reza : Pb avec MacOSX 10.2503 // Sur MacOSX (10.2, g++ 3.1), la lecture du dernier byte du flot cause504 // une erreur, et le flot ne se repositionne plus505 // On ferme le flot et on le rouvre ...506 delete s;507 s = new ifstream(FileName().c_str(), ios::in | IOS_BIN);508 #endif509 485 if (pos < 0) { // no tags 510 486 s->seekg(debut); … … 536 512 537 513 int 538 PInPersist::Nb Tags()514 PInPersist::NbNameTags() 539 515 { 540 516 return tags.size(); … … 567 543 568 544 bool 569 PInPersist::Goto TagNum(int itag)545 PInPersist::GotoNameTagNum(int itag) 570 546 { 571 547 if (itag<0 || itag >= (int)tags.size()) return false; … … 601 577 static vector<string> * ret_tag_names = NULL; 602 578 vector<string> const & 603 PInPersist::Get TagNames()579 PInPersist::GetNameTags() 604 580 { 605 581 if (ret_tag_names) delete ret_tag_names; … … 608 584 for(i=tags.begin(); i!=tags.end(); i++) ret_tag_names->push_back((*i).first); 609 585 return(*ret_tag_names); 586 } 587 588 bool 589 PInPersist::SkipToNextObject() 590 { 591 // A FAIRE NOV 2003 - REZA 592 return true; 610 593 } 611 594 … … 1087 1070 PInPersist::GetObject(AnyDataObj & o, string tagname) 1088 1071 { 1089 Goto Tag(tagname);1072 GotoNameTag(tagname); 1090 1073 GetPPObject(&o); 1091 1074 return; … … 1147 1130 unsigned char ppstag=0; 1148 1131 unsigned char ppst1,ppst2,ppst3,ppst30; 1149 uint_8 cpos,fsize;1132 int_8 cpos,fsize; 1150 1133 uint_8 ui8,cid,oid; 1151 1134 int_4 i4; … … 1158 1141 1159 1142 1160 #ifdef STREAMPOS_IS_CLASS1161 cpos = s->tellg().offset();1162 #else1163 1143 cpos = s->tellg(); 1164 #endif1165 1144 s->seekg(0,ios::end); 1166 #ifdef STREAMPOS_IS_CLASS1167 fsize = s->tellg().offset();1168 #else1169 1145 fsize = s->tellg(); 1170 #endif1171 1146 s->seekg(cpos,ios::beg); 1172 1147 … … 1178 1153 1179 1154 while ( (ppstag != PPS_EOF) && (cpos < fsize) ) { 1180 #ifdef STREAMPOS_IS_CLASS 1181 cpos = s->tellg().offset(); 1182 #else 1183 cpos = s->tellg(); 1184 #endif 1155 cpos = s->tellg(); 1185 1156 GetRawUByte(ppstag); 1186 1157 totntags++; … … 1293 1264 if (lev > 0) cout << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec 1294 1265 << " DataType=" << dtype << " NElts= " << i4 << endl; 1295 s->seekg(( uint_8)dsizeskip*(uint_8)i4, ios::cur);1266 s->seekg((int_8)dsizeskip*(int_8)i4, ios::cur); 1296 1267 break; 1297 1268 … … 1300 1271 if (lev > 0) cout << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec 1301 1272 << " DataType=" << dtype << " NElts= " << ui8 << endl; 1302 s->seekg(( uint_8)dsizeskip*ui8, ios::cur);1273 s->seekg((int_8)dsizeskip*ui8, ios::cur); 1303 1274 break; 1304 1275 } … … 1334 1305 // Let's try to read it 1335 1306 int_8 cpos; 1336 #ifdef STREAMPOS_IS_CLASS1337 cpos = s->tellg().offset();1338 #else1339 1307 cpos = s->tellg(); 1340 #endif1341 1308 s->seekg(pos); 1342 1309 PPersist* ppo = ReadObject(); … … 1359 1326 // cerr << " DBG - PInPersist::KeepOId() " << oid << endl; 1360 1327 if ((objList.size() > 0) && (objList.find(oid) != objList.end()) ) { 1361 // Ceci ne devrait arriver que si on lit dans le desordre (avec Goto Tag)1328 // Ceci ne devrait arriver que si on lit dans le desordre (avec GotoNameTag) 1362 1329 // et pas avec une lecture sequentielle ... Reza 03/2000 1363 1330 // cerr << "PInPersist::KeepOId()/Warning - already present PPS_ObjectId ! " << oid << endl; … … 1401 1368 pps_OId = 0; 1402 1369 // Output stream creation 1403 s = new ofstream(flnm.c_str(),ios::out | IOS_BIN);1370 s = new RawOutFileStream(flnm.c_str()); 1404 1371 version = 3; 1405 1372 // Header … … 1426 1393 } else { 1427 1394 int_8 tagPos; 1428 #ifdef STREAMPOS_IS_CLASS1429 tagPos = s->tellp().offset();1430 #else1431 1395 tagPos = s->tellp(); 1432 #endif1433 1396 for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) { 1434 1397 string name = (*i).first; … … 1450 1413 { 1451 1414 int_8 tagpos; 1452 #ifdef STREAMPOS_IS_CLASS1453 tagpos = s->tellp().offset();1454 #else1455 1415 tagpos = s->tellp(); 1456 #endif1457 1416 PutRawByte(PPS_POSTAG_MARK); 1458 1417 PutI8(tagpos); … … 1471 1430 // Get current file position 1472 1431 int_8 tagPos; 1473 1474 #ifdef STREAMPOS_IS_CLASS1475 tagPos = s->tellp().offset();1476 #else1477 1432 tagPos = s->tellp(); 1478 #endif1479 1433 1480 1434 tags[name] = tagPos; … … 2011 1965 objreftag rt; 2012 1966 rt.ppsoid = id; 2013 #ifdef STREAMPOS_IS_CLASS2014 rt.ppspos = s->tellp().offset();2015 #else2016 1967 rt.ppspos = s->tellp(); 2017 #endif2018 1968 objList[mid] = rt; 2019 1969 } -
trunk/SophyaLib/BaseTools/ppersist.h
r2441 r2459 13 13 #include "pexceptions.h" 14 14 #include "gnumd5.h" 15 #include "rawstream.h" 15 16 16 17 … … 39 40 public: 40 41 virtual ~PPersist() {} 41 // J'ajoute cette fonction pour assurer la compatibilite42 // avec l'ancien PPersist d'Eros (Reza 23/04/99)43 virtual int_4 ClassId() const { return(0); }44 42 45 43 void Write(string const& fn) const; … … 116 114 PPS_NAMETAG_MARK = 7, // To have a name tag, position marker in a file 117 115 PPS_POSTAG_MARK = 8, // Position tag mark + 8 bytes (=stream position) 118 PPS_POSTAG_TABLE = 40,// Position tag table + 8 bytes (=stream position)116 PPS_POSTAG_TABLE = 9, // Position tag table + 8 bytes (=stream position) 119 117 PPS_SIMPLE = 16, // 16 + number of bytes, up to 8 bytes 120 118 PPS_SIMPLE_ARRAY4 = 32, // 32 + number of bytes, up to 8 bytes, then 4 bytes of length … … 146 144 bool GotoPositionTag(int_8 pos); 147 145 bool GotoNameTag(string const& name); 148 inline bool GotoTag(string const& name) { return GotoNameTag(name); } 149 int NbTags(); 150 bool GotoTagNum(int itag); // 0..NbTags-1 146 int NbNameTags(); 147 bool GotoNameTagNum(int itag); // 0..NbTags-1 151 148 string GetTagName(int itag); // 0..NbTags-1 152 149 string GetTagClassName(int itag); // 0..NbTags-1 153 vector<string> const & GetTagNames(); 150 vector<string> const & GetNameTags(); 151 152 // Saut jusqu'au prochain objet 153 bool SkipToNextObject(); 154 154 155 155 // Lecture donnees de base et tableaux de donnees de base … … 247 247 void Scan(); 248 248 249 istream* s;249 RawInOutStream* s; 250 250 251 251 bool bigEndian; … … 342 342 343 343 protected: 344 ostream* s;344 RawInOutStream* s; 345 345 bool bigEndian; 346 346 -
trunk/SophyaLib/BaseTools/rawstream.cc
r2458 r2459 161 161 : RawInOutStream() 162 162 { 163 fip = fopen(path.c_str()," rb");163 fip = fopen(path.c_str(),"wb"); 164 164 if (fip == NULL) { 165 165 string errmsg = "RawOutFileStream() - fopen(wb) ERROR - File= "; -
trunk/SophyaLib/BaseTools/sversion.h
r2441 r2459 3 3 4 4 #define SOPHYA_VERSION 1.8 5 #define SOPHYA_REVISION 05 #define SOPHYA_REVISION 1 6 6 #define SOPHYA_TAG "V_Oct2003" 7 7
Note:
See TracChangeset
for help on using the changeset viewer.