Ignore:
Timestamp:
Dec 4, 2003, 5:43:27 PM (22 years ago)
Author:
ansari
Message:

Separation ppersist.h .cc en deux : ajout de ppfbinstream.h .cc - Reza 4 Dec 2003

File:
1 edited

Legend:

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

    r2459 r2475  
    66#include "ppersist.h"
    77#include "anydataobj.h"
    8 #include <fstream>
    98#include <iostream>
    109#include <typeinfo>
    1110
    12 
    13 #ifdef __mac__
    14 #include "unixmac.h"
    15 #include <SIOUX.h>
    16 #endif
     11// ------------------------- Historique ---------------------------
     12// Le code de ppersist a ete separe en deux en Decembre 2003
     13// a partir de la version CVS (1.26 - ppersist.cc) et
     14// (1.19 - ppersist.h) . 
     15// la partie sur l'ecriture des donnees de base et leurs tableaux
     16// a ete mis dans les fichiers ppfbinstream.h .cc
     17// (Classes PPFBinaryInputStream et PPFBinaryOutputStream
     18// -----------------------------------------------------------------
     19
    1720
    1821//  strptime n'est pas defini sous Linux  - Reza Mars 2000
     
    6467//
    6568//      Register a new persistence handler (PPersist) class.
    66 //      The classId is usually a hash of the class name, and
     69//      The classId is usually a hash of the class< name, and
    6770//      ppclass_name is typeid(PPersistClass).name() .
    6871//      This method is called only through the PPersistRegistrar template
     
    178181
    179182
    180 static inline void bswap8(void* p)
    181 {
    182   uint_8 tmp = *(uint_8*)p;
    183   *(uint_8*)p = ((tmp >> (7*8)) & 0x000000FF) |
    184                 ((tmp >> (5*8)) & 0x0000FF00) |
    185                 ((tmp >> (3*8)) & 0x00FF0000) |
    186                 ((tmp >> (1*8)) & 0xFF000000) |
    187                 ((tmp & 0xFF000000) << (1*8))  |
    188                 ((tmp & 0x00FF0000) << (3*8))  |
    189                 ((tmp & 0x0000FF00) << (5*8))  |
    190                 ((tmp & 0x000000FF) << (7*8));
    191 }
    192 
    193 static inline void bswap4(void* p)
    194 {
    195   uint_4 tmp = *(uint_4*)p;
    196   *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
    197                 ((tmp >> 8)  & 0x0000FF00) |
    198                 ((tmp & 0x0000FF00) << 8)  |
    199                 ((tmp & 0x000000FF) << 24);
    200 }
    201 
    202 static inline void bswap2(void* p)
    203 {
    204   uint_2 tmp = *(uint_2*)p;
    205   *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
    206                 ((tmp & 0x00FF) << 8);
    207 }
    208183
    209184
     
    397372//++
    398373PInPersist::PInPersist(string const& flnm, bool scan)
     374  : PPFBinaryInputStream(flnm, scan)
    399375//
    400376//      Constructeur. Ouvre le fichier.
    401377//--
    402378{
    403   s = new RawInFileStream(flnm.c_str());
    404 
    405   // Read and check header
    406 
    407   char rbuf[36];
    408   GetRawBytes(rbuf, 32);
    409   if (strncmp(rbuf,"SOS-SOPHYA-PPersistFile", 23) != 0)  {
    410     throw FileFormatExc("PInPersist::PInPersist  bad header");
    411   }
    412   rbuf[32] = '\0';
    413   version = atoi(rbuf+25);
    414   if (version < 2) {
    415     cerr << "PInPersist::PInPersist(" << flnm << ") Version(=" << version
    416          << ") < 2 not supported !" << endl;
    417     throw FileFormatExc("PInPersist::PInPersist() - Unsupported (Old) Version");
    418   }
    419   // read endianness
    420   GetRawBytes(rbuf, 32);
    421   if (strncmp(rbuf,"BIG-ENDIAN",10) == 0)
    422     bigEndian = true;
    423   else if (strncmp(rbuf,"LITTLE-ENDIAN",13) == 0)
    424     bigEndian = false;
    425   else {
    426     throw FileFormatExc("PInPersist::PInPersist  bad header - endianness");
    427   }
    428 
    429   // read creation date
    430   GetRawBytes(rbuf, 32);
    431   rbuf[32] = '\0';
    432   struct tm tm;
    433   /*  #if !(defined(__MWERKS__) || defined(OS_MACOSX))  RZ-DEL */
    434   strptime(rbuf,"%d/%m/%Y %H:%M:%S GMT",&tm);
    435   /*  #else
    436   sscanf(rbuf,"%2d/%2d/%4d %2d:%2d:%2d GMT",&tm.tm_mday,&tm.tm_mon,&tm.tm_year,
    437                                             &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
    438 
    439   tm.tm_mon  --;
    440   tm.tm_year -= 1900;
    441   #endif    RZ-DEL */
    442 
    443   creationdate = mktime(&tm);
    444   filename = flnm;  // keep the filename
    445   seqread = true;   // To flag non sequential reads
    446   if (scan && s->isSeekable()) Scan();
    447379}
    448380
     
    454386  for(i=objList.begin(); i!= objList.end(); i++) 
    455387    if ((*i).second)  delete (*i).second;
    456   delete s;
    457 }
    458 
    459 
    460 string
    461 PInPersist::CreationDateStr()
    462 {
    463   time_t cdt = CreationDate();
    464   string cdate = ctime(&cdt);
    465   return(cdate);
    466 }
    467 
    468 void
    469 PInPersist::Scan()
    470 {
    471   // On cherche la liste des tags, a la fin du fichier
    472 
    473   unsigned char ppstype;
    474   int_8 debut;
    475   debut = s->tellg();
    476 
    477   s->seekg(-(sizeof(int_8)+1), ios::end);
    478 
    479   GetTypeTag(ppstype);
    480   if (ppstype != PPS_EOF)
    481     throw FileFormatExc("PInPersist::Scan   corrupted file, no eof entry at end of file");
    482 
    483   int_8 pos;
    484   GetRawI8(pos);
    485   if (pos < 0) {  // no tags
    486     s->seekg(debut);
    487     return;
    488   }
    489 
    490   char buffer[MAXTAGLEN+1];
    491   s->seekg(pos);
    492   while (true) {
    493     GetTypeTag(ppstype);
    494     if (ppstype == PPS_EOF) break;
    495    
    496     if (ppstype != PPS_NAMETAG_TABLE)
    497       throw FileFormatExc("PInPersist::Scan   corrupted file, bad tag entry");
    498 
    499     GetRawI8(pos);
    500     int_4 len;
    501     GetRawI4(len);
    502     if (len > MAXTAGLEN)
    503       throw FileFormatExc("PInPersist::Scan   corrupted file, tag name too long");
    504     GetRawBytes(buffer, len);
    505     buffer[len] = '\0';
    506 
    507     tags[buffer] = pos;
    508   }
    509   s->seekg(debut);
    510 }
    511 
    512 
    513 int
    514 PInPersist::NbNameTags()
    515 {
    516   return tags.size();
    517 }
    518 
    519 bool
    520 PInPersist::GotoPositionTag(int_8 pos)
    521 {
    522   s->seekg(pos);
    523   int_8 tpos;
    524   GetRawI8(tpos);
    525   if (tpos != pos)
    526     throw FileFormatExc("PInPersist::GotoPositionTag() - Wrong tag position!");
    527   return true;
    528 }
    529 
    530 bool
    531 PInPersist::GotoNameTag(string const& name)
    532 {
    533   map<string, int_8>::iterator i = tags.find(name);
    534   if (i == tags.end())
    535     return false;
    536       //    throw NotFoundExc("PInPersist::GotoNameTag   tag not found");
    537   s->seekg((*i).second);
    538   seqread = false;
    539   //  objList.clear(); $CHECK$ EA 171199 Ne pas faire ? Reza 03/2000 ?
    540   return(true);
    541 }
    542 
    543 
    544 bool
    545 PInPersist::GotoNameTagNum(int itag)
    546 {
    547   if (itag<0 || itag >= (int)tags.size()) return false;
    548   map<string, int_8>::iterator i = tags.begin();
    549   for (int j=0; j<itag; j++) i++;
    550   s->seekg((*i).second);
    551   seqread = false;
    552   // objList.clear();  $CHECK$ EA 171199  Ne pas faire ? Reza 03/2000 ?
    553   return(true);
    554 }
    555 
    556 string
    557 PInPersist::GetTagName(int itag)
    558 {
    559   if (itag<0 || itag >= (int)tags.size()) return "";
    560   map<string, int_8>::iterator i = tags.begin();
    561   for (int j=0; j<itag; j++) i++;
    562   return((*i).first);
    563 }
     388}
     389
     390
    564391
    565392string
     
    573400//   return(GetClassName(cid));
    574401  return("");
    575 }
    576 
    577 static vector<string> * ret_tag_names = NULL;
    578 vector<string> const &
    579 PInPersist::GetNameTags()
    580 {
    581 if (ret_tag_names) delete ret_tag_names;
    582 ret_tag_names = new vector<string> ;
    583 map<string, int_8>::iterator i;
    584 for(i=tags.begin(); i!=tags.end(); i++) ret_tag_names->push_back((*i).first);
    585 return(*ret_tag_names); 
    586 }
    587 
    588 bool
    589 PInPersist::SkipToNextObject()
    590 {
    591   // A FAIRE NOV 2003 - REZA
    592   return true;
    593 }
    594 
    595 //++
    596 // void PInPersist::GetByte(char& c)
    597 // void PInPersist::GetBytes(void* ptr, size_t bytes)
    598 // void PInPersist::GetR4   (r_4& result)
    599 // void PInPersist::GetR4s  (r_4* tab, size_t n)
    600 // void PInPersist::GetR8   (r_8& result)
    601 // void PInPersist::GetR8s  (r_8* tab, size_t n)
    602 // void PInPersist::GetI2   (int_2& result)
    603 // void PInPersist::GetI2s  (int_2* tab, size_t n)
    604 // void PInPersist::GetU2   (uint_2& result)
    605 // void PInPersist::GetU2s  (uint_2* tab, size_t n)
    606 // void PInPersist::GetI4   (int_4& result)
    607 // void PInPersist::GetI4s  (int_4* tab, size_t n)
    608 // void PInPersist::GetU4   (uint_4& result)
    609 // void PInPersist::GetU4s  (uint_4* tab, size_t n)
    610 // void PInPersist::GetI8   (int_8& result)
    611 // void PInPersist::GetI8s  (int_8* tab, size_t n)
    612 // void PInPersist::GetU8   (uint_8& result)
    613 // void PInPersist::GetU8s  (uint_8* tab, size_t n)
    614 //      Lecture de données portables depuis le fichier PPersist. Pour chaque type
    615 //      de données, on peut lire une valeur, ou un tableau de valeurs.
    616 // void PInPersist::GetLine(char* ptr, size_t len)
    617 //      Lecture d'une ligne de texte depuis le fichier PPersist.
    618 //--
    619 
    620 
    621 void
    622 PInPersist::GetTypeTag(unsigned char& c)
    623 {
    624   int_8 tpos;
    625   c = PPS_NAMETAG_MARK;
    626   while ( (c == PPS_NAMETAG_MARK) || (c == PPS_POSTAG_MARK) ) {
    627     GetRawUByte(c);
    628     if (c == PPS_POSTAG_MARK)  GetRawI8(tpos);
    629   }
    630   //  while (c == PPS_NAMETAG_MARK) {    Il ne faut plus faire ca !
    631   //    objList.clear();             $CHECK$ Reza 03/2000
    632   //    GetRawByte(c);
    633   //  }
    634 }
    635 
    636 
    637 void
    638 PInPersist::GetRawByte(char& c)
    639 {
    640   GetRawBytes(&c, 1);
    641 }
    642 
    643 void
    644 PInPersist::GetRawUByte(unsigned char& c)
    645 {
    646   GetRawBytes(&c, 1);
    647 }
    648 
    649 void
    650 PInPersist::GetRawBytes(void* ptr, size_t bytes)
    651 {
    652   s->read((char*)ptr, bytes);
    653 }
    654 
    655 void
    656 PInPersist::GetRawI2   (int_2& result)
    657 {
    658   GetRawBytes(&result, sizeof(int_2));
    659   if (bigEndian != IS_BIG_ENDIAN)
    660     bswap2(&result);
    661 }
    662 
    663 void
    664 PInPersist::GetRawI4   (int_4& result)
    665 {
    666   GetRawBytes(&result, sizeof(int_4));
    667   if (bigEndian != IS_BIG_ENDIAN)
    668     bswap4(&result);
    669 }
    670 
    671 void
    672 PInPersist::GetRawI8   (int_8& result)
    673 {
    674   GetRawBytes(&result, sizeof(int_8));
    675   if (bigEndian != IS_BIG_ENDIAN)
    676     bswap8(&result);
    677 }
    678 
    679 void
    680 PInPersist::GetRawU8   (uint_8& result)
    681 {
    682   GetRawBytes(&result, sizeof(uint_8));
    683   if (bigEndian != IS_BIG_ENDIAN)
    684     bswap8(&result);
    685 }
    686 
    687 void
    688 PInPersist::CheckTag(short datasz, short datatype)
    689 // datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
    690 {
    691   unsigned char ppstype;
    692   GetTypeTag(ppstype);
    693   if (ppstype != PPS_SIMPLE + datasz + datatype)
    694     throw FileFormatExc("PInPersist::CheckTag   bad type in ppersist file");
    695 }
    696 
    697 void
    698 PInPersist::CheckArrayTag(short datasz, size_t sz, short datatype)
    699 // datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
    700 {
    701   unsigned char ppstype;
    702   GetTypeTag(ppstype);
    703   size_t filesz;
    704   if (sz <= 0x7fffffff) {
    705     if (ppstype != PPS_SIMPLE_ARRAY4 + datasz + datatype)
    706       throw FileFormatExc("PInPersist::CheckArrayTag   bad type in ppersist file");
    707     int_4 ff;
    708     GetRawI4(ff); filesz=ff;
    709   } else {
    710     if (ppstype != PPS_SIMPLE_ARRAY8 + datasz + datatype)
    711       throw FileFormatExc("PInPersist::CheckArrayTag   bad type in ppersist file");
    712     uint_8 ff;
    713     GetRawU8(ff); filesz=ff;
    714   }
    715   if (filesz != sz)
    716     throw FileFormatExc("PInPersist::CheckArrayTag   bad array size in ppersist file");
    717 }
    718 
    719 void
    720 PInPersist::GetByte(char& c)
    721 {
    722   CheckTag(1,PPS_DATATYPE_CHAR);
    723   GetRawBytes(&c, 1);
    724 }
    725 
    726 
    727 void
    728 PInPersist::GetBytes(void* ptr, size_t bytes)
    729 {
    730   CheckArrayTag(1, bytes, PPS_DATATYPE_CHAR);
    731   GetRawBytes(ptr, bytes);
    732 }
    733 void
    734 PInPersist::GetR4   (r_4& result)
    735 {
    736   CheckTag(4,PPS_DATATYPE_FLOAT);
    737   GetRawBytes(&result, sizeof(r_4));
    738   if (bigEndian != IS_BIG_ENDIAN)
    739     bswap4(&result);
    740 }
    741 
    742 
    743 void
    744 PInPersist::GetR4s  (r_4* tab, size_t n)
    745 {
    746   CheckArrayTag(4,n,PPS_DATATYPE_FLOAT);
    747   GetRawBytes(tab, n*sizeof(r_4));
    748   if (bigEndian == IS_BIG_ENDIAN) return;
    749 
    750   for (unsigned int i=0; i<n; i++)
    751     bswap4(tab+i);
    752 
    753   return;
    754 }
    755 
    756 void
    757 PInPersist::GetR8   (r_8& result)
    758 {
    759   CheckTag(8,PPS_DATATYPE_FLOAT);
    760   GetRawBytes(&result, sizeof(r_8));
    761   if (bigEndian != IS_BIG_ENDIAN)
    762     bswap8(&result);
    763 }
    764 
    765 void
    766 PInPersist::GetR8s  (r_8* tab, size_t n)
    767 {
    768   CheckArrayTag(8,n,PPS_DATATYPE_FLOAT);
    769   GetRawBytes(tab, n*sizeof(r_8));
    770   if (bigEndian == IS_BIG_ENDIAN) return;
    771 
    772   for (unsigned int i=0; i<n; i++)
    773     bswap8(tab+i);
    774 
    775   return;
    776 }
    777 
    778 void
    779 PInPersist::GetI1   (int_1& result)
    780 {
    781   CheckTag(1,PPS_DATATYPE_INTEGER);
    782   GetRawBytes(&result, sizeof(int_1));
    783 }
    784 
    785 void
    786 PInPersist::GetI1s  (int_1* tab, size_t n)
    787 {
    788   CheckArrayTag(1,n,PPS_DATATYPE_INTEGER);
    789   GetRawBytes(tab, n*sizeof(int_1));
    790 }
    791 
    792 void
    793 PInPersist::GetU1   (uint_1& result)
    794 {
    795   CheckTag(1,PPS_DATATYPE_UNSIGNED);
    796   GetRawBytes(&result, sizeof(uint_1));
    797 }
    798 
    799 void
    800 PInPersist::GetU1s  (uint_1* tab, size_t n)
    801 {
    802   CheckArrayTag(1,n,PPS_DATATYPE_UNSIGNED);
    803   GetRawBytes(tab, n*sizeof(uint_1));
    804 }
    805 
    806 void
    807 PInPersist::GetI2   (int_2& result)
    808 {
    809   CheckTag(2,PPS_DATATYPE_INTEGER);
    810   GetRawBytes(&result, sizeof(int_2));
    811   if (bigEndian != IS_BIG_ENDIAN)
    812     bswap2(&result);
    813 }
    814 
    815 void
    816 PInPersist::GetI2s  (int_2* tab, size_t n)
    817 {
    818   CheckArrayTag(2,n,PPS_DATATYPE_INTEGER);
    819   GetRawBytes(tab, n*sizeof(int_2));
    820   if (bigEndian == IS_BIG_ENDIAN) return;
    821 
    822   for (unsigned int i=0; i<n; i++)
    823     bswap2(tab+i);
    824 
    825   return;
    826 }
    827 
    828 void
    829 PInPersist::GetU2   (uint_2& result)
    830 {
    831   CheckTag(2,PPS_DATATYPE_UNSIGNED);
    832   GetRawBytes(&result, sizeof(uint_2));
    833   if (bigEndian != IS_BIG_ENDIAN)
    834     bswap2(&result);
    835 }
    836 
    837 void
    838 PInPersist::GetU2s  (uint_2* tab, size_t n)
    839 {
    840   CheckArrayTag(2,n,PPS_DATATYPE_UNSIGNED);
    841   GetRawBytes(tab, n*sizeof(uint_2));
    842   if (bigEndian == IS_BIG_ENDIAN) return;
    843 
    844   for (unsigned int i=0; i<n; i++)
    845     bswap2(tab+i);
    846 
    847   return;
    848 }
    849 
    850 void
    851 PInPersist::GetI4   (int_4& result)
    852 {
    853   CheckTag(4,PPS_DATATYPE_INTEGER);
    854   GetRawBytes(&result, sizeof(int_4));
    855   if (bigEndian != IS_BIG_ENDIAN)
    856     bswap4(&result);
    857 }
    858 
    859 void
    860 PInPersist::GetI4s  (int_4* tab, size_t n)
    861 {
    862   CheckArrayTag(4,n,PPS_DATATYPE_INTEGER);
    863   GetRawBytes(tab, n*sizeof(int_4));
    864   if (bigEndian == IS_BIG_ENDIAN) return;
    865 
    866   for (unsigned int i=0; i<n; i++)
    867     bswap4(tab+i);
    868 
    869   return;
    870 }
    871 
    872 void
    873 PInPersist::GetU4   (uint_4& result)
    874 {
    875   CheckTag(4,PPS_DATATYPE_UNSIGNED);
    876   GetRawBytes(&result, sizeof(uint_4));
    877   if (bigEndian != IS_BIG_ENDIAN)
    878     bswap4(&result);
    879 }
    880 
    881 void
    882 PInPersist::GetU4s  (uint_4* tab, size_t n)
    883 {
    884   CheckArrayTag(4,n,PPS_DATATYPE_UNSIGNED);
    885   GetRawBytes(tab, n*sizeof(uint_4));
    886   if (bigEndian == IS_BIG_ENDIAN) return;
    887 
    888   for (unsigned int i=0; i<n; i++)
    889     bswap4(tab+i);
    890 
    891   return;
    892 }
    893 
    894 
    895 void
    896 PInPersist::GetI8   (int_8& result)
    897 {
    898   CheckTag(8,PPS_DATATYPE_INTEGER);
    899   GetRawBytes(&result, sizeof(int_8));
    900   if (bigEndian != IS_BIG_ENDIAN)
    901     bswap8(&result);
    902 }
    903 
    904 void
    905 PInPersist::GetI8s  (int_8* tab, size_t n)
    906 {
    907   CheckArrayTag(8,n,PPS_DATATYPE_INTEGER);
    908   GetRawBytes(tab, n*sizeof(int_8));
    909   if (bigEndian == IS_BIG_ENDIAN) return;
    910 
    911   for (unsigned int i=0; i<n; i++)
    912     bswap8(tab+i);
    913 
    914   return;
    915 }
    916 
    917 void
    918 PInPersist::GetU8   (uint_8& result)
    919 {
    920   CheckTag(8,PPS_DATATYPE_UNSIGNED);
    921   GetRawBytes(&result, sizeof(uint_8));
    922   if (bigEndian != IS_BIG_ENDIAN)
    923     bswap8(&result);
    924 }
    925 
    926 void
    927 PInPersist::GetU8s  (uint_8* tab, size_t n)
    928 {
    929   CheckArrayTag(8,n,PPS_DATATYPE_UNSIGNED);
    930   GetRawBytes(tab, n*sizeof(uint_8));
    931   if (bigEndian == IS_BIG_ENDIAN) return;
    932 
    933   for (unsigned int i=0; i<n; i++)
    934     bswap8(tab+i);
    935 
    936   return;
    937 }
    938 
    939 
    940 void
    941 PInPersist::GetLine(char* ptr, size_t len)
    942 {
    943   string str;
    944   GetStr(str);
    945   strncpy(ptr, str.c_str(), len);
    946   ptr[len] = '\0';
    947 }
    948 
    949 void
    950 PInPersist::GetStr(string& str)
    951 {
    952   unsigned char ppstype;
    953   GetTypeTag(ppstype);
    954   if (ppstype != PPS_STRING)
    955     throw FileFormatExc("PInPersist::GetStr   bad type in ppersist file");
    956   int_4 len;
    957   GetRawI4(len);
    958   char * buff = new char[len+1];
    959   GetRawBytes(buff, len);
    960   buff[len] = '\0';
    961   str = buff;
    962   delete[] buff;
    963 }
    964 
    965 void
    966 PInPersist::GetZ4   (complex<r_4>& result)
    967 {
    968   CheckTag(4,PPS_DATATYPE_COMPLEX);
    969   r_4 reim[2];
    970   GetRawBytes(reim, 2*sizeof(r_4));
    971   if (bigEndian != IS_BIG_ENDIAN) {
    972     bswap4(reim);
    973     bswap4(reim+1);
    974   }
    975   result = complex<r_4>(reim[0], reim[1]);
    976 }
    977 
    978 void
    979 PInPersist::GetZ4s  (complex<r_4>* tab, size_t n)
    980 
    981   CheckArrayTag(4,n,PPS_DATATYPE_COMPLEX);
    982   GetRawBytes(tab, n*2*sizeof(r_4));
    983   if (bigEndian == IS_BIG_ENDIAN) return;
    984 
    985   r_4 * p = (r_4 *)tab;
    986   for (unsigned int i=0; i<n; i++) {
    987     bswap4(p);  p++;
    988     bswap4(p);  p++;
    989   }
    990   return;
    991 }
    992 
    993 void
    994 PInPersist::GetZ8   (complex<r_8>& result)
    995 {
    996   CheckTag(8,PPS_DATATYPE_COMPLEX);
    997   r_8 reim[2];
    998   GetRawBytes(reim, 2*sizeof(r_8));
    999   if (bigEndian != IS_BIG_ENDIAN) {
    1000     bswap8(reim);
    1001     bswap8(reim+1);
    1002   }
    1003   result = complex<r_8>(reim[0], reim[1]);
    1004 }
    1005 
    1006 void
    1007 PInPersist::GetZ8s  (complex<r_8>* tab, size_t n)
    1008 {
    1009   CheckArrayTag(8,n,PPS_DATATYPE_COMPLEX);
    1010   GetRawBytes(tab, n*2*sizeof(r_8));
    1011   if (bigEndian == IS_BIG_ENDIAN) return;
    1012 
    1013   r_8 * p = (r_8 *)tab;
    1014   for (unsigned int i=0; i<n; i++) {
    1015     bswap8(p);  p++;
    1016     bswap8(p);  p++;
    1017   }
    1018   return;
    1019 }
    1020 
    1021 
    1022 void
    1023 PInPersist::GetPosTagTable(int_8* ptab, size_t sz)
    1024 {
    1025   unsigned char ppstype;
    1026   GetTypeTag(ppstype);
    1027   if (ppstype != PPS_POSTAG_TABLE)
    1028     throw FileFormatExc("PInPersist::GetPosTagTable  bad type in ppersist stream");
    1029   int_4 tsz;
    1030   GetRawI4(tsz);
    1031   if (tsz != sz)
    1032     throw FileFormatExc("PInPersist::GetPosTagTable Size mismatch ");
    1033   for(int kk=0; kk<tsz; kk++)
    1034     GetRawI8(ptab[kk]);
    1035   return;
    1036 }
    1037 
    1038 void
    1039 PInPersist::GetPosTagTable(vector<int_8>& ptab)
    1040 {
    1041   unsigned char ppstype;
    1042   GetTypeTag(ppstype);
    1043   if (ppstype != PPS_POSTAG_TABLE)
    1044     throw FileFormatExc("PInPersist::GetPosTagTable  bad type in ppersist stream");
    1045   ptab.clear();
    1046   int_4 tsz;
    1047   GetRawI4(tsz);
    1048   int_8 tpos;
    1049   for(int kk=0; kk<tsz; kk++) {
    1050     GetRawI8(tpos);
    1051     ptab.push_back(tpos);
    1052   }
    1053   return;
    1054402}
    1055403
     
    1125473
    1126474
    1127 void
    1128 PInPersist::AnalyseTags(int lev)
    1129 {
    1130   unsigned char ppstag=0;
    1131   unsigned char ppst1,ppst2,ppst3,ppst30;
    1132   int_8 cpos,fsize;
    1133   uint_8 ui8,cid,oid;
    1134   int_4 i4;
    1135   int_8 i8;
    1136   char * buff;
    1137   string str;
    1138  
    1139   cout << "\n ---------------------------------------------------------- " << endl;
    1140   cout << " PInPersist::AnalyseTags(Level= " << lev << ")" << endl;
    1141 
    1142 
    1143   cpos = s->tellg();
    1144   s->seekg(0,ios::end);
    1145   fsize = s->tellg();
    1146   s->seekg(cpos,ios::beg);
    1147 
    1148   cout << "   Version= " << Version() << " FileSize= " << fsize
    1149        << " Creation Date= " << CreationDateStr() <<  endl;
    1150  
    1151   uint_8 totntags = 0;
    1152   bool eofok = false;
    1153 
    1154   while ( (ppstag != PPS_EOF) &&  (cpos < fsize) ) {
    1155     cpos = s->tellg();
    1156     GetRawUByte(ppstag);
    1157     totntags++;
    1158 
    1159     ppst1 = ppstag&0x0f;  // bits 0123
    1160     ppst2 = ppstag&0x30;  // bits     45
    1161     ppst3 = ppstag&0xc0;  // bits       67
    1162     ppst30 = ppstag&0xc1; // bits 0     67
    1163     if ((ppst2 == 0) && (ppst3 == 0) ) {
    1164       switch (ppst1) {
    1165 
    1166       case PPS_NULL :
    1167         if (lev > 1)  cout << "<PPS_NULL> tag at position " << hex << cpos << dec << endl;
    1168         break;
    1169 
    1170       case PPS_STRING :
    1171         GetRawI4(i4);
    1172         if (lev > 1)  cout << "<PPS_STRING> tag at position " << hex << cpos << dec
    1173                            << " Length=" << i4 << endl;
    1174         s->seekg(i4,ios::cur);
    1175         break;
    1176 
    1177       case PPS_OBJECT :
    1178         GetRawU8(cid);
    1179         GetRawU8(oid);
    1180         cout << "<PPS_OBJECT> tag at position " << hex << cpos << " ClassId= " << cid
    1181              << "  ObjectId= " << oid << dec << endl;
    1182         break;
    1183 
    1184       case PPS_REFERENCE :
    1185         GetRawU8(oid);
    1186         GetRawI8(i8);
    1187         cout << "<PPS_REFERENCE> tag at position " << hex << cpos << "  ObjectId= "
    1188              << oid << "  OrigPos=" << i8 << dec << endl;
    1189         break;
    1190 
    1191       case PPS_NAMETAG_MARK :
    1192         cout << "<PPS_NAMETAG_MARK> tag at position " << hex << cpos << dec << endl;
    1193         break;
    1194 
    1195       case PPS_POSTAG_MARK :
    1196         GetRawI8(i8);   
    1197         cout << "<PPS_POSTAG_MARK> tag at position " << hex << cpos
    1198              << " TPos=" << i8 << dec << endl;
    1199         break;
    1200      
    1201       case PPS_ENDOBJECT :
    1202         GetRawU8(oid);
    1203         cout << "<PPS_ENDOBJECT> tag at position " << hex << cpos << "  ObjectId= "
    1204              << oid << dec << endl;
    1205         break;
    1206 
    1207       case PPS_POSTAG_TABLE :
    1208         GetRawI4(i4);
    1209         for(int kkt=0; kkt<i4; kkt++)  GetRawI8(i8);   
    1210         cout << "<PPS_POSTAG_TABLE> tag at position " << hex << cpos << dec << endl;
    1211         break;
    1212 
    1213       case PPS_NAMETAG_TABLE :
    1214         GetRawI8(i8);
    1215         GetRawI4(i4);
    1216         buff = new char[i4+1];
    1217         GetRawBytes(buff, i4);
    1218         buff[i4] = '\0';  str = buff;
    1219         delete[] buff;
    1220         cout << "<PPS_TAG> tag at position " << hex << cpos << dec
    1221              << " Name= " << str << endl;
    1222         break;
    1223 
    1224       case PPS_EOF :
    1225         GetRawI8(i8);   
    1226         cout << "<PPS_EOF> tag at position " << hex << cpos 
    1227              << " TagPos=" << i8 << dec << endl;
    1228         eofok = true;
    1229         break;
    1230 
    1231       default :
    1232         cerr << " ERROR : Unexpected tag value " << hex << ppstag
    1233              << " At position" << cpos << dec << endl;
    1234         throw FileFormatExc("PInPersist::AnalyseTags() - Unexpected tag value !");
    1235       }
    1236     }
    1237     else {
    1238       string dtype = "???? x";
    1239       if (ppst30 == PPS_DATATYPE_COMPLEX) dtype = "COMPLEX x";
    1240       else if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
    1241       else if (ppst3 == PPS_DATATYPE_FLOAT) dtype = "FLOAT x";
    1242       else if (ppst3 == PPS_DATATYPE_INTEGER) dtype = "INTEGER x";
    1243       else if (ppst3 == PPS_DATATYPE_UNSIGNED) dtype = "UNSIGNED x";
    1244       int_4 dsize = ppst1;
    1245       int_4 dsizeskip = dsize;
    1246       if (ppst30 == PPS_DATATYPE_COMPLEX) {
    1247         dsize--;
    1248         dsizeskip = 2*dsize;
    1249       }
    1250       char sb[16];
    1251       sprintf(sb, "%d", dsize);
    1252       dtype += sb;
    1253 
    1254       switch (ppst2) {
    1255 
    1256       case PPS_SIMPLE :
    1257         if (lev > 2)  cout << "<PPS_SIMPLE> tag at position " << hex << cpos << dec
    1258                            << " DataType=" << dtype << endl;
    1259         s->seekg(dsizeskip, ios::cur);
    1260         break;
    1261 
    1262       case PPS_SIMPLE_ARRAY4 :
    1263         GetRawI4(i4);
    1264         if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec
    1265                            << " DataType=" << dtype << " NElts= " << i4 << endl;
    1266         s->seekg((int_8)dsizeskip*(int_8)i4, ios::cur);
    1267         break;
    1268 
    1269       case PPS_SIMPLE_ARRAY8 :
    1270         GetRawU8(ui8);
    1271         if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec
    1272                            << " DataType=" << dtype << " NElts= " << ui8 << endl;
    1273         s->seekg((int_8)dsizeskip*ui8, ios::cur);
    1274         break;
    1275       }
    1276     }
    1277   }
    1278   if (!eofok)
    1279     throw FileFormatExc("PInPersist::AnalyseTags() - Not found <PPS_EOF> tag ");
    1280 
    1281   cout << " PInPersist::AnalyseTags() - End - Total Number of Tags= " << totntags << endl;
    1282   cout << " ---------------------------------------------------------- \n" << endl;
    1283   return;
    1284 }
    1285475
    1286476void
     
    1359549//--
    1360550POutPersist::POutPersist(string const& flnm, int endianness)
    1361 {
    1362   if (endianness == -1)
    1363     bigEndian = IS_BIG_ENDIAN;
    1364   else
    1365     bigEndian = endianness;
    1366 
     551  : PPFBinaryOutputStream(flnm, endianness)
     552{
    1367553  // PPS (POutPersist stream) Object Id initialisation
    1368554  pps_OId = 0;
    1369   // Output stream creation
    1370   s = new RawOutFileStream(flnm.c_str());
    1371   version = 3;
    1372   // Header
    1373   PutRawBytes("SOS-SOPHYA-PPersistFile V3               ",32);
    1374   PutRawBytes(bigEndian
    1375            ? "BIG-ENDIAN                             "
    1376            : "LITTLE-ENDIAN                          ",32);
    1377 
    1378 // ---- GMT creation date of the file
    1379   time_t tm = time(NULL);
    1380   char datestring[33];
    1381   int l=strftime(datestring,32,"%d/%m/%Y %H:%M:%S GMT",gmtime(&tm));
    1382   for(int i=l; i<32; i++)  datestring[i] = ' ';
    1383   datestring[32] = '\0';
    1384   PutRawBytes(datestring, 32);
    1385   filename = flnm;
    1386555}
    1387556
    1388557POutPersist::~POutPersist()
    1389558{
    1390   if (tags.size() == 0) {
    1391     PutRawUByte(PPS_EOF);
    1392     PutRawI8(-1);
    1393   } else {
    1394     int_8 tagPos;
    1395     tagPos = s->tellp();
    1396     for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
    1397       string name = (*i).first;
    1398       int_8 pos = (*i).second;
    1399       PutRawUByte(PPS_NAMETAG_TABLE);                       // This is a tag
    1400       PutRawI8(pos);                             // position of previous tag
    1401       PutRawI4(name.length());                   // length of the name
    1402       PutRawBytes(name.c_str(), name.length());  // name, without final "0".
    1403     }
    1404     PutRawUByte(PPS_EOF);
    1405     PutRawI8(tagPos);
    1406   }
    1407 
    1408   delete s;   // Close the stream
    1409 }
    1410 
    1411 int_8
    1412 POutPersist::WritePositionTag()
    1413 {
    1414   int_8 tagpos;
    1415   tagpos = s->tellp();
    1416   PutRawByte(PPS_POSTAG_MARK);
    1417   PutI8(tagpos);
    1418   return(tagpos);
    1419 }
    1420 
    1421 void
    1422 POutPersist::WriteNameTag(string const& name)
    1423 {
    1424   if (name.length() > MAXTAGLEN)
    1425     throw ParmError("POutPersist::WriteNameTag   tag name too long");
    1426 
    1427   if (tags.find(name) != tags.end())
    1428     throw DuplicateIdExc("POutPersist::WriteNameTag   duplicate tag name");
    1429 
    1430   // Get current file position
    1431   int_8 tagPos;
    1432   tagPos = s->tellp();
    1433 
    1434   tags[name] = tagPos;
    1435   PutRawUByte(PPS_NAMETAG_MARK);                       // This is a tag
    1436   //  objList.clear(); // $CHECK$ EA 171199  - Ne pas faire ? Reza 03/2000
    1437 }
    1438 
    1439 //++
    1440 // void POutPersist::PutByte(char& c)
    1441 // void POutPersist::PutBytes(void const* ptr, size_t bytes)
    1442 // void POutPersist::PutR4   (r_4 result)
    1443 // void POutPersist::PutR4s  (r_4 const* tab, size_t n)
    1444 // void POutPersist::PutR8   (r_8 result)
    1445 // void POutPersist::PutR8s  (r_8 const* tab, size_t n)
    1446 // void POutPersist::PutI2   (int_2 result)
    1447 // void POutPersist::PutI2s  (int_2 const* tab, size_t n)
    1448 // void POutPersist::PutU2   (uint_2 result)
    1449 // void POutPersist::PutU2s  (uint_2 const* tab, size_t n)
    1450 // void POutPersist::PutI4   (int_4 result)
    1451 // void POutPersist::PutI4s  (int_4 const* tab, size_t n)
    1452 // void POutPersist::PutU4   (uint_4 result)
    1453 // void POutPersist::PutU4s  (uint_4 const* tab, size_t n)
    1454 // void POutPersist::PutI8   (int_8 result)
    1455 // void POutPersist::PutI8s  (int_8 const* tab, size_t n)
    1456 // void POutPersist::PutU8   (uint_8 result)
    1457 // void POutPersist::PutU8s  (uint_8 const* tab, size_t n)
    1458 // void POutPersist::PutStr  (string const&)
    1459 //      Ecriture de données portables.. Pour chaque type
    1460 //      de données, on peut écrire une valeur, ou un tableau de valeurs.
    1461 // void POutPersist::PutLine(char const* ptr, size_t len)
    1462 //      Ecriture d'une ligne de texte dans le fichier PPersist.
    1463 //--
    1464 
    1465 
    1466 
    1467 
    1468 void
    1469 POutPersist::PutRawBytes(void const* ptr, size_t bytes)
    1470 {
    1471   s->write((char const*)ptr, bytes);
    1472 }
    1473 
    1474 void
    1475 POutPersist::PutRawByte(char c)
    1476 {
    1477   PutRawBytes(&c, 1);
    1478 }
    1479 
    1480 void
    1481 POutPersist::PutRawUByte(unsigned char c)
    1482 {
    1483   PutRawBytes(&c, 1);
    1484 }
    1485 
    1486 void
    1487 POutPersist::PutRawI2   (int_2 val)
    1488 {
    1489   if (bigEndian != IS_BIG_ENDIAN)
    1490     bswap2(&val);
    1491 
    1492   PutRawBytes(&val, sizeof(int_2));
    1493 }
    1494 
    1495 void
    1496 POutPersist::PutRawI4   (int_4 val)
    1497 {
    1498   if (bigEndian != IS_BIG_ENDIAN)
    1499     bswap4(&val);
    1500 
    1501   PutRawBytes(&val, sizeof(int_4));
    1502 }
    1503 
    1504 void
    1505 POutPersist::PutRawI8   (int_8 val)
    1506 {
    1507   if (bigEndian != IS_BIG_ENDIAN)
    1508     bswap8(&val);
    1509 
    1510   PutRawBytes(&val, sizeof(int_8));
    1511 }
    1512 
    1513 void
    1514 POutPersist::PutRawU8   (uint_8 val)
    1515 {
    1516   if (bigEndian != IS_BIG_ENDIAN)
    1517     bswap8(&val);
    1518 
    1519   PutRawBytes(&val, sizeof(uint_8));
    1520 }
    1521 
    1522 void
    1523 POutPersist::PutArrayTag(short datasz, size_t sz, short datatype)
    1524 // datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
    1525 {
    1526   if (sz <= 0x7fffffff) {
    1527     PutRawUByte(PPS_SIMPLE_ARRAY4 + datasz + datatype);
    1528     PutRawI4(sz);
    1529   } else {
    1530     PutRawUByte(PPS_SIMPLE_ARRAY8 + datasz + datatype);
    1531     PutRawU8(sz);
    1532   }
    1533 }
    1534 
    1535 void
    1536 POutPersist::PutByte(char c)
    1537 {
    1538   PutRawByte(PPS_SIMPLE + 1 + PPS_DATATYPE_CHAR);
    1539   PutRawBytes(&c, 1);
    1540 }
    1541 
    1542 
    1543 
    1544 void
    1545 POutPersist::PutBytes(void const* ptr, size_t bytes)
    1546 {
    1547   PutArrayTag(1, bytes, PPS_DATATYPE_CHAR);
    1548   PutRawBytes(ptr, bytes);
    1549 }
    1550 
    1551 void
    1552 POutPersist::PutR4   (r_4 val)
    1553 {
    1554   PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_FLOAT);
    1555  
    1556   if (bigEndian != IS_BIG_ENDIAN)
    1557     bswap4(&val);
    1558 
    1559   PutRawBytes(&val, sizeof(r_4));
    1560 }
    1561 
    1562 void
    1563 POutPersist::PutR4s  (r_4 const* tab, size_t n)
    1564 {
    1565   PutArrayTag(4, n, PPS_DATATYPE_FLOAT);
    1566 
    1567   if (bigEndian == IS_BIG_ENDIAN) {
    1568     PutRawBytes(tab, n*sizeof(r_4));
    1569   } else {
    1570     for (unsigned int i=0; i<n; i++) {
    1571       r_4 val = tab[i];
    1572       bswap4(&val);
    1573       PutRawBytes(&val, sizeof(r_4));
    1574     }
    1575   }
    1576 }
    1577 
    1578 void
    1579 POutPersist::PutR8   (r_8 val)
    1580 {
    1581   PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_FLOAT);
    1582 
    1583   if (bigEndian != IS_BIG_ENDIAN)
    1584     bswap8(&val);
    1585 
    1586   PutRawBytes(&val, sizeof(r_8));
    1587 }
    1588 
    1589 void
    1590 POutPersist::PutR8s  (r_8 const* tab, size_t n)
    1591 {
    1592   PutArrayTag(8, n, PPS_DATATYPE_FLOAT);
    1593 
    1594   if (bigEndian == IS_BIG_ENDIAN) {
    1595     PutRawBytes(tab, n*sizeof(r_8));
    1596   } else {
    1597     for (unsigned int i=0; i<n; i++) {
    1598       r_8 val = tab[i];
    1599       bswap8(&val);
    1600       PutRawBytes(&val, sizeof(r_8));
    1601     }
    1602   }
    1603 }
    1604 
    1605 void
    1606 POutPersist::PutI1   (int_1 val)
    1607 {
    1608   PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_INTEGER);
    1609   PutRawBytes(&val, sizeof(int_1));
    1610 }
    1611 
    1612 void
    1613 POutPersist::PutI1s  (int_1 const* tab, size_t n)
    1614 {
    1615   PutArrayTag(1, n, PPS_DATATYPE_INTEGER);
    1616   PutRawBytes(tab, n*sizeof(int_1));
    1617 }
    1618 
    1619 void
    1620 POutPersist::PutU1   (uint_1 val)
    1621 {
    1622   PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_UNSIGNED);
    1623   PutRawBytes(&val, sizeof(uint_1));
    1624 }
    1625 
    1626 void
    1627 POutPersist::PutU1s  (uint_1 const* tab, size_t n)
    1628 {
    1629   PutArrayTag(1, n, PPS_DATATYPE_UNSIGNED);
    1630   PutRawBytes(tab, n*sizeof(uint_1));
    1631 }
    1632 
    1633 void
    1634 POutPersist::PutI2   (int_2 val)
    1635 {
    1636   PutRawUByte(PPS_SIMPLE + 2 + PPS_DATATYPE_INTEGER);
    1637 
    1638   if (bigEndian != IS_BIG_ENDIAN)
    1639     bswap2(&val);
    1640 
    1641   PutRawBytes(&val, sizeof(int_2));
    1642 }
    1643 
    1644 void
    1645 POutPersist::PutI2s  (int_2 const* tab, size_t n)
    1646 {
    1647   PutArrayTag(2, n, PPS_DATATYPE_INTEGER);
    1648  
    1649   if (bigEndian == IS_BIG_ENDIAN) {
    1650     PutRawBytes(tab, n*sizeof(int_2));
    1651   } else {
    1652     for (unsigned int i=0; i<n; i++) {
    1653       int_2 val = tab[i];
    1654       bswap2(&val);
    1655       PutRawBytes(&val, sizeof(int_2));
    1656     }
    1657   }
    1658 }
    1659 
    1660 void
    1661 POutPersist::PutU2   (uint_2 val)
    1662 {
    1663   PutRawUByte(PPS_SIMPLE + 2 + PPS_DATATYPE_UNSIGNED);
    1664 
    1665   if (bigEndian != IS_BIG_ENDIAN)
    1666     bswap2(&val);
    1667 
    1668   PutRawBytes(&val, sizeof(uint_2));
    1669 }
    1670 
    1671 void
    1672 POutPersist::PutU2s  (uint_2 const* tab, size_t n)
    1673 {
    1674   PutArrayTag(2, n, PPS_DATATYPE_UNSIGNED);
    1675 
    1676   if (bigEndian == IS_BIG_ENDIAN) {
    1677     PutRawBytes(tab, n*sizeof(uint_2));
    1678   } else {
    1679     for (unsigned int i=0; i<n; i++) {
    1680       uint_2 val = tab[i];
    1681       bswap2(&val);
    1682       PutRawBytes(&val, sizeof(uint_2));
    1683     }
    1684   }
    1685 }
    1686 
    1687 void
    1688 POutPersist::PutI4   (int_4 val)
    1689 {
    1690   PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_INTEGER);
    1691 
    1692   if (bigEndian != IS_BIG_ENDIAN)
    1693     bswap4(&val);
    1694 
    1695   PutRawBytes(&val, sizeof(int_4));
    1696 }
    1697 
    1698 void
    1699 POutPersist::PutI4s  (int_4 const* tab, size_t n)
    1700 {
    1701   PutArrayTag(4, n, PPS_DATATYPE_INTEGER);
    1702 
    1703   if (bigEndian == IS_BIG_ENDIAN) {
    1704     PutRawBytes(tab, n*sizeof(int_4));
    1705   } else {
    1706     for (unsigned int i=0; i<n; i++) {
    1707       int_4 val = tab[i];
    1708       bswap4(&val);
    1709       PutRawBytes(&val, sizeof(int_4));
    1710     }
    1711   }
    1712 }
    1713 
    1714 void
    1715 POutPersist::PutU4   (uint_4 val)
    1716 {
    1717   PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_UNSIGNED);
    1718 
    1719   if (bigEndian != IS_BIG_ENDIAN)
    1720     bswap4(&val);
    1721 
    1722   PutRawBytes(&val, sizeof(uint_4));
    1723 }
    1724 
    1725 void
    1726 POutPersist::PutU4s  (uint_4 const* tab, size_t n)
    1727 {
    1728   PutArrayTag(4, n, PPS_DATATYPE_UNSIGNED);
    1729 
    1730   if (bigEndian == IS_BIG_ENDIAN) {
    1731     PutRawBytes(tab, n*sizeof(uint_4));
    1732   } else {
    1733     for (unsigned int i=0; i<n; i++) {
    1734       uint_4 val = tab[i];
    1735       bswap4(&val);
    1736       PutRawBytes(&val, sizeof(uint_4));
    1737     }
    1738   }
    1739 }
    1740 
    1741 void
    1742 POutPersist::PutI8   (int_8 val)
    1743 {
    1744   PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_INTEGER);
    1745 
    1746   if (bigEndian != IS_BIG_ENDIAN)
    1747     bswap8(&val);
    1748 
    1749   PutRawBytes(&val, sizeof(int_8));
    1750 }
    1751 
    1752 void
    1753 POutPersist::PutI8s  (int_8 const* tab, size_t n)
    1754 {
    1755   PutArrayTag(8, n, PPS_DATATYPE_INTEGER);
    1756 
    1757   if (bigEndian == IS_BIG_ENDIAN) {
    1758     PutRawBytes(tab, n*sizeof(int_8));
    1759   } else {
    1760     for (unsigned int i=0; i<n; i++) {
    1761       int_8 val = tab[i];
    1762       bswap8(&val);
    1763       PutRawBytes(&val, sizeof(int_8));
    1764     }
    1765   }
    1766 }
    1767 
    1768 void
    1769 POutPersist::PutU8   (uint_8 val)
    1770 {
    1771   PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_UNSIGNED);
    1772 
    1773   if (bigEndian != IS_BIG_ENDIAN)
    1774     bswap8(&val);
    1775 
    1776   PutRawBytes(&val, sizeof(uint_8));
    1777 }
    1778 
    1779 void
    1780 POutPersist::PutU8s  (uint_8 const* tab, size_t n)
    1781 {
    1782   PutArrayTag(8, n, PPS_DATATYPE_UNSIGNED);
    1783 
    1784   if (bigEndian == IS_BIG_ENDIAN) {
    1785     PutRawBytes(tab, n*sizeof(uint_8));
    1786   } else {
    1787     for (unsigned int i=0; i<n; i++) {
    1788       uint_8 val = tab[i];
    1789       bswap8(&val);
    1790       PutRawBytes(&val, sizeof(uint_8));
    1791     }
    1792   }
    1793 }
    1794 
    1795 void
    1796 POutPersist::PutStr(string const& str)
    1797 {
    1798   PutRawUByte(PPS_STRING);
    1799   PutRawI4(str.length());
    1800   PutRawBytes(str.c_str(), str.length());
    1801 }
    1802 
    1803 void
    1804 POutPersist::PutLine(char const* ptr, size_t len)
    1805 {
    1806   string str = ptr;
    1807   PutStr(str);
    1808 }
    1809 
    1810 
    1811 void
    1812 POutPersist::PutZ4   (complex<r_4> val)
    1813 {
    1814   PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_COMPLEX);
    1815   r_4 reim[2];
    1816   reim[0] = val.real();
    1817   reim[1] = val.imag();
    1818   if (bigEndian != IS_BIG_ENDIAN) {
    1819     bswap4(reim);
    1820     bswap4(reim+1);
    1821   }
    1822   PutRawBytes(reim, 2*sizeof(r_4));
    1823 }
    1824 
    1825 void
    1826 POutPersist::PutZ4s  (complex<r_4> const* tab, size_t n)
    1827 {
    1828   PutArrayTag(4, n, PPS_DATATYPE_COMPLEX);
    1829 
    1830   if (bigEndian == IS_BIG_ENDIAN) {
    1831     PutRawBytes(tab, n*2*sizeof(r_4));
    1832   } else {
    1833     for (unsigned int i=0; i<n; i++) {
    1834       r_4 reim[2];
    1835       reim[0] = tab[i].real();
    1836       reim[1] = tab[i].imag();
    1837       bswap4(reim);
    1838       bswap4(reim+1);
    1839       PutRawBytes(reim, 2*sizeof(r_4));
    1840     }
    1841   }
    1842 }
    1843 
    1844 void
    1845 POutPersist::PutZ8   (complex<r_8> val)
    1846 {
    1847   PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_COMPLEX);
    1848   r_8 reim[2];
    1849   reim[0] = val.real();
    1850   reim[1] = val.imag();
    1851   if (bigEndian != IS_BIG_ENDIAN) {
    1852     bswap8(reim);
    1853     bswap8(reim+1);
    1854   }
    1855   PutRawBytes(reim, 2*sizeof(r_8));
    1856 }
    1857 
    1858 void
    1859 POutPersist::PutZ8s  (complex<r_8> const* tab, size_t n)
    1860 {
    1861   PutArrayTag(8, n, PPS_DATATYPE_COMPLEX);
    1862 
    1863   if (bigEndian == IS_BIG_ENDIAN) {
    1864     PutRawBytes(tab, n*2*sizeof(r_8));
    1865   } else {
    1866     for (unsigned int i=0; i<n; i++) {
    1867       r_8 reim[2];
    1868       reim[0] = tab[i].real();
    1869       reim[1] = tab[i].imag();
    1870       bswap8(reim);
    1871       bswap8(reim+1);
    1872       PutRawBytes(reim, 2*sizeof(r_8));
    1873     }
    1874   }
    1875 }
    1876 
    1877 void
    1878 POutPersist::PutPosTagTable(int_8 const * ptab, size_t sz)
    1879 {
    1880   PutRawUByte(PPS_POSTAG_TABLE);
    1881   int_4 tsz = sz;
    1882   PutRawI4(tsz);
    1883   for(int kk=0; kk<tsz; kk++)
    1884     PutRawI8(ptab[kk]);
    1885   return;
    1886 }
    1887 
    1888 void
    1889 POutPersist::PutPosTagTable(vector<int_8> const& ptab)
    1890 {
    1891   PutRawUByte(PPS_POSTAG_TABLE);
    1892   int_4 tsz = ptab.size();
    1893   PutRawI4(tsz);
    1894   for(int kk=0; kk<tsz; kk++)
    1895     PutRawI8(ptab[kk]);
    1896   return;
    1897 }
     559}
     560
    1898561
    1899562void
Note: See TracChangeset for help on using the changeset viewer.