Changeset 1080 in Sophya for trunk/SophyaLib/BaseTools


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

Location:
trunk/SophyaLib/BaseTools
Files:
2 added
3 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;
  • trunk/SophyaLib/BaseTools/dvlist.h

    r913 r1080  
    99
    1010#include <stdio.h>
    11 
    1211#include <iostream.h>
    1312
     13#include "mutyv.h"
    1414#include <list>
    1515#include <map>
    16 #include <string.h>
    17 #include <string>
    1816
    1917namespace SOPHYA {
    20 
    21 // Classe utilitaire pour manipuler des variables typees
    22 //! A simple class for holding string, integer and float type values.
    23 class MuTyV {
    24 public:
    25   union {
    26   int_8 iv;
    27   r_8 dv;
    28   char strv[39];
    29   } mtv;
    30   char typ;
    31 
    32   static char myStrBuf[64]; 
    33 
    34   inline MuTyV() { typ = 'I'; mtv.iv = 0;  mtv.dv = 0.;  mtv.strv[0] ='\0'; }
    35   inline MuTyV(MuTyV const & a) { typ = a.typ; mtv = a.mtv; }
    36   inline MuTyV(int_4 i) { typ = 'I'; mtv.iv = (int_8)i; mtv.dv = 0.;  mtv.strv[0] ='\0'; }
    37   inline MuTyV(int_8 i) { typ = 'I'; mtv.iv = i; mtv.dv = 0.;  mtv.strv[0] ='\0'; }
    38   inline MuTyV(r_4 f) { typ = 'D'; mtv.dv = (r_8)f;  mtv.iv = 0;  mtv.strv[0] ='\0'; }
    39   inline MuTyV(r_8 d) { typ = 'D'; mtv.dv = d; mtv.iv = 0;  mtv.strv[0] ='\0'; }
    40   inline MuTyV(char const* s)  { typ = 'S'; strncpy(mtv.strv, s, 39); mtv.strv[38] = '\0'; }
    41   inline MuTyV(string const& s) { typ = 'S'; strncpy(mtv.strv, s.c_str(), 39); mtv.strv[38] = '\0'; }
    42   inline MuTyV & operator= (MuTyV const & a) { typ = a.typ; mtv = a.mtv; return(*this); }
    43   inline int_4  operator= (int_4 v)  { typ = 'I'; mtv.iv = (int_8)v; return(v); }
    44   inline int_8  operator= (int_8 v)  { typ = 'I'; mtv.iv = v; return(v); }
    45   inline r_4  operator= (r_4 v)  { typ = 'D'; mtv.dv = (r_8)v; return(v); }
    46   inline r_8 operator= (r_8 v) { typ = 'D'; mtv.dv = v; return(v); }
    47   inline char*  operator= (char* s)  { typ = 'S'; strncpy(mtv.strv, s, 39);
    48                                        mtv.strv[38] = '\0';  return(s); }
    49   inline string& operator= (string& s)    { typ = 'S'; strncpy(mtv.strv, s.c_str(), 39);
    50                                             mtv.strv[38] = '\0'; return(s); }
    51 
    52   inline operator int_4() { if (typ == 'I')  return((int_4)mtv.iv);
    53                             else if (typ == 'D') return((int_4)mtv.dv);
    54                             else return(atol(mtv.strv)); }
    55   inline operator int_8() { if (typ == 'I')  return((int_8)mtv.iv);
    56                             else if (typ == 'D') return((int_8)mtv.dv);
    57                             else return(atol(mtv.strv)); }
    58   inline operator r_4() { if (typ == 'I')  return((r_4)mtv.iv);
    59                             else if (typ == 'D') return((r_4)mtv.dv);
    60                             else return((r_4)atof(mtv.strv)); }
    61   inline operator r_8() { if (typ == 'I')  return((r_8)mtv.iv);
    62                             else if (typ == 'D') return(mtv.dv);
    63                             else return(atof(mtv.strv)); }
    64   inline operator string() { char *ss=myStrBuf;
    65                             if (typ == 'I')  sprintf(ss,"%ld", (long)mtv.iv);
    66                             else if (typ == 'D') sprintf(ss,"%.20g", mtv.dv);
    67                             else ss = mtv.strv;
    68                             return(ss); }
    69 };
    7018
    7119//  Classe liste de variables  Dynamic Variable List 
     
    7422class DVList : public AnyDataObj {
    7523public:
    76 //  enum {classId = ClassId_DVList };
    7724
    7825                    DVList();
     
    8936  int_8             GetI(string const& key, int_8 def=-1);
    9037  r_8               GetD(string const& key, r_8 def=-9.e19);
     38  complex<r_8>      GetZ(string const& key, complex<r_8> def=-9.e19);
    9139  string            GetS(string const& key, char* def="");
    9240  string            GetComment(string const& key);
     
    9442  void              SetI(string const& key, int_8 val);
    9543  void              SetD(string const& key, r_8 val);
     44  void              SetZ(string const& key, complex<r_8> val);
    9645  void              SetS(string const& key, char const*  val);
    97   void              SetS(string const& key, string val);
     46  void              SetS(string const& key, string const& val);
    9847  void              SetComment(string const& key, string const& comm);
    9948
  • trunk/SophyaLib/BaseTools/sversion.h

    r1078 r1080  
    33
    44#define SOPHYA_VERSION   0.9
    5 #define SOPHYA_REVISION  71
     5#define SOPHYA_REVISION  80
    66#define SOPHYA_TAG       "V_Jul2000"
    77
Note: See TracChangeset for help on using the changeset viewer.