Changeset 2459 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Nov 22, 2003, 6:45:23 PM (22 years ago)
Author:
ansari
Message:

Suite modifications PPersist - en particulier, utilisation des RawInOutStream - Reza 22 Nov 2003

Location:
trunk/SophyaLib/BaseTools
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/basetools.h

    r1620 r2459  
    1414#include "sophyainit.h"
    1515#include "ppersist.h"
     16#include "ppfnametag.h"
    1617#include "ndatablock.h"
    1718#include "anydataobj.h"
  • trunk/SophyaLib/BaseTools/ppersist.cc

    r2441 r2459  
    347347//--
    348348{
    349   if (!s.GotoTag(tag))
     349  if (!s.GotoNameTag(tag))
    350350    throw NotFoundExc("PPersist::ReadAtTag  tag not found");
    351351  Read(s);
     
    401401//--
    402402{
    403   s = new ifstream(flnm.c_str(),ios::in | IOS_BIN);
     403  s = new RawInFileStream(flnm.c_str());
    404404
    405405  // Read and check header
     
    444444  filename = flnm;  // keep the filename
    445445  seqread = true;   // To flag non sequential reads
    446   if (scan) Scan();
     446  if (scan && s->isSeekable()) Scan();
    447447}
    448448
     
    472472
    473473  unsigned char ppstype;
    474   size_t debut;
    475 #ifdef STREAMPOS_IS_CLASS
    476   debut = s->tellg().offset();
    477 #else
     474  int_8 debut;
    478475  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
    492477  s->seekg(-(sizeof(int_8)+1), ios::end);
    493 #endif
    494478
    495479  GetTypeTag(ppstype);
     
    499483  int_8 pos;
    500484  GetRawI8(pos);
    501 #if defined(Darwin)
    502   // Septembre 2003 - Reza : Pb avec MacOSX 10.2
    503   // Sur MacOSX (10.2, g++ 3.1), la lecture du dernier byte du flot cause
    504   // une erreur, et le flot ne se repositionne plus
    505   // On ferme le flot et on le rouvre ...
    506   delete s;
    507   s = new ifstream(FileName().c_str(), ios::in | IOS_BIN);
    508 #endif
    509485  if (pos < 0) {  // no tags
    510486    s->seekg(debut);
     
    536512
    537513int
    538 PInPersist::NbTags()
     514PInPersist::NbNameTags()
    539515{
    540516  return tags.size();
     
    567543
    568544bool
    569 PInPersist::GotoTagNum(int itag)
     545PInPersist::GotoNameTagNum(int itag)
    570546{
    571547  if (itag<0 || itag >= (int)tags.size()) return false;
     
    601577static vector<string> * ret_tag_names = NULL;
    602578vector<string> const &
    603 PInPersist::GetTagNames()
     579PInPersist::GetNameTags()
    604580{
    605581if (ret_tag_names) delete ret_tag_names;
     
    608584for(i=tags.begin(); i!=tags.end(); i++) ret_tag_names->push_back((*i).first);
    609585return(*ret_tag_names); 
     586}
     587
     588bool
     589PInPersist::SkipToNextObject()
     590{
     591  // A FAIRE NOV 2003 - REZA
     592  return true;
    610593}
    611594
     
    10871070PInPersist::GetObject(AnyDataObj & o, string tagname)
    10881071{
    1089   GotoTag(tagname);
     1072  GotoNameTag(tagname);
    10901073  GetPPObject(&o);
    10911074  return;
     
    11471130  unsigned char ppstag=0;
    11481131  unsigned char ppst1,ppst2,ppst3,ppst30;
    1149   uint_8 cpos,fsize;
     1132  int_8 cpos,fsize;
    11501133  uint_8 ui8,cid,oid;
    11511134  int_4 i4;
     
    11581141
    11591142
    1160 #ifdef STREAMPOS_IS_CLASS
    1161   cpos = s->tellg().offset();
    1162 #else
    11631143  cpos = s->tellg();
    1164 #endif
    11651144  s->seekg(0,ios::end);
    1166 #ifdef STREAMPOS_IS_CLASS
    1167   fsize = s->tellg().offset();
    1168 #else
    11691145  fsize = s->tellg();
    1170 #endif
    11711146  s->seekg(cpos,ios::beg);
    11721147
     
    11781153
    11791154  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();
    11851156    GetRawUByte(ppstag);
    11861157    totntags++;
     
    12931264        if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec
    12941265                           << " 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);
    12961267        break;
    12971268
     
    13001271        if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec
    13011272                           << " DataType=" << dtype << " NElts= " << ui8 << endl;
    1302         s->seekg((uint_8)dsizeskip*ui8, ios::cur);
     1273        s->seekg((int_8)dsizeskip*ui8, ios::cur);
    13031274        break;
    13041275      }
     
    13341305    // Let's try to read it
    13351306    int_8 cpos;
    1336 #ifdef STREAMPOS_IS_CLASS
    1337     cpos = s->tellg().offset();
    1338 #else
    13391307    cpos = s->tellg();
    1340 #endif
    13411308    s->seekg(pos);
    13421309    PPersist* ppo = ReadObject();
     
    13591326  //  cerr << " DBG - PInPersist::KeepOId() " << oid << endl;
    13601327  if ((objList.size() > 0) && (objList.find(oid) != objList.end()) ) {
    1361     //  Ceci ne devrait arriver que si on lit dans le desordre (avec GotoTag)
     1328    //  Ceci ne devrait arriver que si on lit dans le desordre (avec GotoNameTag)
    13621329    //  et pas avec une lecture sequentielle ...   Reza 03/2000
    13631330    //  cerr << "PInPersist::KeepOId()/Warning - already present PPS_ObjectId ! " << oid << endl;
     
    14011368  pps_OId = 0;
    14021369  // Output stream creation
    1403   s = new ofstream(flnm.c_str(),ios::out | IOS_BIN); 
     1370  s = new RawOutFileStream(flnm.c_str());
    14041371  version = 3;
    14051372  // Header
     
    14261393  } else {
    14271394    int_8 tagPos;
    1428 #ifdef STREAMPOS_IS_CLASS
    1429     tagPos = s->tellp().offset();
    1430 #else
    14311395    tagPos = s->tellp();
    1432 #endif
    14331396    for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
    14341397      string name = (*i).first;
     
    14501413{
    14511414  int_8 tagpos;
    1452 #ifdef STREAMPOS_IS_CLASS
    1453   tagpos = s->tellp().offset();
    1454 #else
    14551415  tagpos = s->tellp();
    1456 #endif
    14571416  PutRawByte(PPS_POSTAG_MARK);
    14581417  PutI8(tagpos);
     
    14711430  // Get current file position
    14721431  int_8 tagPos;
    1473 
    1474   #ifdef STREAMPOS_IS_CLASS
    1475   tagPos = s->tellp().offset();
    1476   #else
    14771432  tagPos = s->tellp();
    1478   #endif
    14791433
    14801434  tags[name] = tagPos;
     
    20111965    objreftag rt;
    20121966    rt.ppsoid = id;
    2013 #ifdef STREAMPOS_IS_CLASS
    2014     rt.ppspos = s->tellp().offset();
    2015 #else
    20161967    rt.ppspos = s->tellp();
    2017 #endif
    20181968    objList[mid] = rt;
    20191969  }
  • trunk/SophyaLib/BaseTools/ppersist.h

    r2441 r2459  
    1313#include "pexceptions.h"
    1414#include "gnumd5.h"
     15#include "rawstream.h"
    1516
    1617
     
    3940  public:
    4041    virtual           ~PPersist() {}
    41 // J'ajoute cette fonction pour assurer la compatibilite
    42 // avec l'ancien PPersist d'Eros     (Reza 23/04/99)
    43     virtual int_4      ClassId() const { return(0); }
    4442
    4543    void               Write(string const& fn) const;
     
    116114          PPS_NAMETAG_MARK = 7,     // To have a name tag, position marker in a file
    117115          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)
    119117          PPS_SIMPLE = 16,          // 16 + number of bytes, up to 8 bytes
    120118          PPS_SIMPLE_ARRAY4 = 32,   // 32 + number of bytes, up to 8 bytes, then 4 bytes of length
     
    146144    bool   GotoPositionTag(int_8 pos);
    147145    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
    151148    string GetTagName(int itag);  // 0..NbTags-1
    152149    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();
    154154
    155155    // Lecture donnees de base et tableaux de donnees de base
     
    247247    void   Scan();
    248248
    249     istream* s;
     249    RawInOutStream* s;
    250250
    251251    bool bigEndian;
     
    342342
    343343  protected:
    344     ostream* s;
     344    RawInOutStream* s;
    345345    bool bigEndian;
    346346
  • trunk/SophyaLib/BaseTools/rawstream.cc

    r2458 r2459  
    161161  : RawInOutStream()
    162162{
    163   fip = fopen(path.c_str(),"rb");
     163  fip = fopen(path.c_str(),"wb");
    164164  if (fip == NULL) {
    165165    string errmsg = "RawOutFileStream() - fopen(wb) ERROR - File= ";
  • trunk/SophyaLib/BaseTools/sversion.h

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