| 1 | #include "machdefs.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <iostream> | 
|---|
| 4 |  | 
|---|
| 5 | #include "pexceptions.h" | 
|---|
| 6 | #include "vfs.h" | 
|---|
| 7 |  | 
|---|
| 8 | //------------------------------------------------------ | 
|---|
| 9 | // An example to illustrate how to make a class | 
|---|
| 10 | //  persistent using the SOPHYA PPF services | 
|---|
| 11 | // (C) LAL-IN2P3/CNRS   (C) DAPNIA-SPP/CEA | 
|---|
| 12 | // ---------------------------------------------------- | 
|---|
| 13 |  | 
|---|
| 14 | using namespace SOPHYA; | 
|---|
| 15 |  | 
|---|
| 16 | //--- The main program ---- | 
|---|
| 17 |  | 
|---|
| 18 | int main(int narg, char* arg[]) | 
|---|
| 19 | { | 
|---|
| 20 |  | 
|---|
| 21 | cout << " --------- tvfs.cc  test of class Vfs and ObjFileIO<Vfs>  ---------- " | 
|---|
| 22 | << endl; | 
|---|
| 23 |  | 
|---|
| 24 | // We have to register the PPersist handler for our class Vfs | 
|---|
| 25 | // This should be performed at initialization | 
|---|
| 26 | // The following two lines (CPP macros) do the job : | 
|---|
| 27 |  | 
|---|
| 28 | // First, register the PPF handler ObjFileIO<Vfs> | 
|---|
| 29 | PPRegister(ObjFileIO<Vfs>); | 
|---|
| 30 | // Register the list of classes which can be handled by ObjFileIO<Vfs> | 
|---|
| 31 | DObjRegister(ObjFileIO<Vfs>, Vfs); | 
|---|
| 32 |  | 
|---|
| 33 |  | 
|---|
| 34 | try { | 
|---|
| 35 | Vfs xa(5); | 
|---|
| 36 | xa.Set(0, 0., "Zero"); | 
|---|
| 37 | xa.Set(1, 1., "Un"); | 
|---|
| 38 | xa.Set(2, 2., "Deux"); | 
|---|
| 39 | xa.Set(3, 3., "Trois"); | 
|---|
| 40 | xa.Set(4, 4., "Quatre"); | 
|---|
| 41 | cout << xa ; | 
|---|
| 42 | { | 
|---|
| 43 | // We save our objet ito a POutPersist flow | 
|---|
| 44 | POutPersist po("tvfs.ppf"); | 
|---|
| 45 | po << xa; | 
|---|
| 46 | } | 
|---|
| 47 | { | 
|---|
| 48 | // We try to read in the saved Vfs xa object | 
|---|
| 49 | Vfs xb; | 
|---|
| 50 | cout << " Vfs xb before reading : \n " << xb << endl; | 
|---|
| 51 | PInPersist pi("tvfs.ppf"); | 
|---|
| 52 | pi >> xb; | 
|---|
| 53 | cout << " After reading pi >> xb : \n " << xb << endl; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | catch (PThrowable & pex) { | 
|---|
| 59 | cerr << " tvfs.cc/Error - Exception catched " << (string)typeid(pex).name() | 
|---|
| 60 | << " - Msg= " << pex.Msg() << endl; | 
|---|
| 61 | } | 
|---|
| 62 | catch (...) { | 
|---|
| 63 | cerr << " tx.cc/Error - Exception (...) catched " << endl; | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | cout << " ----------- End of tx.cc  ------------- " << endl; | 
|---|
| 67 |  | 
|---|
| 68 | return(0); | 
|---|
| 69 |  | 
|---|
| 70 | } | 
|---|