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