source: Sophya/trunk/SophyaProg/Examples/MyPPF/README@ 3721

Last change on this file since 3721 was 3420, checked in by ansari, 18 years ago

Ajout du repetoire MyPPF (exemple de handler PPersist) dans le module Example - Reza 07/12/2007

File size: 3.2 KB
Line 
1Example to illustrate how to make a class persistent
2using SOPHYA PPF services
3-----------------------------------------------
4 (C) LAL-IN2P3/CNRS (C) DAPNIA-SPP/CEA
5 R. Ansari , 2007
6-----------------------------------------------
7
80/ Content :
9 - vfs.h : Declaration of the Vfs class Vfs . This is the class
10 which we want to make persistent using SOPHYA PPF services
11 - vfs.cc : the Vfs class implementation AND its PPF handler ObjFileIO<Vfs>
12 - tvfs.cc : the test main program
13 - makefile : compiles tvfs.cc and vfs.cc and links them to build tvfs
14
15
161/ The class should inherit from the SOPHYA::AnyDataObj class.
17 In the example here, we want to make the class Vfs persistent
18class Vfs : public SOPHYA::AnyDataObj {
19 ...
20}
21
222/ A PPF handler should be implemented . The PPF handler class
23should inherit from SOPHYA::PPersist . The pure virtual methods
24of PPersist class (DataObj() , SetDataObj() , ReadSelf(), WriteSelf()
25has to be implemented.
26
27class PPFHandlerVfs : public SOPHYA::PPersist {
28public:
29 virtual SOPHYA::AnyDataObj* DataObj();
30 virtual void SetDataObj(SOPHYA::AnyDataObj &);
31protected:
32 virtual void ReadSelf(SOPHYA::PInPersist&);
33 virtual void WriteSelf(SOPHYA::POutPersist&) const;
34}
35
36
37It is possible to use the template class SOPHYA::ObjFileIO<T>, and
38specialize it for the tharget class (here SOPHYA::ObjFileIO<Vfs>),
39by defining the two methods :
40 SOPHYA::ObjFileIO<Vfs>::ReadSelf(SOPHYA::PInPersist&)
41 SOPHYA::ObjFileIO<Vfs>::WriteSelf(SOPHYA::POutPersist&) const
42
433/ If it is NOT possible to have the target class inherit from AnyDataObj,
44a wrapper class should be used. The same class can play the role of wrapper
45AND the PPF handler.
46 (See the PPF handler / wrapper class for STL vectors :
47 SOPHYA::PPFWrapperSTLVector<T> in file BaseTools/ppfwrapstlv.h )
48
49
504/ Implement the ReadSelf() and WriteSelf() methods of the PPF handler.
51All the I/O services from the following classes can be used :
52 - PPFBinaryIOStrem , PPFBinaryInputStream , PInPersist
53 - PPFBinaryIOStrem , PPFBinaryOutputStream , POutPersist
54Writing and reading of the embeded objects for which a handler has been registered
55can simply be performed by :
56 POutPersist::PutObject() PInPersist::GetObject()
57
58==> The services associated with nametags (PPFBinaryOutputStream::WriteNameTag()
59 PPFBinaryInputStream::GotoNameTag() ... ) are NOT intented to be used in
60 WriteSelf() , ReadSelf()
61
62
635/ The new PPF handler, as well as the list of classes it can handle has to be
64registered prior to use PPF read/write for the target classes. This must be
65performed during the initialization phase, for example at the beginning of the
66main() program. Another possibility is to use a module initializer
67(See SophyaInitiator class in file BaseTools/sophyainit.h )
68and declare a static instance of the class (Note that this works only if
69the system loader handles correcly the call of constructor
70for the statically declared objects)
71
72The registration can be performed using the CPP macros defined in BaseTools/ppersist.h
73
74 // First, register the PPF handler ObjFileIO<Vfs>
75 PPRegister(ObjFileIO<Vfs>);
76 // Register the list of classes which can be handled by ObjFileIO<Vfs>
77 DObjRegister(ObjFileIO<Vfs>, Vfs);
Note: See TracBrowser for help on using the repository browser.