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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.