source: Sophya/trunk/SophyaProg/Tests/tstppfwrapstl.cc

Last change on this file was 3619, checked in by cmv, 16 years ago

add various #include<> for g++ 4.3 (jaunty 9.04), cmv 05/05/2009

File size: 4.7 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include "math.h"
7#include <iostream>
8#include <string>
9
10#include <typeinfo>
11#include "timing.h"
12#include "histinit.h"
13#include "pexceptions.h"
14#include "ppfwrapstlv.h"
15
16/* Programme test du PPFWrapper pour les vecteurs de la STL */
17/* SOPHYA - R. Ansari (LAL) - Avril 2005 */
18
19int main(int narg, char* arg[])
20{
21 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
22 cout << " tstppfwrapstl : Test classes PPFWrapper \n"
23 << " Usage: tstppfwrapstl [VectorSize=10] [prtlev=0,1] " << endl;
24 return 0;
25 }
26 cout << " ---- Programme tstppfwrapstl.cc ---- \n"
27 << " ::: Test classes PPFWrapper de std::vector ::: " << endl;
28 int prtlev = 0;
29 int SZV = 10;
30 if (narg > 1) SZV = atoi(arg[1]);
31 if (narg > 2) prtlev = atoi(arg[2]);
32 cout << " ----- Test PPFWrapperSTLVector<T> Size= " << SZV << " PrtLev= "
33 << prtlev << endl;
34 int rc = 0;
35 try {
36 SophyaInit();
37
38 InitTim();
39 vector<float> vw(SZV);
40 for(int k=0; k<SZV; k++) vw[k] = 3.141596*k;
41 #define MyNSC 6
42 const char * strcst[MyNSC] = { "Langage C++" , "Programmation Objet", "Calcul scientifique",
43 "Librairie de classes", "SOPHYA", " et Java alors ?"};
44
45 cout << "1/ Initialisation vector<float> vf , vector<int> vi , vector<string> vs " << endl;
46
47 vector<float> vf(SZV);
48 vector<string> vs(SZV);
49 vector<int> vi(SZV);
50 for(int k=0; k<SZV; k++) {
51 vf[k] = 3.141596*k;
52 vs[k] = strcst[k%MyNSC];
53 vi[k] = random();
54 }
55 if (prtlev > 0) {
56 cout << " vector<float> vf Size= " << vf.size() << " values: \n" ;
57 int k;
58 for(k=0; k<vf.size(); k++) cout << vf[k] << " ; ";
59 cout << endl;
60 cout << " vector<int> vi Size= " << vi.size() << " values: \n" ;
61 for(k=0; k<vi.size(); k++) cout << vi[k] << " ; ";
62 cout << endl;
63 cout << " vector<string> vs Size= " << vs.size() << " values: \n" ;
64 for(k=0; k<vs.size(); k++) cout << vs[k] << " ; ";
65 cout << endl;
66 }
67 {
68 cout << "2/ Ecriture vf vi vs ds fichier wrapstl.ppf" << endl;
69 POutPersist so("wrapstl.ppf");
70 so << PPFNameTag("STLVec<float>") << vf;
71 so << PPFNameTag("STLVec<string>") << vs;
72 so << PPFNameTag("STLVec<int>") << vi;
73 }
74 vector<string> vsr;
75 vector<int> vir;
76 vector<float> vfr;
77 {
78 cout << "3/ Relecture vfr vir vsr depuis fichier wrapstl.ppf " << endl;
79 PInPersist si("wrapstl.ppf");
80 si >> PPFNameTag("STLVec<string>") >> vsr >> vir;
81 si >> PPFNameTag("STLVec<float>") >> vfr;
82 if (prtlev > 0) {
83 cout << " vector<float> vfr Size= " << vfr.size() << " values: \n" ;
84 int k;
85 for(k=0; k<vfr.size(); k++) cout << vfr[k] << " ; ";
86 cout << endl;
87 cout << " vector<int> vir Size= " << vir.size() << " values: \n" ;
88 for(k=0; k<vir.size(); k++) cout << vir[k] << " ; ";
89 cout << endl;
90 cout << " vector<string> vsr Size= " << vsr.size() << " values: \n" ;
91 for(k=0; k<vsr.size(); k++) cout << vsr[k] << " ; ";
92 cout << endl;
93 }
94 }
95 cout << "3/ Comparaison vfr<>vf vir<>vr vsr<>vr " << endl;
96 int k;
97 if (vfr.size() != vf.size()) {
98 cout << " ... Difference de taille vf et vfr " << endl;
99 rc += 1;
100 }
101 else {
102 int ndiff = 0;
103 for(k=0; k<vfr.size(); k++)
104 if (vfr[k] != vf[k]) ndiff ++;
105 if (ndiff != 0) {
106 cout << " vf <> vfr NDiff = " << ndiff << endl;
107 rc += 2;
108 }
109 }
110 if (vir.size() != vi.size()) {
111 cout << " ... Difference de taille vi et vir " << endl;
112 rc += 4;
113 }
114 else {
115 int ndiff = 0;
116 for(k=0; k<vir.size(); k++)
117 if (vir[k] != vi[k]) ndiff ++;
118 if (ndiff != 0) {
119 cout << " vi <> vir NDiff = " << ndiff << endl;
120 rc += 8;
121 }
122 }
123 if (vsr.size() != vs.size()) {
124 cout << " ... Difference de taille vi et vir " << endl;
125 rc += 16;
126 }
127 else {
128 int ndiff = 0;
129 for(k=0; k<vsr.size(); k++)
130 if (vsr[k] != vs[k]) ndiff ++;
131 if (ndiff != 0) {
132 cout << " vs <> vsr NDiff = " << ndiff << endl;
133 rc += 32;
134 }
135 }
136 if (rc == 0) cout << " .... Comparaison OK " << endl;
137
138 }
139 catch (PThrowable & exc) {
140 cerr << " tstppfwrapstl.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
141 << " - Msg= " << exc.Msg() << endl;
142 rc = 99;
143 }
144 catch (std::exception & e) {
145 cerr << " tstppfwrapstl.cc: Catched std::xception "
146 << " - what()= " << e.what() << endl;
147 rc = 98;
148 }
149 catch (...) {
150 cerr << " tstppfwrapstl.cc: some other exception (...) was caught ! " << endl;
151 rc = 97;
152 }
153 PrtTim("End tstppfwrapstl " );
154 cout << " ---- Programme tstppfwrapstl.cc - FIN (Rc=" << rc << ") --- " << endl;
155 return rc;
156}
Note: See TracBrowser for help on using the repository browser.