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