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

Last change on this file since 1197 was 1080, checked in by ansari, 25 years ago

Classe MuTyV separe et etendu pour support complexe - Reza 24/7/2000

File size: 3.1 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 inline MuTyV() { typ = 'I'; iv = 0; dv = dv_im = 0.; strv = NULL; }
23 MuTyV(MuTyV const & a);
24 inline MuTyV(uint_2 i) { typ = 'I'; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; }
25 inline MuTyV(int_4 i) { typ = 'I'; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; }
26 inline MuTyV(int_8 i) { typ = 'I'; iv = i; dv = (r_8)i; dv_im = 0.; strv = NULL; }
27 inline MuTyV(r_4 f) { typ = 'D'; dv = (r_8)f; iv = (int_8)f; dv_im = 0.; strv = NULL; }
28 inline MuTyV(r_8 d) { typ = 'D'; dv = d; iv = (int_8)d; dv_im = 0.; strv = NULL; }
29 inline MuTyV(complex<r_4> z) { typ = 'Z'; dv = (r_8)z.real(); dv_im = z.imag();
30 iv = (int_8)dv; strv = NULL; }
31 inline MuTyV(complex<r_8> z) { typ = 'Z'; dv = z.real(); dv_im = z.imag();
32 iv = (int_8)dv; strv = NULL; }
33
34 MuTyV(char const* s);
35 MuTyV(string const& s);
36
37 ~MuTyV();
38
39 inline char Type() { return typ; }
40
41 MuTyV & operator= (MuTyV const & a);
42 inline uint_2 operator= (uint_2 v) { typ = 'I'; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); }
43 inline int_4 operator= (int_4 v) { typ = 'I'; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); }
44 inline int_8 operator= (int_8 v) { typ = 'I'; iv = v; dv = (r_8)v; dv_im = 0.; return(v); }
45 inline r_4 operator= (r_4 v) { typ = 'D'; dv = (r_8)v; iv = (int_8)v; dv_im = 0.; return(v); }
46 inline r_8 operator= (r_8 v) { typ = 'D'; dv = v; iv = (int_8)v; dv_im = 0.; return(v); }
47 inline complex<r_4> operator= (complex<r_4> v) { typ = 'Z'; dv = (r_8)v.real(); dv_im = v.imag();
48 iv = (int_8)dv; return(v); }
49 inline complex<r_8> operator= (complex<r_8> v) { typ = 'Z'; dv = (r_8)v.real(); dv_im = v.imag();
50 iv = (int_8)dv; return(v); }
51 char* operator= (char* s);
52 string& operator= (string& s);
53
54 inline operator uint_2() const { return((uint_2)iv); }
55 inline operator int_4() const { return((int_4)iv); }
56 inline operator int_8() const { return(iv); }
57 inline operator r_4() const { return((r_4)dv); }
58 inline operator r_8() const { return(dv); }
59 inline operator complex<r_4>() const { return(complex<r_4>((r_4)dv, (r_4)dv_im)); }
60 inline operator complex<r_8>() const { return(complex<r_8>(dv, dv_im)); }
61
62 operator string() const ;
63
64 int_8 iv;
65 r_8 dv;
66 r_8 dv_im; /* for holding imaginary part of a complex */
67 string * strv;
68 char typ;
69
70};
71
72inline ostream& operator << (ostream& s, MuTyV const & mtv)
73{ s << (string)mtv; return(s); }
74
75
76} // namespace SOPHYA
77
78#endif /* MUTYV_H_SEEN */
79
80
Note: See TracBrowser for help on using the repository browser.