| 1 | #include "dvlist.h" | 
|---|
| 2 | #include "ndatablock.h" | 
|---|
| 3 | #include "fiondblock.h" | 
|---|
| 4 | #include "sophyainit.h" | 
|---|
| 5 |  | 
|---|
| 6 |  | 
|---|
| 7 | int main(int narg, char* arg[]) | 
|---|
| 8 | { | 
|---|
| 9 |  | 
|---|
| 10 | // We handle exception at the high level | 
|---|
| 11 | try { | 
|---|
| 12 | // This macro initialize the library | 
|---|
| 13 | // static objects handle this - However, not all loader call | 
|---|
| 14 | // the constructor for static objects | 
|---|
| 15 | SophyaInit(); | 
|---|
| 16 |  | 
|---|
| 17 | // using a DVList object | 
|---|
| 18 | cout << " Creating and using DVList and NDataBlock<T> " << endl; | 
|---|
| 19 | DVList dvl; | 
|---|
| 20 | dvl["A"] = 12; | 
|---|
| 21 | dvl["bs"] = "hello"; | 
|---|
| 22 |  | 
|---|
| 23 | // Using a datablock object with 66 integers | 
|---|
| 24 | NDataBlock<int_4> idb(66); | 
|---|
| 25 | // We initialize all values with the value 15 | 
|---|
| 26 | idb = 15; | 
|---|
| 27 |  | 
|---|
| 28 | // Using a datablock object with 40 float | 
|---|
| 29 | NDataBlock<r_4> rdb(40); | 
|---|
| 30 | // We initialize all values with the value 3.14 | 
|---|
| 31 | rdb = 3.14; | 
|---|
| 32 |  | 
|---|
| 33 | // Writing (serialiazing) objects into POutPersist streams | 
|---|
| 34 | cout << " Writing objects in POutPersist streams " << endl; | 
|---|
| 35 | { | 
|---|
| 36 | POutPersist so1("t11.ppf"); | 
|---|
| 37 | so1 << dvl; | 
|---|
| 38 | POutPersist so2("t12.ppf"); | 
|---|
| 39 | string nom = "idb"; | 
|---|
| 40 | so2.PutObject(idb, nom); | 
|---|
| 41 | nom = "rdb"; | 
|---|
| 42 | so2.PutObject(rdb, nom); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | // Reading objects from PInPersist streams | 
|---|
| 46 | cout << " reading objects from PInPersist streams " << endl; | 
|---|
| 47 | { | 
|---|
| 48 | PInPersist si1("t11.ppf"); | 
|---|
| 49 | DVList dvlr; | 
|---|
| 50 | si1 >> dvlr; | 
|---|
| 51 | cout << dvlr;     // Print on the standard output | 
|---|
| 52 | PInPersist si2("t12.ppf"); | 
|---|
| 53 | string nom = "rdb"; | 
|---|
| 54 | NDataBlock<r_4> rrdb; | 
|---|
| 55 | si2.GetObject(rrdb, nom); | 
|---|
| 56 | cout << rrdb;     // Print on the standard output | 
|---|
| 57 | NDataBlock<int_4> ridb; | 
|---|
| 58 | nom = "idb"; | 
|---|
| 59 | si2.GetObject(ridb, nom); | 
|---|
| 60 | cout << ridb;     // Print on the standard output | 
|---|
| 61 | si2.GetObject(ridb, nom); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | // Opening an non existing file for reading generates an exception | 
|---|
| 65 | cout << " Generating an exception ... " << endl; | 
|---|
| 66 | PInPersist si("zz.zz"); | 
|---|
| 67 |  | 
|---|
| 68 | } | 
|---|
| 69 | catch (PThrowable & exc) { | 
|---|
| 70 | cerr << " Catched Exception " << (string)typeid(exc).name() | 
|---|
| 71 | << " - Msg= " << exc.Msg() << endl; | 
|---|
| 72 | } | 
|---|
| 73 | catch (...) { | 
|---|
| 74 | cerr << " some other exception was caught ! " << endl; | 
|---|
| 75 | } | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|