Changeset 2476 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Dec 5, 2003, 12:02:27 AM (22 years ago)
Author:
ansari
Message:

Debug/correction des ppersist suite a la separation des PInOutPersist en PPFInOutStream - Reza 5 Dec 2003

Location:
trunk/SophyaLib/BaseTools
Files:
5 edited

Legend:

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

    r2475 r2476  
    180180}
    181181
     182static inline void bswap8_hash(void* p)
     183{
     184  uint_8 tmp = *(uint_8*)p;
     185  *(uint_8*)p = ((tmp >> (7*8)) & 0x000000FF) |
     186                ((tmp >> (5*8)) & 0x0000FF00) |
     187                ((tmp >> (3*8)) & 0x00FF0000) |
     188                ((tmp >> (1*8)) & 0xFF000000) |
     189                ((tmp & 0xFF000000) << (1*8))  |
     190                ((tmp & 0x00FF0000) << (3*8))  |
     191                ((tmp & 0x0000FF00) << (5*8))  |
     192                ((tmp & 0x000000FF) << (7*8));
     193}
    182194
    183195
     
    190202        uint_8 hash2 =   *((uint_8*) (ctx.buf+8));
    191203#if IS_BIG_ENDIAN
    192         bswap8(&hash1);
    193         bswap8(&hash2);
     204        bswap8_hash(&hash1);
     205        bswap8_hash(&hash2);
    194206#endif
    195207       
     
    628640    objreftag rt;
    629641    rt.ppsoid = id;
     642    //    cout << " DBG-rt.ppspos = s->tellp(); " << endl;
    630643    rt.ppspos = s->tellp();
     644    // cout << " DBG-rt.ppspos = s->tellp(); = " << rt.ppspos << endl;
    631645    objList[mid] = rt;
    632646  }
  • trunk/SophyaLib/BaseTools/ppfbinstream.cc

    r2475 r2476  
    5050
    5151
    52 PPFBinaryInputStream::PPFBinaryInputStream()
    53 {
    54   s = NULL;
    55   version = 0;
    56   bigEndian = true;
     52PPFBinaryInputStream::PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan)
     53{
     54  s = is;
     55  _ads = ad;
     56  Init(scan);
    5757}
    5858
     
    6464{
    6565  s = new RawInFileStream(flnm.c_str());
    66 
     66  _ads = true;
     67  Init(scan);
     68}
     69
     70PPFBinaryInputStream::~PPFBinaryInputStream()
     71{
     72  if (_ads && (s!=NULL) ) delete s;
     73}
     74
     75void
     76PPFBinaryInputStream::Init(bool scan)
     77{
    6778  // Read and check header
    6879
     
    7586  version = atoi(rbuf+25);
    7687  if (version < 2) {
    77     cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << flnm << ") Version(=" << version
     88    cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << FileName() << ") Version(=" << version
    7889         << ") < 2 not supported !" << endl;
    7990    throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream() - Unsupported (Old) Version");
     
    104115
    105116  creationdate = mktime(&tm);
    106   filename = flnm;  // keep the filename
    107117  seqread = true;   // To flag non sequential reads
    108   if (scan && s->isSeekable()) Scan();
    109 }
    110 
    111 
    112 
    113 PPFBinaryInputStream::~PPFBinaryInputStream()
    114 {
    115   if (s) delete s;
    116 }
     118  if (scan && s->isSeekable()) {
     119    if (Version() >= 3) ReadNameTagTable();
     120    else ReadNameTagTableV2();
     121  }
     122}
     123
     124
     125
    117126
    118127
     
    126135
    127136void
    128 PPFBinaryInputStream::Scan()
    129 {
    130   // On cherche la liste des tags, a la fin du fichier
    131 
     137PPFBinaryInputStream::ReadNameTagTable()
     138{
    132139  unsigned char ppstype;
    133140  int_8 debut;
     
    138145  GetTypeTag(ppstype);
    139146  if (ppstype != PPS_EOF)
    140     throw FileFormatExc("PPFBinaryInputStream::Scan   corrupted file, no eof entry at end of file");
     147    throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable()  Corrupted file, no EOF tag at end of file");
     148
     149  // Lecture position NameTagTable
     150  int_8 pos;
     151  GetRawI8(pos);
     152  if (pos < 0) {  // no tags
     153    s->seekg(debut);
     154    return;
     155  }
     156 
     157  // On se positionne au debut du NameTagTable
     158  s->seekg(pos);
     159  GetTypeTag(ppstype);
     160  if (ppstype != PPS_NAMETAG_TABLE)
     161    throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable()  Corrupted file PPS_NAMETAG_TABLE not found");
     162  uint_8 ttsz,it;
     163  GetU8(ttsz);
     164  for(it=0; it<ttsz; it++) {
     165    int_8 tpos;
     166    string tname;
     167    GetI8(tpos);
     168    GetStr(tname);
     169    tags[tname] = tpos;
     170  }
     171  // On revient au debut du float, juste apres l'entete
     172  s->seekg(debut);
     173}
     174
     175void
     176PPFBinaryInputStream::ReadNameTagTableV2()
     177{
     178  // On cherche la liste des tags, a la fin du fichier
     179
     180  unsigned char ppstype;
     181  int_8 debut;
     182  debut = s->tellg();
     183
     184  s->seekg(-(sizeof(int_8)+1), ios::end);
     185
     186  GetTypeTag(ppstype);
     187  if (ppstype != PPS_EOF)
     188    throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, no eof entry at end of file");
    141189
    142190  int_8 pos;
     
    154202   
    155203    if (ppstype != PPS_NAMETAG_TABLE)
    156       throw FileFormatExc("PPFBinaryInputStream::Scan   corrupted file, bad tag entry");
     204      throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, bad tag entry");
    157205
    158206    GetRawI8(pos);
     
    160208    GetRawI4(len);
    161209    if (len > MAXTAGLEN_V2)
    162       throw FileFormatExc("PPFBinaryInputStream::Scan   corrupted file, tag name too long");
     210      throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, tag name too long");
    163211    GetRawBytes(buffer, len);
    164212    buffer[len] = '\0';
     
    242290
    243291bool
    244 PPFBinaryInputStream::SkipItem()
     292PPFBinaryInputStream::SkipNextItem()
    245293{
    246294  // A FAIRE NOV 2003 - REZA
    247295  return true;
     296}
     297
     298char
     299PPFBinaryInputStream::NextItemTag(short datasz, size_t sz)
     300{
     301  datasz = 0;
     302  sz = 0;
     303  return 0;
     304}
     305
     306void
     307PPFBinaryInputStream::SkipItem(bool fgrdt, char itag)
     308{
     309  return;
    248310}
    249311
     
    888950//--
    889951
    890 PPFBinaryOutputStream::PPFBinaryOutputStream()
    891 {
    892   s = NULL;
    893   version = 0;
     952PPFBinaryOutputStream::PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness)
     953{
     954  s = os;
     955  _ads = ad;
     956  Init(endianness);
    894957}
    895958
    896959PPFBinaryOutputStream::PPFBinaryOutputStream(string const& flnm, int endianness)
     960{
     961  // Output stream creation
     962  s = new RawOutFileStream(flnm.c_str());
     963  _ads = true;
     964  Init(endianness);
     965}
     966
     967PPFBinaryOutputStream::~PPFBinaryOutputStream()
     968{
     969  WriteNameTagTable();
     970  if (_ads && (s != NULL)) delete s;   // Close the stream
     971}
     972
     973void
     974PPFBinaryOutputStream::Init(int endianness)
    897975{
    898976  if (endianness == -1)
     
    901979    bigEndian = endianness;
    902980
    903   // Output stream creation
    904   s = new RawOutFileStream(flnm.c_str());
    905981  version = 3;
    906982  // Header
     
    917993  datestring[32] = '\0';
    918994  PutRawBytes(datestring, 32);
    919   filename = flnm;
    920 }
    921 
    922 PPFBinaryOutputStream::~PPFBinaryOutputStream()
     995}
     996
     997void
     998PPFBinaryOutputStream::WriteNameTagTable()
     999
     1000  if (tags.size() == 0) {
     1001    PutRawUByte(PPS_EOF);
     1002    PutRawI8(-1);
     1003  }
     1004  else {
     1005    int_8 tagPos;
     1006    tagPos = s->tellp();
     1007    PutRawUByte(PPS_NAMETAG_TABLE);                       // This is a tag
     1008    PutU8((uint_8)tags.size());    // Number of tags
     1009    for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
     1010      int_8 pos = (*i).second;
     1011      PutI8(pos);
     1012      PutStr((*i).first);
     1013    }
     1014    PutRawUByte(PPS_EOF);
     1015    PutRawI8(tagPos);
     1016  }
     1017 
     1018}
     1019
     1020void
     1021PPFBinaryOutputStream::WriteNameTagTableV2()
    9231022{
    9241023  if (tags.size() == 0) {
     
    9401039  }
    9411040
    942   delete s;   // Close the stream
    943 }
     1041}
     1042
    9441043
    9451044int_8
  • trunk/SophyaLib/BaseTools/ppfbinstream.h

    r2475 r2476  
    5555  };
    5656 
    57   PPFBinaryIOStream();
    58   virtual ~PPFBinaryIOStream();
     57  PPFBinaryIOStream() { }
     58  virtual ~PPFBinaryIOStream() { }
    5959  int    Version() {return version;}  // PIn/OutPersist version number
    60   string FileName() { return filename; }   // Retourne le nom de fichier
    6160 
    6261protected:
    6362 
    6463  map<string, int_8> tags;
    65   string filename;
    6664  int version;     // PPersist(In/Out) version
    6765};
     
    7169class PPFBinaryInputStream : public PPFBinaryIOStream {
    7270public:
    73   PPFBinaryInputStream();
     71  PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan=false);
    7472  PPFBinaryInputStream(string const& flnm, bool scan=true);
    7573  virtual  ~PPFBinaryInputStream();
     74
     75  inline string FileName() { return s->getFileName(); }   // Retourne le nom de fichier
    7676 
    7777  // Gestion des tags
     
    8585  // Saut jusqu'au prochain objet
    8686  bool   SkipToNextObject();
    87   // Saut d'un item de base (tag+donnees correspondantes)
    88   bool   SkipItem();
     87  // Saut d'un item de base (tag+donnees correspondantes), le suivant ds le flot
     88  bool   SkipNextItem();
     89  // Lecture du tag de type next item + infos correspondantes
     90  // Le stream est re-positionne avant le tag
     91  char   NextItemTag(short datasz, size_t sz);
    8992 
    9093  // Lecture donnees de base et tableaux de donnees de base
     
    157160 
    158161protected:
     162  void   Init(bool scan);
     163  void   ReadNameTagTableV2();
     164  void   ReadNameTagTable();
     165
     166  void   SkipItem(bool fgrdi, char itag);
     167
    159168  void   CheckTag   (short datasz, short datatype);
    160169  void   CheckArrayTag(short datasz, size_t sz, short datatype);
     
    168177  void   GetRawU8   (uint_8&);
    169178 
    170   void   Scan();
    171  
    172179  RawInOutStream* s;
     180  bool _ads; // delete/close the stream at the end
    173181 
    174182  bool bigEndian;
     
    181189class PPFBinaryOutputStream : public PPFBinaryIOStream {
    182190public:
    183   PPFBinaryOutputStream();
     191  PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness = PPS_NATIVE);
    184192  PPFBinaryOutputStream(string const& flnm, int endianness = PPS_NATIVE);
    185193  virtual ~PPFBinaryOutputStream();
     194
     195  inline string FileName() { return s->getFileName(); }   // Retourne le nom de fichier
    186196 
    187197  // Ecriture de tags
     
    253263 
    254264protected:
    255   RawInOutStream* s;
    256   bool bigEndian;
    257  
     265  void     Init(int endianness);
     266  void     WriteNameTagTable();
     267  void     WriteNameTagTableV2();
     268
    258269  void     PutArrayTag(short datasz, size_t sz, short datatype);
    259270  void     PutRawByte (char);
     
    264275  void     PutRawU8   (uint_8);
    265276  void     PutRawBytes(void const* ptr, size_t bytes);
    266  
     277
     278  // Attributs, variables
     279  RawInOutStream* s;
     280  bool _ads; // delete/close the stream at the end
     281
     282  bool bigEndian;
     283
    267284};
    268285 
  • trunk/SophyaLib/BaseTools/rawstream.h

    r2458 r2476  
    2828  virtual RawInOutStream& seekp(int_8, int sd = ios::beg);
    2929  virtual RawInOutStream& write(const char* s, uint_8 n);
     30  inline  std::string     getFileName() const { return _filename; }
     31protected:
     32  std::string _filename;
     33
    3034};
    3135
     
    4347  virtual RawInOutStream& read(char* s, uint_8 n);
    4448
    45   inline  std::string     getFileName() const { return _filename; }
    4649protected:
    4750  FILE * fip;
    48   std::string _filename;
    4951};
    5052
     
    6264  virtual RawInOutStream& write(const char* s, uint_8 n);
    6365
    64   inline  std::string     getFileName() const { return _filename; }
    6566protected:
    6667  FILE * fip;
    67   std::string _filename; 
    6868};
    6969
  • trunk/SophyaLib/BaseTools/sversion.h

    r2459 r2476  
    33
    44#define SOPHYA_VERSION   1.8
    5 #define SOPHYA_REVISION  1
     5#define SOPHYA_REVISION  2
    66#define SOPHYA_TAG       "V_Oct2003"
    77
Note: See TracChangeset for help on using the changeset viewer.