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


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.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
Note: See TracChangeset for help on using the changeset viewer.