Changeset 1310 in Sophya for trunk/SophyaLib


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

Location:
trunk/SophyaLib/BaseTools
Files:
5 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
  • trunk/SophyaLib/BaseTools/dvlist.h

    r1157 r1310  
    3333  void              Clear();
    3434  DVList&           Merge(const DVList&);
     35
     36  //! Returns the number of elements (variables) in DVList object
     37  inline int        Size() { return(mvlist.size()); }
     38  //! Returns the number of elements (variables) in DVList object
     39  inline int        NVar() { return(mvlist.size()); }
    3540
    3641  int_8             GetI(string const& key, int_8 def=-1) const;
  • trunk/SophyaLib/BaseTools/mutyv.cc

    r1225 r1310  
    3838{
    3939  typ = a.typ;  iv = a.iv;  dv = a.dv;  dv_im = a.dv_im;
    40   if (typ == 'S')  strv = new string(*(a.strv));
     40  if (typ == MTVString)  strv = new string(*(a.strv));
    4141  else strv = NULL;
    4242}
     
    5151MuTyV::MuTyV(char const* s)
    5252{
    53   typ = 'S';
     53  typ = MTVString;
    5454  strv = new string(s);
    5555  mutyv_decodestr(s, dv, dv_im);
     
    6060MuTyV::MuTyV(string const& s)
    6161{
    62   typ = 'S';
     62  typ = MTVString;
    6363  strv = new string(s);
    6464  mutyv_decodestr(s.c_str(), dv, dv_im);
     
    7070{
    7171  typ = a.typ;  iv = a.iv;  dv = a.dv;  dv_im = a.dv_im;
    72   if (typ == 'S')  {
     72  if (typ == MTVString)  {
    7373    if (strv) *strv = *(a.strv); 
    7474    else strv = new string(*(a.strv));
     
    8080char * MuTyV::operator= (char* s)
    8181{
    82   typ = 'S';
     82  typ = MTVString;
    8383  if (strv) *strv = s; 
    8484  else strv = new string(s);
     
    9191string & MuTyV::operator= (string& s)
    9292{
    93   typ = 'S';
     93  typ = MTVString;
    9494  if (strv) *strv = s; 
    9595  else strv = new string(s);
     
    102102MuTyV::operator string() const
    103103{
    104   if (typ == 'S')  return(*strv);
     104  if (typ == MTVString)  return(*strv);
    105105  else {
    106106    char buff[96];
    107     if (typ == 'I')  sprintf(buff,"%ld", (long)iv);
    108     else if (typ == 'D') sprintf(buff,"%.20g", dv);
    109     else if (typ == 'Z') sprintf(buff,"(%.20g , %.20g)", dv, dv_im);
     107    if (typ == MTVInteger)  sprintf(buff,"%ld", (long)iv);
     108    else if (typ == MTVFloat) sprintf(buff,"%.20g", dv);
     109    else if (typ == MTVComplex) sprintf(buff,"(%.20g , %.20g)", dv, dv_im);
    110110    else buff[0] = '\0';
    111111    return(string(buff));
  • trunk/SophyaLib/BaseTools/mutyv.h

    r1290 r1310  
    2020public:
    2121
    22   inline MuTyV() { typ = 'I'; iv = 0;  dv = dv_im = 0.;  strv = NULL; }
     22  enum MTVType {
     23    MTVInteger,
     24    MTVFloat,
     25    MTVComplex,
     26    MTVString
     27  };
     28
     29  inline MuTyV() { typ = MTVInteger; iv = 0;  dv = dv_im = 0.;  strv = NULL; }
    2330         MuTyV(MuTyV const & a);
    24   inline MuTyV(uint_2 i) { typ = 'I'; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; }
    25   inline MuTyV(int_4 i)  { typ = 'I'; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; }
    26   inline MuTyV(int_8 i)  { typ = 'I'; iv = i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; }
    27   inline MuTyV(r_4 f) { typ = 'D'; dv = (r_8)f; iv = (int_8)f;  dv_im = 0.;  strv = NULL; }
    28   inline MuTyV(r_8 d) { typ = 'D'; dv = d;  iv = (int_8)d;  dv_im = 0.;  strv = NULL; }
    29   inline MuTyV(complex<r_4> z) { typ = 'Z'; dv = (r_8)z.real();  dv_im = z.imag(); 
     31  inline MuTyV(uint_2 i) { typ = MTVInteger; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; }
     32  inline MuTyV(int_4 i)  { typ = MTVInteger; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; }
     33  inline MuTyV(int_8 i)  { typ = MTVInteger; iv = i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; }
     34  inline MuTyV(r_4 f) { typ = MTVFloat; dv = (r_8)f; iv = (int_8)f;  dv_im = 0.;  strv = NULL; }
     35  inline MuTyV(r_8 d) { typ = MTVFloat; dv = d;  iv = (int_8)d;  dv_im = 0.;  strv = NULL; }
     36  inline MuTyV(complex<r_4> z) { typ = MTVComplex; dv = (r_8)z.real();  dv_im = z.imag(); 
    3037                                 iv = (int_8)dv;  strv = NULL; }
    31   inline MuTyV(complex<r_8> z) { typ = 'Z'; dv = z.real();  dv_im = z.imag(); 
     38  inline MuTyV(complex<r_8> z) { typ = MTVComplex; dv = z.real();  dv_im = z.imag(); 
    3239                                 iv = (int_8)dv;  strv = NULL; }
    3340
     
    3744         ~MuTyV();
    3845 
    39   inline char Type() const { return typ; }
     46  inline MTVType Type() const { return typ; }
    4047
    4148         MuTyV & operator= (MuTyV const & a);
    42   inline uint_2  operator= (uint_2 v)  { typ = 'I'; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(v); }
    43   inline int_4  operator= (int_4 v)  { typ = 'I'; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(v); }
    44   inline int_8  operator= (int_8 v)  { typ = 'I'; iv = v;  dv = (r_8)v; dv_im = 0.;  return(v); }
    45   inline r_4  operator= (r_4 v)  { typ = 'D'; dv = (r_8)v; iv = (int_8)v;  dv_im = 0.;  return(v); }
    46   inline r_8  operator= (r_8 v) { typ = 'D'; dv = v; iv = (int_8)v;  dv_im = 0.;  return(v); }
    47   inline complex<r_4> operator= (complex<r_4> v) { typ = 'Z'; dv = (r_8)v.real();  dv_im = v.imag();
     49  inline uint_2  operator= (uint_2 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(v); }
     50  inline int_4  operator= (int_4 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(v); }
     51  inline int_8  operator= (int_8 v)  { typ = MTVInteger; iv = v;  dv = (r_8)v; dv_im = 0.;  return(v); }
     52  inline r_4  operator= (r_4 v)  { typ = MTVFloat; dv = (r_8)v; iv = (int_8)v;  dv_im = 0.;  return(v); }
     53  inline r_8  operator= (r_8 v) { typ = MTVFloat; dv = v; iv = (int_8)v;  dv_im = 0.;  return(v); }
     54  inline complex<r_4> operator= (complex<r_4> v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag();
    4855                                                    iv = (int_8)dv;  return(v); }
    49   inline complex<r_8> operator= (complex<r_8> v) { typ = 'Z'; dv = (r_8)v.real();  dv_im = v.imag();
     56  inline complex<r_8> operator= (complex<r_8> v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag();
    5057                                                    iv = (int_8)dv;  return(v); }
    5158         char*  operator= (char* s);
     
    6673  r_8 dv_im;   /* for holding imaginary part of a complex */
    6774  string * strv;
    68   char typ;
     75  MTVType typ;
    6976
    7077};
  • trunk/SophyaLib/BaseTools/sversion.h

    r1283 r1310  
    33
    44#define SOPHYA_VERSION   0.9
    5 #define SOPHYA_REVISION  96
     5#define SOPHYA_REVISION  97
    66#define SOPHYA_TAG       "V_Oct2000"
    77
Note: See TracChangeset for help on using the changeset viewer.