Changeset 1310 in Sophya for trunk/SophyaLib/BaseTools/dvlist.cc


Ignore:
Timestamp:
Nov 9, 2000, 4:39:19 PM (25 years ago)
Author:
ansari
Message:

Changement de codage du type ds MuTyV (en prevision d'introduction de
nouveaux types codes ds MuTyV + Modif ObjFIO<DVList> - Reza 9/11/2000

File:
1 edited

Legend:

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

    r1245 r1310  
    158158for(it = dvl.mvlist.begin(); it != dvl.mvlist.end(); it++)
    159159  {
    160   switch ((*it).second.elval.typ)
     160  switch ((*it).second.elval.Type())
    161161    {
    162     case 'I' :
     162    case MuTyV::MTVInteger :
    163163      SetI((*it).first, (*it).second.elval.iv);
    164164      break;
    165     case 'D' :
     165    case  MuTyV::MTVFloat :
    166166      SetD((*it).first, (*it).second.elval.dv);
    167167      break;
    168     case 'Z' :
     168    case MuTyV::MTVComplex :
    169169      SetZ((*it).first, complex<r_8>((*it).second.elval.dv, (*it).second.elval.dv_im));
    170170      break;
    171     case 'S' :
     171    case MuTyV::MTVString :
    172172      SetS((*it).first, *((*it).second.elval.strv));
    173173      break;
     
    398398os << "DVList::Print() - NVar= " << (int)mvlist.size() << "\n";
    399399if (comment.length() > 0)  os << comment << endl;
    400 char buff[256];
     400char buff[1024];
    401401ValList::const_iterator it;
    402402for(it = mvlist.begin(); it != mvlist.end(); it++)  {
    403   switch ((*it).second.elval.typ)
     403  switch ((*it).second.elval.Type())
    404404    {
    405     case 'I' :
     405    case MuTyV::MTVInteger :
    406406      sprintf(buff, "%s = %ld (int) %s\n", (*it).first.substr(0,64).c_str(),
    407407              (long)((*it).second.elval.iv), (*it).second.elcomm.substr(0,128).c_str());
    408408      break;
    409     case 'D' :
     409    case MuTyV::MTVFloat :
    410410      sprintf(buff, "%s = %.20g (double) %s\n", (*it).first.substr(0,64).c_str(),
    411411              (*it).second.elval.dv, (*it).second.elcomm.substr(0,128).c_str());
    412412      break;
    413     case 'Z' :
     413    case MuTyV::MTVComplex :
    414414      sprintf(buff, "%s = %.20g %.20g i (complex) %s\n", (*it).first.substr(0,64).c_str(),
    415415              (*it).second.elval.dv, (*it).second.elval.dv_im, (*it).second.elcomm.substr(0,128).c_str());
    416416      break;
    417     case 'S' :
     417    case MuTyV::MTVString :
    418418      sprintf(buff, "%s = %s (string) %s\n", (*it).first.substr(0,64).c_str(),
    419               (*it).second.elval.strv->c_str(), (*it).second.elcomm.substr(0,128).c_str());
     419              (*it).second.elval.strv->substr(0,800).c_str(), (*it).second.elcomm.substr(0,128).c_str());
    420420      break;
    421421    default :
     
    469469void        ObjFileIO<DVList>::WriteSelf(POutPersist& s) const
    470470{
    471 char buf[512];
     471char buf[1024];
    472472string sfw;
    473 
    474473int lc = dobj->Comment().length();
    475 if (lc > 0) {
    476   sprintf(buf,"Comment: ( %6d ) ", lc);
    477   sfw = buf;  s.PutStr(sfw);
    478   s.PutStr(dobj->Comment());
    479   }
    480 sfw = "----Variable-List---------------";  s.PutStr(sfw);
     474//  itab -  0 : Version,  1 : NVar,  2  : Comment length, 3 reserved
     475uint_4 itab[4];
     476itab[0] = 2;  // Version number = 2
     477itab[1] = dobj->Size();
     478itab[2] = lc;
     479itab[3] = 0;
     480s.Put(itab, 4);
     481
     482if (lc > 0) s.PutStr(dobj->Comment());
     483sfw = "\n----Variable-List---------------\n"; 
     484s.PutStr(sfw);
     485
    481486DVList::ValList::const_iterator it;
    482487for(it = dobj->Begin(); it != dobj->End(); it++)  {
    483   switch ((*it).second.elval.typ) {
    484     case 'I' :
    485       sprintf(buf,"I %s %ld", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.iv) );
     488  switch ((*it).second.elval.Type()) {
     489    case MuTyV::MTVInteger :
     490      sprintf(buf,"I %s %ld\n", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.iv) );
    486491      sfw = buf;  s.PutStr(sfw);
    487492      break;
    488     case 'D' :
    489       sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv );
     493    case MuTyV::MTVFloat :
     494      sprintf(buf,"F %s %.20g\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv );
    490495      sfw = buf;  s.PutStr(sfw);
    491496      break;
    492     case 'Z' :
    493       sprintf(buf,"Z %s %.20g %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv,
     497    case MuTyV::MTVComplex :
     498      sprintf(buf,"Z %s %.20g %.20g\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv,
    494499                                      (*it).second.elval.dv_im);
    495500      sfw = buf;  s.PutStr(sfw);
    496501      break;
    497     case 'S' :
    498       sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.elval.strv->c_str() );
     502    case MuTyV::MTVString :
     503      sprintf(buf,"S %s %s\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.strv->substr(0,960).c_str() );
    499504      sfw = buf;  s.PutStr(sfw);
    500505      break;
     
    515520void        ObjFileIO<DVList>::ReadSelf(PInPersist& s)
    516521{
    517 char buf[512];
     522char buf[1024];
    518523string sfr;
    519524int_8 j,iv,k;
     
    524529dobj->Clear();
    525530
    526 s.GetStr(sfr);  // Pour lire les "------- "
    527 if (sfr[0] != '-') {  // Il y a un champ commentaire a lire
     531//  itab -  0 : Version,  1 : NVar,  2  : Comment length, 3 reserved
     532uint_4 itab[4];
     533s.Get(itab, 4);
     534if (itab[2] > 0) {  // Il y a un champ commentaire a lire
    528535  s.GetStr(sfr);
    529536  dobj->Comment() = sfr;
    530537  }
     538
     539s.GetStr(sfr);  // Pour lire les "------- "
    531540
    532541string key="";
    533542while(ok) {
    534543  s.GetStr(sfr);
    535   strncpy(buf, sfr.c_str(), 512);
    536   buf[511] = '\0';
     544  strncpy(buf, sfr.c_str(), 1024);
     545  buf[1023] = '\0';
     546  j = strlen(buf)-1;
     547  if ( (j >= 0) && (buf[j] == '\n') )  buf[j] = '\0';
    537548  if (strncmp(buf,"ZZZZZ",5) == 0)  { ok=false; break; }
    538549  if (buf[0] == '#') {
     
    548559      dobj->SetI(key, iv);
    549560      break;
    550     case 'D' :
     561    case 'F' :
    551562      dv = atof(buf+j+1);
    552563      key = buf+2;
     
    562573      dobj->SetZ(key, z);
    563574      break;
    564     case 'S' :
     575    case  'S' :
    565576      key = buf+2;
    566577      dobj->SetS(key, buf+j+1);
     
    569580      break;
    570581    }
    571   }
     582  }
     583if (dobj->Size() != itab[1])  // Probleme !!!
     584  throw FileFormatExc("ObjFileIO<DVList>::ReadSelf() Error in Nb. Variables !");
    572585}
    573586
Note: See TracChangeset for help on using the changeset viewer.