Changeset 588 in Sophya
- Timestamp:
- Nov 17, 1999, 4:47:03 PM (26 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ppersist.cc
r582 r588 36 36 MD5_CTX PIOPersist::ctx; 37 37 PIOPersist::ClassList * PIOPersist::classList = NULL; // $CHECK$ Reza 26/04/99 38 map<string, uint_8> * PIOPersist::typeids = NULL; 38 39 39 40 //++ … … 44 45 { 45 46 classList = new PIOPersist::ClassList; 46 } 47 48 //++ 49 void 50 PIOPersist::RegisterClass(uint_8 classId, ClassCreatorFunc f) 47 typeids = new map<string, uint_8>; 48 } 49 50 //++ 51 void 52 PIOPersist::RegisterClass(uint_8 classId, string typname, ClassCreatorFunc f) 51 53 // 52 54 // Register a new persistant class. … … 64 66 65 67 (*classList)[classId] = f; 68 (*typeids)[typname] = classId; 66 69 } 67 70 … … 154 157 // Check tag value 155 158 char ppstype; 156 s.Get RawByte(ppstype);159 s.GetTypeTag(ppstype); 157 160 if (ppstype != PInPersist::PPS_OBJECT) { 158 161 throw FileFormatExc("PPersist::Read : not an object in flow"); … … 162 165 uint_8 classId; 163 166 s.GetRawU8(classId); 164 if (classId != PIOPersist::Hash(typeid(*this).name())) { 167 uint_8 myClassId = PIOPersist::getTypeId(typeid(*this).name()); 168 if (classId != myClassId) { 165 169 throw FileFormatExc("PPersist::Read : not the same object type"); 166 170 } … … 274 278 // Find tag entries at end of file 275 279 s->seekg(-(sizeof(int_8)+1), ios::end); 276 Get RawByte(ppstype);280 GetTypeTag(ppstype); 277 281 if (ppstype != PPS_EOF) 278 282 throw FileFormatExc("PInPersist::Scan corrupted file, no eof entry at end of file"); … … 288 292 s->seekg(pos); 289 293 while (true) { 290 Get RawByte(ppstype);294 GetTypeTag(ppstype); 291 295 if (ppstype == PPS_EOF) break; 292 296 … … 322 326 // throw NotFoundExc("PInPersist::GotoTag tag not found"); 323 327 s->seekg((*i).second); 328 objList.clear(); // $CHECK$ EA 171199 324 329 return(true); 325 330 } … … 332 337 for (int j=0; j<itag; j++) i++; 333 338 s->seekg((*i).second); 339 objList.clear(); // $CHECK$ EA 171199 334 340 return(true); 335 341 } … … 410 416 } 411 417 418 void 419 PInPersist::GetTypeTag(char& c) 420 { 421 GetRawByte(c); 422 while (c == PPS_TAG_MARK) { 423 objList.clear(); 424 GetRawByte(c); 425 } 426 } 427 412 428 413 429 void … … 459 475 { 460 476 char ppstype; 461 Get RawByte(ppstype);477 GetTypeTag(ppstype); 462 478 if (ppstype != PPS_SIMPLE + datasz) 463 479 throw FileFormatExc("PInPersist::CheckTag bad type in ppersist file"); … … 468 484 { 469 485 char ppstype; 470 Get RawByte(ppstype);486 GetTypeTag(ppstype); 471 487 size_t filesz; 472 488 if (sz <= 0x7fff) { … … 686 702 { 687 703 char ppstype; 688 Get RawByte(ppstype);704 GetTypeTag(ppstype); 689 705 if (ppstype != PPS_LINE) 690 706 throw FileFormatExc("PInPersist::GetLine bad type in ppersist file"); … … 696 712 { 697 713 char ppstype; 698 Get RawByte(ppstype);714 GetTypeTag(ppstype); 699 715 if (ppstype != PPS_STRING) 700 716 throw FileFormatExc("PInPersist::GetLine bad type in ppersist file"); … … 713 729 // Get tag 714 730 char ppstype; 715 Get RawByte(ppstype);731 GetTypeTag(ppstype); 716 732 if (ppstype != PPS_OBJECT && ppstype != PPS_REFERENCE && ppstype != PPS_NULL) { 717 733 throw FileFormatExc("PInPersist::ReadObject : not an object in flow"); … … 741 757 GetRawI4(id); 742 758 if (id <0 || id>=objList.size()) { 743 throw FileFormatExc("PInPersist::ReadObject invalid object id for reference"); 759 char msg[200]; 760 sprintf(msg, "PInPersist::ReadObject invalid object id for reference: %d/%d",id,objList.size()); 761 throw FileFormatExc(msg); 744 762 } 745 763 return objList[id]; … … 843 861 844 862 tags[name] = tagPos; 863 PutRawByte(PPS_TAG_MARK); // This is a tag 864 objList.clear(); // $CHECK$ EA 171199 845 865 } 846 866 … … 1193 1213 1194 1214 PutRawByte(PPS_OBJECT); 1195 PutRawU8(PIOPersist::Hash(typeid(*obj).name())); 1215 PutRawU8(getTypeId(typeid(*obj).name())); 1216 //PutRawU8(PIOPersist::Hash(typeid(*obj).name())); 1196 1217 assignObjectId(obj); 1197 1218 obj->WriteSelf(*this); -
trunk/SophyaLib/BaseTools/ppersist.h
r582 r588 69 69 typedef PPersist* (*ClassCreatorFunc)(); 70 70 71 static void RegisterClass(uint_8 classId, ClassCreatorFunc f);71 static void RegisterClass(uint_8 classId, string typname, ClassCreatorFunc f); 72 72 static ClassCreatorFunc FindCreatorFunc(uint_8 classId); 73 73 static uint_8 Hash(string const& typname) { … … 80 80 81 81 static void Initialize(); // Pour initialiser classList 82 static uint_8 getTypeId(string s) {return (*typeids)[s];} 82 83 private: 83 84 … … 85 86 // Pas de createur appele pour objets statiques sur Linux - $CHECK$ Reza 26/04/99 86 87 static ClassList * classList; 88 static map<string, uint_8> * typeids; 87 89 88 90 protected: 91 89 92 enum {PPS_NULL = 0, // this is a null object 90 93 PPS_STRING = 1, // string, length (2b) + data … … 94 97 PPS_EOF = 5, // Just before tag infomation, offset to PPS_TAG 95 98 PPS_LINE = 6, // '\n'-terminated, deprecated ? 99 PPS_TAG_MARK = 7, // to reset object count when skipped 96 100 PPS_SIMPLE = 16, // 16 + number of bytes, up to 8 bytes 97 101 PPS_SIMPLE_ARRAY = 32, // 32 + number of bytes, up to 8 bytes, then 2 bytes of length … … 166 170 void CheckTag (short datasz); 167 171 void CheckArrayTag(short datasz, size_t sz); 172 void GetTypeTag (char& c); 168 173 void GetRawByte (char& c); 169 174 void GetRawBytes(void* ptr, size_t bytes); … … 319 324 public: 320 325 static PPersist* Create() {return new T();} 321 static void Register(string id) {PIOPersist::RegisterClass(Hash(id), Create);}326 static void Register(string id) {PIOPersist::RegisterClass(Hash(id),typeid(T).name(),Create);} 322 327 static uint_8 Hash(string id) { 323 328 return PIOPersist::Hash(id);
Note:
See TracChangeset
for help on using the changeset viewer.