Changeset 588 in Sophya


Ignore:
Timestamp:
Nov 17, 1999, 4:47:03 PM (26 years ago)
Author:
ansari
Message:

Gestion typeid/typename. Gestion simultanee tag+reference

Location:
trunk/SophyaLib/BaseTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/ppersist.cc

    r582 r588  
    3636MD5_CTX PIOPersist::ctx;
    3737PIOPersist::ClassList * PIOPersist::classList = NULL;   // $CHECK$ Reza 26/04/99
     38map<string, uint_8> * PIOPersist::typeids = NULL;
    3839
    3940//++
     
    4445{
    4546classList = new PIOPersist::ClassList;
    46 }
    47 
    48 //++
    49 void
    50 PIOPersist::RegisterClass(uint_8 classId, ClassCreatorFunc f)
     47typeids = new map<string, uint_8>;
     48}
     49
     50//++
     51void
     52PIOPersist::RegisterClass(uint_8 classId, string typname, ClassCreatorFunc f)
    5153//
    5254//      Register a new persistant class.
     
    6466 
    6567  (*classList)[classId] = f;
     68  (*typeids)[typname]  = classId;
    6669}
    6770
     
    154157  // Check tag value
    155158  char ppstype;
    156   s.GetRawByte(ppstype);
     159  s.GetTypeTag(ppstype);
    157160  if (ppstype != PInPersist::PPS_OBJECT) {
    158161    throw FileFormatExc("PPersist::Read : not an object in flow");
     
    162165  uint_8 classId;
    163166  s.GetRawU8(classId);
    164   if (classId != PIOPersist::Hash(typeid(*this).name())) {
     167  uint_8 myClassId = PIOPersist::getTypeId(typeid(*this).name());
     168  if (classId != myClassId) {
    165169    throw FileFormatExc("PPersist::Read : not the same object type");
    166170  }
     
    274278  // Find tag entries at end of file
    275279  s->seekg(-(sizeof(int_8)+1), ios::end);
    276   GetRawByte(ppstype);
     280  GetTypeTag(ppstype);
    277281  if (ppstype != PPS_EOF)
    278282    throw FileFormatExc("PInPersist::Scan   corrupted file, no eof entry at end of file");
     
    288292  s->seekg(pos);
    289293  while (true) {
    290     GetRawByte(ppstype);
     294    GetTypeTag(ppstype);
    291295    if (ppstype == PPS_EOF) break;
    292296   
     
    322326      //    throw NotFoundExc("PInPersist::GotoTag   tag not found");
    323327  s->seekg((*i).second);
     328  objList.clear(); // $CHECK$ EA 171199
    324329  return(true);
    325330}
     
    332337  for (int j=0; j<itag; j++) i++;
    333338  s->seekg((*i).second);
     339  objList.clear(); // $CHECK$ EA 171199
    334340  return(true);
    335341}
     
    410416}
    411417
     418void
     419PInPersist::GetTypeTag(char& c)
     420{
     421  GetRawByte(c);
     422  while (c == PPS_TAG_MARK) {
     423    objList.clear();
     424    GetRawByte(c);
     425  }
     426}
     427
    412428
    413429void
     
    459475{
    460476  char ppstype;
    461   GetRawByte(ppstype);
     477  GetTypeTag(ppstype);
    462478  if (ppstype != PPS_SIMPLE + datasz)
    463479    throw FileFormatExc("PInPersist::CheckTag   bad type in ppersist file");
     
    468484{
    469485  char ppstype;
    470   GetRawByte(ppstype);
     486  GetTypeTag(ppstype);
    471487  size_t filesz;
    472488  if (sz <= 0x7fff) {
     
    686702{
    687703  char ppstype;
    688   GetRawByte(ppstype);
     704  GetTypeTag(ppstype);
    689705  if (ppstype != PPS_LINE)
    690706    throw FileFormatExc("PInPersist::GetLine   bad type in ppersist file");
     
    696712{
    697713  char ppstype;
    698   GetRawByte(ppstype);
     714  GetTypeTag(ppstype);
    699715  if (ppstype != PPS_STRING)
    700716    throw FileFormatExc("PInPersist::GetLine   bad type in ppersist file");
     
    713729  // Get tag
    714730  char ppstype;
    715   GetRawByte(ppstype);
     731  GetTypeTag(ppstype);
    716732  if (ppstype != PPS_OBJECT && ppstype != PPS_REFERENCE && ppstype != PPS_NULL) {
    717733    throw FileFormatExc("PInPersist::ReadObject : not an object in flow");
     
    741757    GetRawI4(id);
    742758    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);
    744762    }
    745763    return objList[id];
     
    843861
    844862  tags[name] = tagPos;
     863  PutRawByte(PPS_TAG_MARK);                       // This is a tag
     864  objList.clear(); // $CHECK$ EA 171199
    845865}
    846866
     
    11931213
    11941214  PutRawByte(PPS_OBJECT);
    1195   PutRawU8(PIOPersist::Hash(typeid(*obj).name()));
     1215  PutRawU8(getTypeId(typeid(*obj).name()));
     1216  //PutRawU8(PIOPersist::Hash(typeid(*obj).name()));
    11961217  assignObjectId(obj);
    11971218  obj->WriteSelf(*this);
  • trunk/SophyaLib/BaseTools/ppersist.h

    r582 r588  
    6969    typedef PPersist*            (*ClassCreatorFunc)();
    7070 
    71     static void                  RegisterClass(uint_8 classId, ClassCreatorFunc f);
     71    static void                  RegisterClass(uint_8 classId, string typname, ClassCreatorFunc f);
    7272    static ClassCreatorFunc      FindCreatorFunc(uint_8 classId);
    7373    static uint_8 Hash(string const& typname) {
     
    8080 
    8181    static void Initialize();   // Pour initialiser classList
     82    static uint_8 getTypeId(string s) {return (*typeids)[s];}
    8283  private:
    8384
     
    8586    // Pas de createur appele pour objets statiques sur Linux - $CHECK$ Reza 26/04/99
    8687    static ClassList *           classList; 
     88    static map<string, uint_8> * typeids;
    8789
    8890  protected:
     91
    8992    enum {PPS_NULL = 0,             // this is a null object
    9093          PPS_STRING = 1,           // string, length (2b) + data
     
    9497          PPS_EOF = 5,              // Just before tag infomation, offset to PPS_TAG
    9598          PPS_LINE = 6,             // '\n'-terminated, deprecated ?
     99          PPS_TAG_MARK = 7,         // to reset object count when skipped
    96100          PPS_SIMPLE = 16,          // 16 + number of bytes, up to 8 bytes
    97101          PPS_SIMPLE_ARRAY = 32,    // 32 + number of bytes, up to 8 bytes, then 2 bytes of length
     
    166170    void   CheckTag   (short datasz);
    167171    void   CheckArrayTag(short datasz, size_t sz);
     172    void   GetTypeTag (char& c);
    168173    void   GetRawByte (char& c);
    169174    void   GetRawBytes(void* ptr, size_t bytes);
     
    319324    public:
    320325      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);}
    322327      static uint_8 Hash(string id) {
    323328        return PIOPersist::Hash(id);
Note: See TracChangeset for help on using the changeset viewer.