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


Ignore:
Timestamp:
Jul 24, 2000, 2:49:24 PM (25 years ago)
Author:
ansari
Message:

Classe MuTyV separe et etendu pour support complexe - Reza 24/7/2000

File:
1 edited

Legend:

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

    r913 r1080  
    3838//--
    3939
    40 char MuTyV::myStrBuf[64];   // Declare static ds le .h
    4140
    4241static MuTyV ddvdum(-9.e19);
    4342
    44 /*!
    45    \class SOPHYA::MuTyV
    46    \ingroup SysTools
    47    Simple utility class which can be used to hold values of type
    48    string, integer (\b int_8) or float (\b r_8) and providing
    49    easy conversion methods between these types.
    50 */
    5143
    5244/*!
     
    6153   used to represent FITS headers. The class \b SOPHYA::ObjFileIO<DVList>
    6254   handles serialisation for DVList. (See SOPHYA::PPersist ).
    63    An
    64    \code
    65    //  ------- Using MuTyV objects -------
    66    MuTyV mvu;         // MuTyV variable declaration
    67    mvu = 60;          // mvu contains the integer value 60
    68    mvu = 66.6;        // and now the double value 66.6
    69    string ds = mvu;   // ds contains the string "66.6"
    70    MuTyV mvi(14);     // New MuTyV variable containing integer value 14
    71    r_4 x = mvi;       // x has the value 14.0
    72    MuTyV mvs("Bonjour !");  // mvs contains the string "Bonjour !"
    73    string s = mvs;          // s vaut "Bonjour, Ca va ?" 
     55   
    7456   //  ------- Using DVList objects ------
    7557   DVList  dvl;
     
    179161    {
    180162    case 'I' :
    181       SetI((*it).first, (*it).second.elval.mtv.iv);
     163      SetI((*it).first, (*it).second.elval.iv);
    182164      break;
    183165    case 'D' :
    184       SetD((*it).first, (*it).second.elval.mtv.dv);
     166      SetD((*it).first, (*it).second.elval.dv);
     167      break;
     168    case 'Z' :
     169      SetZ((*it).first, complex<r_8>((*it).second.elval.dv, (*it).second.elval.dv_im));
    185170      break;
    186171    case 'S' :
    187       SetS((*it).first, (*it).second.elval.mtv.strv);
     172      SetS((*it).first, *((*it).second.elval.strv));
    188173      break;
    189174    default :
     
    214199ValList::iterator it = mvlist.find(key);
    215200if (it == mvlist.end())  return(def);
    216 if ( (*it).second.elval.typ != 'I') return(def);
    217 return((*it).second.elval.mtv.iv);
     201return((*it).second.elval.iv);
    218202}
    219203
     
    225209ValList::iterator it = mvlist.find(key);
    226210if (it == mvlist.end())  return(def);
    227 if ( (*it).second.elval.typ != 'D') return(def);
    228 return((*it).second.elval.mtv.dv);
     211return((*it).second.elval.dv);
     212}
     213
     214/* --Methode-- */
     215/*! Returns the value corresponding to name \b key, converted to complex
     216    Default value \b def is returned if name \b key not found */
     217complex<r_8>       DVList::GetZ(string const& key, complex<r_8> def)
     218{
     219ValList::iterator it = mvlist.find(key);
     220if (it == mvlist.end())  return(def);
     221return((*it).second.elval.dv);
    229222}
    230223
     
    236229ValList::iterator it = mvlist.find(key);
    237230if (it == mvlist.end())  return(def);
    238 if ( (*it).second.elval.typ != 'S') return(def);
    239 return((*it).second.elval.mtv.strv);
     231return(*((*it).second.elval.strv));
    240232}
    241233
     
    252244// void  SetI(string const& key, int_8  val)
    253245// void  SetD(string const& key, r_8 val)
     246// void  SetZ(string const& key, complex<r_8> val)
    254247// void  SetS(string const& key, char*  val)
    255248// void  SetS(string const& key, string val)
    256 //      Crée la variable de nom "key", de type entier, double, string et
     249//      Crée la variable de nom "key", de type entier, double, complexe, string et
    257250//      lui attribue la valeur "val". Si une variable du même nom existe,
    258251//      sa valeur et eventuellement son type sont modifiés.  Les noms de
     
    280273
    281274/* --Methode-- */
     275void        DVList::SetZ(string const& key, complex<r_8> val)
     276/*! Appends or sets the complex value \b val in the list with name \b key */
     277{
     278Get(key) = val;
     279}
     280
     281/* --Methode-- */
    282282/*! Appends or sets the string value \b val in the list with name \b key */
    283283void        DVList::SetS(string const& key, char const* val)
     
    289289/* --Methode-- */
    290290/*! Appends or sets the string value \b val in the list with name \b key */
    291 void        DVList::SetS(string const& key, string val)
     291void        DVList::SetS(string const& key, string const& val)
    292292{
    293293MuTyV div(val);
     
    367367    case 'I' :
    368368      sprintf(buff, "%s = %ld (int) %s\n", (*it).first.substr(0,64).c_str(),
    369               (long)((*it).second.elval.mtv.iv), (*it).second.elcomm.substr(0,128).c_str());
     369              (long)((*it).second.elval.iv), (*it).second.elcomm.substr(0,128).c_str());
    370370      break;
    371371    case 'D' :
    372372      sprintf(buff, "%s = %.20g (double) %s\n", (*it).first.substr(0,64).c_str(),
    373               (*it).second.elval.mtv.dv, (*it).second.elcomm.substr(0,128).c_str());
     373              (*it).second.elval.dv, (*it).second.elcomm.substr(0,128).c_str());
     374      break;
     375    case 'Z' :
     376      sprintf(buff, "%s = %.20g %.20g i (complex) %s\n", (*it).first.substr(0,64).c_str(),
     377              (*it).second.elval.dv, (*it).second.elval.dv_im, (*it).second.elcomm.substr(0,128).c_str());
    374378      break;
    375379    case 'S' :
    376380      sprintf(buff, "%s = %s (string) %s\n", (*it).first.substr(0,64).c_str(),
    377               (*it).second.elval.mtv.strv, (*it).second.elcomm.substr(0,128).c_str());
     381              (*it).second.elval.strv->c_str(), (*it).second.elcomm.substr(0,128).c_str());
    378382      break;
    379383    default :
     
    441445  switch ((*it).second.elval.typ) {
    442446    case 'I' :
    443       sprintf(buf,"I %s %ld", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.mtv.iv) );
     447      sprintf(buf,"I %s %ld", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.iv) );
    444448      sfw = buf;  s.PutStr(sfw);
    445449      break;
    446450    case 'D' :
    447       sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.mtv.dv );
     451      sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv );
    448452      sfw = buf;  s.PutStr(sfw);
    449453      break;
     454    case 'Z' :
     455      sprintf(buf,"Z %s %.20g %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv,
     456                                      (*it).second.elval.dv_im);
     457      sfw = buf;  s.PutStr(sfw);
     458      break;
    450459    case 'S' :
    451       sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.elval.mtv.strv );
     460      sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.elval.strv->c_str() );
    452461      sfw = buf;  s.PutStr(sfw);
    453462      break;
     
    470479char buf[512];
    471480string sfr;
    472 int_8 j,iv;
    473 r_8 dv;
     481int_8 j,iv,k;
     482r_8 dv, dvi;
     483complex<r_8> z;
    474484bool ok=true;
    475485buf[0] = '\0';
     
    505515      dobj->SetD(key, dv);
    506516      break;
     517    case 'Z' :
     518      k = posc(buf+j+1, ' ')+j+1;
     519      buf[k] = '\0';
     520      dv = atof(buf+j+1);
     521      dvi = atof(buf+k+1);
     522      key = buf+2;
     523      z = complex<r_8>(dv, dvi);     
     524      dobj->SetZ(key, z);
     525      break;
    507526    case 'S' :
    508527      key = buf+2;
Note: See TracChangeset for help on using the changeset viewer.