Changeset 1863 in Sophya for trunk


Ignore:
Timestamp:
Jan 18, 2002, 9:58:50 AM (24 years ago)
Author:
ansari
Message:

Ajout test sur classe complex ds vecmapstl.cc - Reza 18/01/2002

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Eval/COS/vecmapstl.cc

    r1571 r1863  
    88#include <vector>
    99#include <map>
     10#include <complex>
    1011
     12// :::::::::::::::::::::::::::::::::::::::::::::::::::::
     13// Test du support de la STL par le compilateur
     14// string, vector<T>, map<T>, complex<T> exception
     15// :::::::::::::::::::::::::::::::::::::::::::::::::::::
     16 
    1117using namespace std;
    1218
     19// --------------------------------------------------------------------
     20// definition d'une classe de conversion de C (complexes) <> R (reel)
     21class convCR {
     22public:
     23  inline convCR() { dv = 0.;  dv_im = 0.; } 
     24  inline convCR(float v) { dv = (double)v;  dv_im = 0.; } 
     25  inline convCR(double v) { dv = v;  dv_im = 0.; } 
     26  inline convCR(complex<float> z) { dv = (double)z.real();  dv_im = (double)z.imag(); } 
     27  inline convCR(complex<double> z) { dv = z.real();  dv_im = z.imag(); }
     28  inline float  operator= (float v) { dv = (double)v;  dv_im = 0.; return v; }
     29  inline double operator= (double v) { dv = v;  dv_im = 0.; return v; }
     30  inline complex<float>  operator= (complex<float> z)
     31   { dv = (double)z.real(); dv_im = (double)z.imag(); return z; }
     32  inline complex<double>  operator= (complex<double> z)
     33   { dv = z.real(); dv_im = z.imag(); return z; }
     34
     35  inline operator float() const  { return((float)dv); }
     36  inline operator double() const  { return(dv); }
     37  inline operator complex<float>() const { return(complex<float>((float)dv, (float)dv_im)); }
     38  inline operator complex<double>() const { return(complex<float>(dv, dv_im)); }
     39 
     40  double dv;
     41  double dv_im;   /* for holding imaginary part of a complex */
     42};
     43// --------------------------------------------------------------------
    1344
    1445int main(int narg, char *arg[])
    1546{
    16   cout << "\n ---- Test vector et map de la stl --- \n" ;
     47  cout << "\n :::::::: Test complex / vector et map de la stl :::::::: \n" ;
    1748  int rc = 0;
    1849  try {
     
    2051    int k;
    2152    for(k=0; k<5; k++)    vi.push_back(k*5);
    22     cout << " vector<int> vi.size() = " << vi.size() << endl;
     53    cout << " -----> vector<int> vi.size() = " << vi.size() << endl;
    2354    for(k=0; k<vi.size(); k++)
    2455      cout << "vi[" << k << "]= " << vi[k] << endl;
     
    2960    msi["Douze"] = 12;
    3061    map<string, int>::iterator it;
    31     cout << " map<string, int> msi.size() = " << msi.size() << endl;
     62    cout << " -----> map<string, int> msi.size() = " << msi.size() << endl;
    3263    for(it=msi.begin(); it!=msi.end(); it++)
    3364      cout << " S= " << (*it).first << " I=" << (*it).second << endl;
     65    cout << " ---->  complex numbers and convCR : " << endl;
     66    complex<float> z,z1(2,2),z2(3,-1);
     67    complex<double> zd,zd1(2.5,2.5),zd2(3.3,-1);
     68    cout << " complex<float>: z1=" << z1 << " z2=" << z2
     69         << " z1+z2=" << z1+z2 << endl;
     70    cout << " complex<double>: z1=" << zd1 << " z2=" << zd2
     71         << " zd1+zd2=" << zd1+zd2 << endl;
     72    convCR czr, czr1(z1), czr2(zd2), czr3;
     73    cout << " convCR: czr1(z1)" << (complex<float>)czr1
     74         << " czr2(z2)" << (complex<double>)czr2
     75         << " czr1+czr2= " << (complex<double>)czr2+(complex<double>)czr1 << endl;
    3476  }
    3577  catch(exception exc){
     
    4587  }
    4688
    47   cout << " ------ Exiting from vecmapstl.cc ----------- \n" << endl;
     89  cout << " ::::::::: Exiting from vecmapstl.cc ::::::::: \n" << endl;
    4890  exit(rc);
    4991}
Note: See TracChangeset for help on using the changeset viewer.