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