| 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
| 2 | // Classe MuTyV : Variable multi-type numerique | 
|---|
| 3 | //                               Reza Ansari - 96-2000 | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef MUTYV_H_SEEN | 
|---|
| 6 | #define MUTYV_H_SEEN | 
|---|
| 7 |  | 
|---|
| 8 | #include "machdefs.h" | 
|---|
| 9 |  | 
|---|
| 10 | #include <string> | 
|---|
| 11 | #include <complex> | 
|---|
| 12 | #include "timestamp.h" | 
|---|
| 13 |  | 
|---|
| 14 | #include <iostream> | 
|---|
| 15 |  | 
|---|
| 16 | namespace SOPHYA { | 
|---|
| 17 |  | 
|---|
| 18 | // Classe utilitaire pour manipuler des variables typees | 
|---|
| 19 | //! A simple class for holding string, integer, float and complex type values. | 
|---|
| 20 |  | 
|---|
| 21 | class MuTyV { | 
|---|
| 22 | public: | 
|---|
| 23 |  | 
|---|
| 24 | enum MTVType { | 
|---|
| 25 | MTVInteger, | 
|---|
| 26 | MTVFloat, | 
|---|
| 27 | MTVComplex, | 
|---|
| 28 | MTVString, | 
|---|
| 29 | MTVTimeStamp | 
|---|
| 30 | }; | 
|---|
| 31 |  | 
|---|
| 32 | inline MuTyV() { typ = MTVInteger; iv = 0;  dv = dv_im = 0.;  strv = NULL; } | 
|---|
| 33 | MuTyV(MuTyV const & a); | 
|---|
| 34 | inline MuTyV(uint_2 i) { typ = MTVInteger; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; } | 
|---|
| 35 | inline MuTyV(uint_8 i) { typ = MTVInteger; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; } | 
|---|
| 36 | inline MuTyV(int_4 i)  { typ = MTVInteger; iv = (int_8)i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; } | 
|---|
| 37 | inline MuTyV(int_8 i)  { typ = MTVInteger; iv = i;  dv = (r_8)i;  dv_im = 0.;  strv = NULL; } | 
|---|
| 38 | inline MuTyV(r_4 f) { typ = MTVFloat; dv = (r_8)f; iv = (int_8)f;  dv_im = 0.;  strv = NULL; } | 
|---|
| 39 | inline MuTyV(r_8 d) { typ = MTVFloat; dv = d;  iv = (int_8)d;  dv_im = 0.;  strv = NULL; } | 
|---|
| 40 | inline MuTyV(complex<r_4> const& z) { typ = MTVComplex; dv = (r_8)z.real();  dv_im = z.imag(); | 
|---|
| 41 | iv = (int_8)dv;  strv = NULL; } | 
|---|
| 42 | inline MuTyV(complex<r_8> const& z) { typ = MTVComplex; dv = z.real();  dv_im = z.imag(); | 
|---|
| 43 | iv = (int_8)dv;  strv = NULL; } | 
|---|
| 44 |  | 
|---|
| 45 | MuTyV(char const* s); | 
|---|
| 46 | MuTyV(string const& s); | 
|---|
| 47 | MuTyV(TimeStamp const& ts); | 
|---|
| 48 |  | 
|---|
| 49 | ~MuTyV(); | 
|---|
| 50 |  | 
|---|
| 51 | MuTyV & operator= (MuTyV const & a); | 
|---|
| 52 | inline MuTyV & operator= (uint_2 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); } | 
|---|
| 53 | inline MuTyV & operator= (uint_8 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); } | 
|---|
| 54 | inline MuTyV & operator= (int_4 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); } | 
|---|
| 55 | inline MuTyV & operator= (int_8 v)  { typ = MTVInteger; iv = v;  dv = (r_8)v; dv_im = 0.;  return(*this); } | 
|---|
| 56 | inline MuTyV & operator= (r_4 v)  { typ = MTVFloat; dv = (r_8)v; iv = (int_8)v;  dv_im = 0.;  return(*this); } | 
|---|
| 57 | inline MuTyV & operator= (r_8 v) { typ = MTVFloat; dv = v; iv = (int_8)v;  dv_im = 0.;  return(*this); } | 
|---|
| 58 | inline MuTyV & operator= (complex<r_4> const& v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag(); | 
|---|
| 59 | iv = (int_8)dv;  return(*this); } | 
|---|
| 60 | inline MuTyV & operator= (complex<r_8> const& v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag(); | 
|---|
| 61 | iv = (int_8)dv;  return(*this); } | 
|---|
| 62 | const char*  operator= (const char* s); | 
|---|
| 63 | string const& operator= (string const & s); | 
|---|
| 64 | TimeStamp const& operator= (TimeStamp const & s); | 
|---|
| 65 |  | 
|---|
| 66 | inline operator uint_2() const { return((uint_2)iv); } | 
|---|
| 67 | inline operator uint_4() const { return((uint_4)iv); } | 
|---|
| 68 | inline operator uint_8() const { return((uint_8)iv); } | 
|---|
| 69 | inline operator int_4()  const { return((int_4)iv); } | 
|---|
| 70 | inline operator int_8()  const { return(iv); } | 
|---|
| 71 | inline operator r_4() const  { return((r_4)dv); } | 
|---|
| 72 | inline operator r_8() const  { return(dv); } | 
|---|
| 73 | inline operator complex<r_4>() const { return(complex<r_4>((r_4)dv, (r_4)dv_im)); } | 
|---|
| 74 | inline operator complex<r_8>() const { return(complex<r_8>(dv, dv_im)); } | 
|---|
| 75 |  | 
|---|
| 76 | operator string() const ; | 
|---|
| 77 | operator TimeStamp() const ; | 
|---|
| 78 |  | 
|---|
| 79 | inline MTVType Type() const { return typ; } | 
|---|
| 80 | inline int_8   GetIntPart() const { return iv; } | 
|---|
| 81 | inline r_8     GetRealPart() const { return dv; } | 
|---|
| 82 | inline r_8     GetImagPart() const { return dv_im; } | 
|---|
| 83 | inline string*  GetStringPointer() const { return (strv); } | 
|---|
| 84 |  | 
|---|
| 85 | protected: | 
|---|
| 86 | int_8 iv; | 
|---|
| 87 | r_8 dv; | 
|---|
| 88 | r_8 dv_im;   /* for holding imaginary part of a complex */ | 
|---|
| 89 | string * strv; | 
|---|
| 90 | MTVType typ; | 
|---|
| 91 |  | 
|---|
| 92 | }; | 
|---|
| 93 |  | 
|---|
| 94 | inline ostream& operator << (ostream& s, MuTyV const & mtv) | 
|---|
| 95 | {  s << (string)mtv;   return(s); } | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | } // namespace SOPHYA | 
|---|
| 99 |  | 
|---|
| 100 | #endif /* MUTYV_H_SEEN */ | 
|---|
| 101 |  | 
|---|
| 102 |  | 
|---|