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