| [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 "segdatablock.h" | 
|---|
|  | 14 | #include "fiosegdb.h" | 
|---|
|  | 15 | #include "swsegdb.h" | 
|---|
|  | 16 | #include "ppfswapper.h" | 
|---|
|  | 17 | #include "ppfwrapstlv.h" | 
|---|
|  | 18 |  | 
|---|
|  | 19 | /*  Programme test des classes  SegDataBlock<T> et son PPF writer */ | 
|---|
|  | 20 | /*  SwSegDataBlock<T> avec le swapper PPF                         */ | 
|---|
|  | 21 | /*  SOPHYA - R. Ansari (LAL)  -   Avril 2005                      */ | 
|---|
|  | 22 |  | 
|---|
|  | 23 | int main(int narg, char* arg[]) | 
|---|
|  | 24 | { | 
|---|
|  | 25 | cout << " ---- Programme tstsegdb.cc ----- \n" | 
|---|
|  | 26 | << "     Test classe SegDataBlock<T> et  SwSegDataBlock<T>  " << endl; | 
|---|
|  | 27 | int rc = 0; | 
|---|
|  | 28 | try { | 
|---|
|  | 29 | SophyaInit(); | 
|---|
|  | 30 |  | 
|---|
|  | 31 | InitTim(); | 
|---|
|  | 32 | cout << "1/ Test SegDataBlock Creation,remplissage, impression (segi, ssegi, sgds" << endl; | 
|---|
|  | 33 | SegDataBlock<int> segi; | 
|---|
|  | 34 | segi.Extend(); | 
|---|
|  | 35 | cout << segi; | 
|---|
|  | 36 |  | 
|---|
|  | 37 | SegDataBlock<int> ssegi(segi); | 
|---|
|  | 38 | segi = 432; | 
|---|
|  | 39 | ssegi.Extend(); | 
|---|
|  | 40 | ssegi.Print(cout, 4, " , "); | 
|---|
|  | 41 | SegDataBlock<string> sgds(5,3); | 
|---|
|  | 42 | cout << sgds; | 
|---|
|  | 43 | sgds[2] = "bonjour";  sgds[5] = "AAAA"; | 
|---|
|  | 44 | sgds[8] = "BbbBBbb"; | 
|---|
|  | 45 | sgds.Print(cout, 4, " ; "); | 
|---|
| [3568] | 46 |  | 
|---|
|  | 47 | cout << "1.b/ Testing SegDataBlock<string> srsdb.Share(sgds)" << endl; | 
|---|
|  | 48 | SegDataBlock<string> srsdb; | 
|---|
|  | 49 | srsdb.Share(sgds); | 
|---|
|  | 50 | srsdb.Print(cout, 4, " ; "); | 
|---|
|  | 51 | srsdb[6] = "HelloBug"; | 
|---|
|  | 52 | sgds.Print(cout, 4, " ; "); | 
|---|
|  | 53 |  | 
|---|
|  | 54 | cout << "1.c/ Appel operateur copie : sgsdscp = sgds " << endl; | 
|---|
| [2694] | 55 | SegDataBlock<string> sgdscp; | 
|---|
|  | 56 | sgdscp = sgds; | 
|---|
| [2659] | 57 | { | 
|---|
|  | 58 | cout << "2/ Ecriture segi sgds et ssegi dans segdb.ppf " << endl; | 
|---|
|  | 59 | POutPersist so("segdb.ppf"); | 
|---|
|  | 60 | so << segi << sgds << ssegi; | 
|---|
|  | 61 | } | 
|---|
|  | 62 | { | 
|---|
|  | 63 | cout << "3/ Lecture depuis segdb.ppf et print " << endl; | 
|---|
|  | 64 | SegDataBlock<int> rsd1, rsd2; | 
|---|
|  | 65 | SegDataBlock<string> rsds; | 
|---|
|  | 66 | PInPersist si("segdb.ppf"); | 
|---|
|  | 67 | si >> rsd1 >> rsds >> rsd2; | 
|---|
|  | 68 | rsds.Print(cout, 4, " ; "); | 
|---|
|  | 69 | cout << "4/ On modifie certains elements de rsd1 et on verifie le partage de reference en lecture" << endl; | 
|---|
|  | 70 | for(int jj=0; jj<rsd1.Size(); jj += 9) | 
|---|
|  | 71 | rsd1[jj] = 999; | 
|---|
|  | 72 | rsd1.Print(cout, 4, " , "); | 
|---|
|  | 73 | rsd2.Print(cout, 4, " , "); | 
|---|
|  | 74 | } | 
|---|
|  | 75 | cout << "5/ Test  SwSegDataBlock<T>  creation/remplissage  " << endl; | 
|---|
|  | 76 | int SWSEGSZ = 4; | 
|---|
|  | 77 | { | 
|---|
|  | 78 | cout << " Creation PPFDataSwapper<float> swout(so) avec swseg.ppf " << endl; | 
|---|
|  | 79 | POutPersist so("swseg.ppf"); | 
|---|
|  | 80 | PPFDataSwapper<float> swout(so); | 
|---|
|  | 81 | SwSegDataBlock<float> swsd(swout, SWSEGSZ, 3); | 
|---|
|  | 82 | float * fp = swsd.GetSegment(0); | 
|---|
|  | 83 | fp[0] = 6.54321;   fp[1] = 65.4321;  fp[2] = 654.321;  fp[3] = 6543.21; | 
|---|
|  | 84 | fp = swsd.GetSegment(1); | 
|---|
|  | 85 | fp[0] = 2.56789;   fp[1] = 25.6789;  fp[2] = 256.789;  fp[3] = 2567.89; | 
|---|
|  | 86 | fp = swsd.GetSegment(2); | 
|---|
|  | 87 | fp[0] = 12.567;   fp[1] = 225.67;  fp[2] = 3256.7;  fp[3] = 42567.; | 
|---|
|  | 88 | vector<int_8> tags = swsd.GetSwapPosTagTable(); | 
|---|
|  | 89 | so << tags; | 
|---|
|  | 90 | } | 
|---|
|  | 91 | { | 
|---|
|  | 92 | cout << "6/ Creation PPFDataSwapper<float> avec lecture depuis swseg.ppf " << endl; | 
|---|
|  | 93 | PInPersist si("swseg.ppf"); | 
|---|
|  | 94 | PPFDataSwapper<float> swin(si); | 
|---|
|  | 95 | vector<int_8> tags; | 
|---|
|  | 96 | si >> tags; | 
|---|
|  | 97 | SwSegDataBlock<float> swsd(swin, tags, SWSEGSZ); | 
|---|
|  | 98 | cout <<"7/ Recopie ds SegDataBlock<float> depuis SwSegDataBlock<float> et print" << endl; | 
|---|
|  | 99 | SegDataBlock<float> segf,segf2; | 
|---|
|  | 100 | segf = swsd; | 
|---|
|  | 101 | segf.Print(cout, 4, "  "); | 
|---|
|  | 102 | segf2 = swsd; | 
|---|
|  | 103 | segf2.Print(cout, 4, "  "); | 
|---|
|  | 104 | } | 
|---|
|  | 105 |  | 
|---|
|  | 106 | } | 
|---|
|  | 107 | catch (PThrowable & exc) { | 
|---|
|  | 108 | cerr << " tstsegdb.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name() | 
|---|
|  | 109 | << " - Msg= " << exc.Msg() << endl; | 
|---|
|  | 110 | rc = 99; | 
|---|
|  | 111 | } | 
|---|
|  | 112 | catch (std::exception & e) { | 
|---|
|  | 113 | cerr << " tstsegdb.cc: Catched std::xception " | 
|---|
|  | 114 | << " - what()= " << e.what() << endl; | 
|---|
|  | 115 | rc = 98; | 
|---|
|  | 116 | } | 
|---|
|  | 117 | catch (...) { | 
|---|
|  | 118 | cerr << " tstsegdb.cc: some other exception (...) was caught ! " << endl; | 
|---|
|  | 119 | rc = 97; | 
|---|
|  | 120 | } | 
|---|
|  | 121 | PrtTim("End tstsegdb " ); | 
|---|
|  | 122 | cout << " ---- Programme tstsegdb.cc -  FIN  (Rc=" << rc << ") --- " << endl; | 
|---|
|  | 123 | return rc; | 
|---|
|  | 124 | } | 
|---|