Ignore:
Timestamp:
Oct 3, 2003, 3:39:33 PM (22 years ago)
Author:
ansari
Message:

1) Premiere serie des modifications et ajout fonctionalites pour les PPersist:

  • Ecriture/lecture complex<> et tableaux de complex
  • Ecriture/lecture int_1, uint_1 et tableaux de
  • Tag de positionnement et table de tag de positionnement

2) Adaptation de Read/Write NDataBlock et suppression du fichier piocmplx.h

Reza 03/10/2003

File:
1 edited

Legend:

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

    r2430 r2441  
    336336//--
    337337{
    338   s.WriteTag(tag);
     338  s.WriteNameTag(tag);
    339339  s.PutPPObject(this);
    340340}
     
    431431  rbuf[32] = '\0';
    432432  struct tm tm;
    433   #if !(defined(__MWERKS__) || defined(OS_MACOSX))
     433  /*  #if !(defined(__MWERKS__) || defined(OS_MACOSX))  RZ-DEL */
    434434  strptime(rbuf,"%d/%m/%Y %H:%M:%S GMT",&tm);
    435   #else
     435  /*  #else
    436436  sscanf(rbuf,"%2d/%2d/%4d %2d:%2d:%2d GMT",&tm.tm_mday,&tm.tm_mon,&tm.tm_year,
    437437                                            &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
     438
    438439  tm.tm_mon  --;
    439440  tm.tm_year -= 1900;
    440   #endif
     441  #endif    RZ-DEL */
     442
    441443  creationdate = mktime(&tm);
    442444  filename = flnm;  // keep the filename
     
    516518    if (ppstype == PPS_EOF) break;
    517519   
    518     if (ppstype != PPS_TAG)
     520    if (ppstype != PPS_NAMETAG_TABLE)
    519521      throw FileFormatExc("PInPersist::Scan   corrupted file, bad tag entry");
    520522
     
    540542
    541543bool
    542 PInPersist::GotoTag(string const& name)
     544PInPersist::GotoPositionTag(int_8 pos)
     545{
     546  s->seekg(pos);
     547  int_8 tpos;
     548  GetRawI8(tpos);
     549  if (tpos != pos)
     550    throw FileFormatExc("PInPersist::GotoPositionTag() - Wrong tag position!");
     551  return true;
     552}
     553
     554bool
     555PInPersist::GotoNameTag(string const& name)
    543556{
    544557  map<string, int_8>::iterator i = tags.find(name);
    545558  if (i == tags.end())
    546559    return false;
    547       //    throw NotFoundExc("PInPersist::GotoTag   tag not found");
     560      //    throw NotFoundExc("PInPersist::GotoNameTag   tag not found");
    548561  s->seekg((*i).second);
    549562  seqread = false;
     
    551564  return(true);
    552565}
     566
    553567
    554568bool
     
    625639PInPersist::GetTypeTag(unsigned char& c)
    626640{
    627   c = PPS_TAG_MARK;
    628   while (c == PPS_TAG_MARK) GetRawUByte(c);
    629   //  while (c == PPS_TAG_MARK) {    Il ne faut plus faire ca !
     641  int_8 tpos;
     642  c = PPS_NAMETAG_MARK;
     643  while ( (c == PPS_NAMETAG_MARK) || (c == PPS_POSTAG_MARK) ) {
     644    GetRawUByte(c);
     645    if (c == PPS_POSTAG_MARK)  GetRawI8(tpos);
     646  }
     647  //  while (c == PPS_NAMETAG_MARK) {    Il ne faut plus faire ca !
    630648  //    objList.clear();             $CHECK$ Reza 03/2000
    631649  //    GetRawByte(c);
     
    776794
    777795void
     796PInPersist::GetI1   (int_1& result)
     797{
     798  CheckTag(1,PPS_DATATYPE_INTEGER);
     799  GetRawBytes(&result, sizeof(int_1));
     800}
     801
     802void
     803PInPersist::GetI1s  (int_1* tab, size_t n)
     804{
     805  CheckArrayTag(1,n,PPS_DATATYPE_INTEGER);
     806  GetRawBytes(tab, n*sizeof(int_1));
     807}
     808
     809void
     810PInPersist::GetU1   (uint_1& result)
     811{
     812  CheckTag(1,PPS_DATATYPE_UNSIGNED);
     813  GetRawBytes(&result, sizeof(uint_1));
     814}
     815
     816void
     817PInPersist::GetU1s  (uint_1* tab, size_t n)
     818{
     819  CheckArrayTag(1,n,PPS_DATATYPE_UNSIGNED);
     820  GetRawBytes(tab, n*sizeof(uint_1));
     821}
     822
     823void
    778824PInPersist::GetI2   (int_2& result)
    779825{
     
    934980}
    935981
     982void
     983PInPersist::GetZ4   (complex<r_4>& result)
     984{
     985  CheckTag(4,PPS_DATATYPE_COMPLEX);
     986  r_4 reim[2];
     987  GetRawBytes(reim, 2*sizeof(r_4));
     988  if (bigEndian != IS_BIG_ENDIAN) {
     989    bswap4(reim);
     990    bswap4(reim+1);
     991  }
     992  result = complex<r_4>(reim[0], reim[1]);
     993}
     994
     995void
     996PInPersist::GetZ4s  (complex<r_4>* tab, size_t n)
     997
     998  CheckArrayTag(4,n,PPS_DATATYPE_COMPLEX);
     999  GetRawBytes(tab, n*2*sizeof(r_4));
     1000  if (bigEndian == IS_BIG_ENDIAN) return;
     1001
     1002  r_4 * p = (r_4 *)tab;
     1003  for (unsigned int i=0; i<n; i++) {
     1004    bswap4(p);  p++;
     1005    bswap4(p);  p++;
     1006  }
     1007  return;
     1008}
     1009
     1010void
     1011PInPersist::GetZ8   (complex<r_8>& result)
     1012{
     1013  CheckTag(8,PPS_DATATYPE_COMPLEX);
     1014  r_8 reim[2];
     1015  GetRawBytes(reim, 2*sizeof(r_8));
     1016  if (bigEndian != IS_BIG_ENDIAN) {
     1017    bswap8(reim);
     1018    bswap8(reim+1);
     1019  }
     1020  result = complex<r_8>(reim[0], reim[1]);
     1021}
     1022
     1023void
     1024PInPersist::GetZ8s  (complex<r_8>* tab, size_t n)
     1025{
     1026  CheckArrayTag(8,n,PPS_DATATYPE_COMPLEX);
     1027  GetRawBytes(tab, n*2*sizeof(r_8));
     1028  if (bigEndian == IS_BIG_ENDIAN) return;
     1029
     1030  r_8 * p = (r_8 *)tab;
     1031  for (unsigned int i=0; i<n; i++) {
     1032    bswap8(p);  p++;
     1033    bswap8(p);  p++;
     1034  }
     1035  return;
     1036}
     1037
     1038
     1039void
     1040PInPersist::GetPosTagTable(int_8* ptab, size_t sz)
     1041{
     1042  unsigned char ppstype;
     1043  GetTypeTag(ppstype);
     1044  if (ppstype != PPS_POSTAG_TABLE)
     1045    throw FileFormatExc("PInPersist::GetPosTagTable  bad type in ppersist stream");
     1046  int_4 tsz;
     1047  GetRawI4(tsz);
     1048  if (tsz != sz)
     1049    throw FileFormatExc("PInPersist::GetPosTagTable Size mismatch ");
     1050  for(int kk=0; kk<tsz; kk++)
     1051    GetRawI8(ptab[kk]);
     1052  return;
     1053}
     1054
     1055void
     1056PInPersist::GetPosTagTable(vector<int_8>& ptab)
     1057{
     1058  unsigned char ppstype;
     1059  GetTypeTag(ppstype);
     1060  if (ppstype != PPS_POSTAG_TABLE)
     1061    throw FileFormatExc("PInPersist::GetPosTagTable  bad type in ppersist stream");
     1062  ptab.clear();
     1063  int_4 tsz;
     1064  GetRawI4(tsz);
     1065  int_8 tpos;
     1066  for(int kk=0; kk<tsz; kk++) {
     1067    GetRawI8(tpos);
     1068    ptab.push_back(tpos);
     1069  }
     1070  return;
     1071}
    9361072
    9371073PPersist*
     
    10101146{
    10111147  unsigned char ppstag=0;
    1012   unsigned char ppst1,ppst2,ppst3;
     1148  unsigned char ppst1,ppst2,ppst3,ppst30;
    10131149  uint_8 cpos,fsize;
    10141150  uint_8 ui8,cid,oid;
     
    10531189    ppst2 = ppstag&0x30;  // bits     45
    10541190    ppst3 = ppstag&0xc0;  // bits       67
     1191    ppst30 = ppstag&0xc1; // bits 0     67
    10551192    if ((ppst2 == 0) && (ppst3 == 0) ) {
    10561193      switch (ppst1) {
     
    10811218        break;
    10821219
    1083       case PPS_TAG_MARK :
    1084         cout << "<PPS_TAG_MARK> tag at position " << hex << cpos << dec << endl;
     1220      case PPS_NAMETAG_MARK :
     1221        cout << "<PPS_NAMETAG_MARK> tag at position " << hex << cpos << dec << endl;
     1222        break;
     1223
     1224      case PPS_POSTAG_MARK :
     1225        GetRawI8(i8);   
     1226        cout << "<PPS_POSTAG_MARK> tag at position " << hex << cpos
     1227             << " TPos=" << i8 << dec << endl;
    10851228        break;
    10861229     
     
    10911234        break;
    10921235
    1093       case PPS_TAG :
     1236      case PPS_POSTAG_TABLE :
     1237        GetRawI4(i4);
     1238        for(int kkt=0; kkt<i4; kkt++)  GetRawI8(i8);   
     1239        cout << "<PPS_POSTAG_TABLE> tag at position " << hex << cpos << dec << endl;
     1240        break;
     1241
     1242      case PPS_NAMETAG_TABLE :
    10941243        GetRawI8(i8);
    10951244        GetRawI4(i4);
     
    11171266    else {
    11181267      string dtype = "???? x";
    1119       if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
     1268      if (ppst30 == PPS_DATATYPE_COMPLEX) dtype = "COMPLEX x";
     1269      else if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
    11201270      else if (ppst3 == PPS_DATATYPE_FLOAT) dtype = "FLOAT x";
    11211271      else if (ppst3 == PPS_DATATYPE_INTEGER) dtype = "INTEGER x";
    11221272      else if (ppst3 == PPS_DATATYPE_UNSIGNED) dtype = "UNSIGNED x";
    11231273      int_4 dsize = ppst1;
     1274      int_4 dsizeskip = dsize;
     1275      if (ppst30 == PPS_DATATYPE_COMPLEX) {
     1276        dsize--;
     1277        dsizeskip = 2*dsize;
     1278      }
    11241279      char sb[16];
    11251280      sprintf(sb, "%d", dsize);
     
    11311286        if (lev > 2)  cout << "<PPS_SIMPLE> tag at position " << hex << cpos << dec
    11321287                           << " DataType=" << dtype << endl;
    1133         s->seekg(dsize, ios::cur);
     1288        s->seekg(dsizeskip, ios::cur);
    11341289        break;
    11351290
     
    11381293        if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec
    11391294                           << " DataType=" << dtype << " NElts= " << i4 << endl;
    1140         s->seekg((uint_8)dsize*(uint_8)i4, ios::cur);
     1295        s->seekg((uint_8)dsizeskip*(uint_8)i4, ios::cur);
    11411296        break;
    11421297
     
    11451300        if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec
    11461301                           << " DataType=" << dtype << " NElts= " << ui8 << endl;
    1147         s->seekg((uint_8)dsize*ui8, ios::cur);
     1302        s->seekg((uint_8)dsizeskip*ui8, ios::cur);
    11481303        break;
    11491304      }
     
    12471402  // Output stream creation
    12481403  s = new ofstream(flnm.c_str(),ios::out | IOS_BIN); 
    1249 
     1404  version = 3;
    12501405  // Header
    1251   PutRawBytes("SOS-SOPHYA-PPersistFile V2               ",32);
     1406  PutRawBytes("SOS-SOPHYA-PPersistFile V3               ",32);
    12521407  PutRawBytes(bigEndian
    12531408           ? "BIG-ENDIAN                             "
     
    12791434      string name = (*i).first;
    12801435      int_8 pos = (*i).second;
    1281       PutRawUByte(PPS_TAG);                       // This is a tag
     1436      PutRawUByte(PPS_NAMETAG_TABLE);                       // This is a tag
    12821437      PutRawI8(pos);                             // position of previous tag
    12831438      PutRawI4(name.length());                   // length of the name
     
    12911446}
    12921447
    1293 
    1294 void
    1295 POutPersist::WriteTag(string const& name)
     1448int_8
     1449POutPersist::WritePositionTag()
     1450{
     1451  int_8 tagpos;
     1452#ifdef STREAMPOS_IS_CLASS
     1453  tagpos = s->tellp().offset();
     1454#else
     1455  tagpos = s->tellp();
     1456#endif
     1457  PutRawByte(PPS_POSTAG_MARK);
     1458  PutI8(tagpos);
     1459  return(tagpos);
     1460}
     1461
     1462void
     1463POutPersist::WriteNameTag(string const& name)
    12961464{
    12971465  if (name.length() > MAXTAGLEN)
    1298     throw ParmError("POutPersist::WriteTag   tag name too long");
     1466    throw ParmError("POutPersist::WriteNameTag   tag name too long");
    12991467
    13001468  if (tags.find(name) != tags.end())
    1301     throw DuplicateIdExc("POutPersist::WriteTag   duplicate tag name");
     1469    throw DuplicateIdExc("POutPersist::WriteNameTag   duplicate tag name");
    13021470
    13031471  // Get current file position
     
    13111479
    13121480  tags[name] = tagPos;
    1313   PutRawUByte(PPS_TAG_MARK);                       // This is a tag
     1481  PutRawUByte(PPS_NAMETAG_MARK);                       // This is a tag
    13141482  //  objList.clear(); // $CHECK$ EA 171199  - Ne pas faire ? Reza 03/2000
    13151483}
     
    14821650
    14831651void
     1652POutPersist::PutI1   (int_1 val)
     1653{
     1654  PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_INTEGER);
     1655  PutRawBytes(&val, sizeof(int_1));
     1656}
     1657
     1658void
     1659POutPersist::PutI1s  (int_1 const* tab, size_t n)
     1660{
     1661  PutArrayTag(1, n, PPS_DATATYPE_INTEGER);
     1662  PutRawBytes(tab, n*sizeof(int_1));
     1663}
     1664
     1665void
     1666POutPersist::PutU1   (uint_1 val)
     1667{
     1668  PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_UNSIGNED);
     1669  PutRawBytes(&val, sizeof(uint_1));
     1670}
     1671
     1672void
     1673POutPersist::PutU1s  (uint_1 const* tab, size_t n)
     1674{
     1675  PutArrayTag(1, n, PPS_DATATYPE_UNSIGNED);
     1676  PutRawBytes(tab, n*sizeof(uint_1));
     1677}
     1678
     1679void
    14841680POutPersist::PutI2   (int_2 val)
    14851681{
     
    16601856
    16611857void
     1858POutPersist::PutZ4   (complex<r_4> val)
     1859{
     1860  PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_COMPLEX);
     1861  r_4 reim[2];
     1862  reim[0] = val.real();
     1863  reim[1] = val.imag();
     1864  if (bigEndian != IS_BIG_ENDIAN) {
     1865    bswap4(reim);
     1866    bswap4(reim+1);
     1867  }
     1868  PutRawBytes(reim, 2*sizeof(r_4));
     1869}
     1870
     1871void
     1872POutPersist::PutZ4s  (complex<r_4> const* tab, size_t n)
     1873{
     1874  PutArrayTag(4, n, PPS_DATATYPE_COMPLEX);
     1875
     1876  if (bigEndian == IS_BIG_ENDIAN) {
     1877    PutRawBytes(tab, n*2*sizeof(r_4));
     1878  } else {
     1879    for (unsigned int i=0; i<n; i++) {
     1880      r_4 reim[2];
     1881      reim[0] = tab[i].real();
     1882      reim[1] = tab[i].imag();
     1883      bswap4(reim);
     1884      bswap4(reim+1);
     1885      PutRawBytes(reim, 2*sizeof(r_4));
     1886    }
     1887  }
     1888}
     1889
     1890void
     1891POutPersist::PutZ8   (complex<r_8> val)
     1892{
     1893  PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_COMPLEX);
     1894  r_8 reim[2];
     1895  reim[0] = val.real();
     1896  reim[1] = val.imag();
     1897  if (bigEndian != IS_BIG_ENDIAN) {
     1898    bswap8(reim);
     1899    bswap8(reim+1);
     1900  }
     1901  PutRawBytes(reim, 2*sizeof(r_8));
     1902}
     1903
     1904void
     1905POutPersist::PutZ8s  (complex<r_8> const* tab, size_t n)
     1906{
     1907  PutArrayTag(8, n, PPS_DATATYPE_COMPLEX);
     1908
     1909  if (bigEndian == IS_BIG_ENDIAN) {
     1910    PutRawBytes(tab, n*2*sizeof(r_8));
     1911  } else {
     1912    for (unsigned int i=0; i<n; i++) {
     1913      r_8 reim[2];
     1914      reim[0] = tab[i].real();
     1915      reim[1] = tab[i].imag();
     1916      bswap8(reim);
     1917      bswap8(reim+1);
     1918      PutRawBytes(reim, 2*sizeof(r_8));
     1919    }
     1920  }
     1921}
     1922
     1923void
     1924POutPersist::PutPosTagTable(int_8 const * ptab, size_t sz)
     1925{
     1926  PutRawUByte(PPS_POSTAG_TABLE);
     1927  int_4 tsz = sz;
     1928  PutRawI4(tsz);
     1929  for(int kk=0; kk<tsz; kk++)
     1930    PutRawI8(ptab[kk]);
     1931  return;
     1932}
     1933
     1934void
     1935POutPersist::PutPosTagTable(vector<int_8> const& ptab)
     1936{
     1937  PutRawUByte(PPS_POSTAG_TABLE);
     1938  int_4 tsz = ptab.size();
     1939  PutRawI4(tsz);
     1940  for(int kk=0; kk<tsz; kk++)
     1941    PutRawI8(ptab[kk]);
     1942  return;
     1943}
     1944
     1945void
    16621946POutPersist::PutObject(AnyDataObj & o)
    16631947{
     
    16731957POutPersist::PutObject(AnyDataObj & o, string tagname)
    16741958{
    1675   WriteTag(tagname);
     1959  WriteNameTag(tagname);
    16761960  PutObject(o);
    16771961}
Note: See TracChangeset for help on using the changeset viewer.