source: Sophya/trunk/SophyaLib/BaseTools/mutyv.h@ 1405

Last change on this file since 1405 was 1310, checked in by ansari, 25 years ago

Changement de codage du type ds MuTyV (en prevision d'introduction de
nouveaux types codes ds MuTyV + Modif ObjFIO<DVList> - Reza 9/11/2000

File size: 3.3 KB
Line 
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 <iostream.h>
13
14namespace SOPHYA {
15
16// Classe utilitaire pour manipuler des variables typees
17//! A simple class for holding string, integer, float and complex type values.
18
19class MuTyV {
20public:
21
22 enum MTVType {
23 MTVInteger,
24 MTVFloat,
25 MTVComplex,
26 MTVString
27 };
28
29 inline MuTyV() { typ = MTVInteger; iv = 0; dv = dv_im = 0.; strv = NULL; }
30 MuTyV(MuTyV const & a);
31 inline MuTyV(uint_2 i) { typ = MTVInteger; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; }
32 inline MuTyV(int_4 i) { typ = MTVInteger; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; }
33 inline MuTyV(int_8 i) { typ = MTVInteger; iv = i; dv = (r_8)i; dv_im = 0.; strv = NULL; }
34 inline MuTyV(r_4 f) { typ = MTVFloat; dv = (r_8)f; iv = (int_8)f; dv_im = 0.; strv = NULL; }
35 inline MuTyV(r_8 d) { typ = MTVFloat; dv = d; iv = (int_8)d; dv_im = 0.; strv = NULL; }
36 inline MuTyV(complex<r_4> z) { typ = MTVComplex; dv = (r_8)z.real(); dv_im = z.imag();
37 iv = (int_8)dv; strv = NULL; }
38 inline MuTyV(complex<r_8> z) { typ = MTVComplex; dv = z.real(); dv_im = z.imag();
39 iv = (int_8)dv; strv = NULL; }
40
41 MuTyV(char const* s);
42 MuTyV(string const& s);
43
44 ~MuTyV();
45
46 inline MTVType Type() const { return typ; }
47
48 MuTyV & operator= (MuTyV const & a);
49 inline uint_2 operator= (uint_2 v) { typ = MTVInteger; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); }
50 inline int_4 operator= (int_4 v) { typ = MTVInteger; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); }
51 inline int_8 operator= (int_8 v) { typ = MTVInteger; iv = v; dv = (r_8)v; dv_im = 0.; return(v); }
52 inline r_4 operator= (r_4 v) { typ = MTVFloat; dv = (r_8)v; iv = (int_8)v; dv_im = 0.; return(v); }
53 inline r_8 operator= (r_8 v) { typ = MTVFloat; dv = v; iv = (int_8)v; dv_im = 0.; return(v); }
54 inline complex<r_4> operator= (complex<r_4> v) { typ = MTVComplex; dv = (r_8)v.real(); dv_im = v.imag();
55 iv = (int_8)dv; return(v); }
56 inline complex<r_8> operator= (complex<r_8> v) { typ = MTVComplex; dv = (r_8)v.real(); dv_im = v.imag();
57 iv = (int_8)dv; return(v); }
58 char* operator= (char* s);
59 string& operator= (string& s);
60
61 inline operator uint_2() const { return((uint_2)iv); }
62 inline operator int_4() const { return((int_4)iv); }
63 inline operator int_8() const { return(iv); }
64 inline operator r_4() const { return((r_4)dv); }
65 inline operator r_8() const { return(dv); }
66 inline operator complex<r_4>() const { return(complex<r_4>((r_4)dv, (r_4)dv_im)); }
67 inline operator complex<r_8>() const { return(complex<r_8>(dv, dv_im)); }
68
69 operator string() const ;
70
71 int_8 iv;
72 r_8 dv;
73 r_8 dv_im; /* for holding imaginary part of a complex */
74 string * strv;
75 MTVType typ;
76
77};
78
79inline ostream& operator << (ostream& s, MuTyV const & mtv)
80{ s << (string)mtv; return(s); }
81
82
83} // namespace SOPHYA
84
85#endif /* MUTYV_H_SEEN */
86
87
Note: See TracBrowser for help on using the repository browser.