source: Sophya/trunk/SophyaProg/Examples/ex1.cc@ 3504

Last change on this file since 3504 was 3427, checked in by ansari, 18 years ago

Corrections/maj mineures ds Examples (README, Makefile ...) , Reza 08/12/2007

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