| 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_4 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); }
 | 
|---|
| 54 |   inline MuTyV & operator= (uint_8 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); }
 | 
|---|
| 55 |   inline MuTyV & operator= (int_2 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); }
 | 
|---|
| 56 |   inline MuTyV & operator= (int_4 v)  { typ = MTVInteger; iv = (int_8)v;  dv = (r_8)v;  dv_im = 0.;  return(*this); }
 | 
|---|
| 57 |   inline MuTyV & operator= (int_8 v)  { typ = MTVInteger; iv = v;  dv = (r_8)v; dv_im = 0.;  return(*this); }
 | 
|---|
| 58 |   inline MuTyV & operator= (r_4 v)  { typ = MTVFloat; dv = (r_8)v; iv = (int_8)v;  dv_im = 0.;  return(*this); }
 | 
|---|
| 59 |   inline MuTyV & operator= (r_8 v) { typ = MTVFloat; dv = v; iv = (int_8)v;  dv_im = 0.;  return(*this); }
 | 
|---|
| 60 |   inline MuTyV & operator= (complex<r_4> const& v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag();
 | 
|---|
| 61 |                                                     iv = (int_8)dv;  return(*this); }
 | 
|---|
| 62 |   inline MuTyV & operator= (complex<r_8> const& v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag();
 | 
|---|
| 63 |                                                     iv = (int_8)dv;  return(*this); }
 | 
|---|
| 64 |          const char*  operator= (const char* s);
 | 
|---|
| 65 |          string const& operator= (string const & s);
 | 
|---|
| 66 |          TimeStamp const& operator= (TimeStamp const & s);
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   inline operator uint_2() const { return((uint_2)iv); }
 | 
|---|
| 69 |   inline operator uint_4() const { return((uint_4)iv); }
 | 
|---|
| 70 |   inline operator uint_8() const { return((uint_8)iv); }
 | 
|---|
| 71 |   inline operator int_2()  const { return((int_2)iv); }
 | 
|---|
| 72 |   inline operator int_4()  const { return((int_4)iv); }
 | 
|---|
| 73 |   inline operator int_8()  const { return(iv); }
 | 
|---|
| 74 |   inline operator r_4() const  { return((r_4)dv); }
 | 
|---|
| 75 |   inline operator r_8() const  { return(dv); }
 | 
|---|
| 76 |   inline operator complex<r_4>() const { return(complex<r_4>((r_4)dv, (r_4)dv_im)); }
 | 
|---|
| 77 |   inline operator complex<r_8>() const { return(complex<r_8>(dv, dv_im)); }
 | 
|---|
| 78 | 
 | 
|---|
| 79 |          operator string() const ; 
 | 
|---|
| 80 |          operator TimeStamp() const ; 
 | 
|---|
| 81 | 
 | 
|---|
| 82 |   inline uint_2 Convert(uint_2& x) const { x = (uint_2)iv; return x; }
 | 
|---|
| 83 |   inline uint_4 Convert(uint_4& x) const { x = (uint_4)iv; return x; }
 | 
|---|
| 84 |   inline uint_8 Convert(uint_8& x) const { x = (uint_8)iv; return x; }
 | 
|---|
| 85 |   inline int_4 Convert(int_2& x) const { x = (int_2)iv; return x; }
 | 
|---|
| 86 |   inline int_4 Convert(int_4& x) const { x = (int_4)iv; return x; }
 | 
|---|
| 87 |   inline int_8 Convert(int_8& x) const { x = iv; return x; }
 | 
|---|
| 88 |   inline r_4 Convert(r_4& x) const { x = (r_4)dv; return x; }
 | 
|---|
| 89 |   inline r_8 Convert(r_8& x) const { x = dv; return x; }
 | 
|---|
| 90 |   inline complex<r_4> Convert(complex<r_4> & x) const 
 | 
|---|
| 91 |     { x = complex< r_4 > ((r_4)dv, (r_4)dv_im); return x; }
 | 
|---|
| 92 |   inline complex<r_8> Convert(complex<r_8> & x) const 
 | 
|---|
| 93 |     { x = complex< r_8 > (dv, dv_im); return x; }
 | 
|---|
| 94 |   
 | 
|---|
| 95 |   string&  Convert(string& x) const ; 
 | 
|---|
| 96 |   TimeStamp& Convert(TimeStamp& x) const ; 
 | 
|---|
| 97 | 
 | 
|---|
| 98 |   inline MTVType Type() const { return typ; }
 | 
|---|
| 99 |   inline int_8   GetIntPart() const { return iv; }
 | 
|---|
| 100 |   inline r_8     GetRealPart() const { return dv; }
 | 
|---|
| 101 |   inline r_8     GetImagPart() const { return dv_im; }
 | 
|---|
| 102 |   inline string*  GetStringPointer() const { return (strv); } 
 | 
|---|
| 103 | 
 | 
|---|
| 104 | protected:
 | 
|---|
| 105 |   int_8 iv;
 | 
|---|
| 106 |   r_8 dv;
 | 
|---|
| 107 |   r_8 dv_im;   /* for holding imaginary part of a complex */
 | 
|---|
| 108 |   string * strv;
 | 
|---|
| 109 |   MTVType typ;
 | 
|---|
| 110 | 
 | 
|---|
| 111 | };
 | 
|---|
| 112 | 
 | 
|---|
| 113 | inline ostream& operator << (ostream& s, MuTyV const & mtv)
 | 
|---|
| 114 | {  s << (string)mtv;   return(s); }
 | 
|---|
| 115 |  
 | 
|---|
| 116 | 
 | 
|---|
| 117 | } // namespace SOPHYA
 | 
|---|
| 118 | 
 | 
|---|
| 119 | #endif /* MUTYV_H_SEEN */
 | 
|---|
| 120 | 
 | 
|---|
| 121 | 
 | 
|---|