Index: /trunk/SophyaProg/Examples/MyPPF/README
===================================================================
--- /trunk/SophyaProg/Examples/MyPPF/README	(revision 3420)
+++ /trunk/SophyaProg/Examples/MyPPF/README	(revision 3420)
@@ -0,0 +1,77 @@
+Example to illustrate how to make a class persistent
+using SOPHYA PPF services 
+-----------------------------------------------
+   (C) LAL-IN2P3/CNRS   (C) DAPNIA-SPP/CEA 
+               R. Ansari , 2007 
+-----------------------------------------------
+
+0/ Content : 
+   - vfs.h : Declaration of the Vfs class Vfs . This is the class 
+             which we want to make persistent using SOPHYA PPF services
+   - vfs.cc : the Vfs class implementation AND its PPF handler ObjFileIO<Vfs>
+   - tvfs.cc : the test main program
+   - makefile : compiles tvfs.cc and vfs.cc and links them to build tvfs
+
+
+1/ The class should inherit from the SOPHYA::AnyDataObj class. 
+   In the example here, we want to make the class Vfs persistent
+class Vfs : public SOPHYA::AnyDataObj {
+ ... 
+}
+
+2/ A PPF handler should be implemented . The PPF handler class 
+should inherit from SOPHYA::PPersist . The pure virtual methods 
+of PPersist class (DataObj() , SetDataObj() , ReadSelf(), WriteSelf()
+has to be implemented. 
+
+class PPFHandlerVfs : public SOPHYA::PPersist {
+public:
+  virtual SOPHYA::AnyDataObj* DataObj();
+  virtual void       SetDataObj(SOPHYA::AnyDataObj &);
+protected: 
+  virtual void       ReadSelf(SOPHYA::PInPersist&);
+  virtual void       WriteSelf(SOPHYA::POutPersist&) const;
+}
+
+
+It is possible to use the template class SOPHYA::ObjFileIO<T>, and 
+specialize it for the tharget class (here SOPHYA::ObjFileIO<Vfs>), 
+by defining the two methods :
+  SOPHYA::ObjFileIO<Vfs>::ReadSelf(SOPHYA::PInPersist&)
+  SOPHYA::ObjFileIO<Vfs>::WriteSelf(SOPHYA::POutPersist&) const
+
+3/ If it is NOT possible to have the target class inherit from AnyDataObj, 
+a wrapper class should be used. The same class can play the role of wrapper
+AND the PPF handler. 
+  (See the PPF handler / wrapper class for STL vectors :
+   SOPHYA::PPFWrapperSTLVector<T> in file BaseTools/ppfwrapstlv.h )
+
+
+4/ Implement the ReadSelf() and WriteSelf() methods of the PPF handler.
+All the I/O services from the following classes can be used : 
+  - PPFBinaryIOStrem , PPFBinaryInputStream , PInPersist
+  - PPFBinaryIOStrem , PPFBinaryOutputStream , POutPersist
+Writing and reading of the embeded objects for which a handler has been registered 
+can simply be performed by : 
+  POutPersist::PutObject()   PInPersist::GetObject()
+
+==> The services associated with nametags (PPFBinaryOutputStream::WriteNameTag() 
+    PPFBinaryInputStream::GotoNameTag() ... ) are NOT intented to be used in 
+    WriteSelf() , ReadSelf()
+
+
+5/ The new PPF handler, as well as the list of classes it can handle has to be
+registered prior to use PPF read/write for the target classes. This must be 
+performed during the initialization phase, for example at the beginning of the 
+main() program. Another possibility is to use a module initializer 
+(See SophyaInitiator class in file BaseTools/sophyainit.h ) 
+and declare a static instance of the class (Note that this works only if 
+the system loader handles correcly the call of constructor 
+for the statically declared objects)
+
+The registration can be performed using the CPP macros defined in BaseTools/ppersist.h
+
+  // First, register the PPF handler ObjFileIO<Vfs> 
+  PPRegister(ObjFileIO<Vfs>);
+  // Register the list of classes which can be handled by ObjFileIO<Vfs> 
+  DObjRegister(ObjFileIO<Vfs>, Vfs);
Index: /trunk/SophyaProg/Examples/MyPPF/makefile
===================================================================
--- /trunk/SophyaProg/Examples/MyPPF/makefile	(revision 3420)
+++ /trunk/SophyaProg/Examples/MyPPF/makefile	(revision 3420)
@@ -0,0 +1,18 @@
+include $(SOPHYABASE)/include/sophyamake.inc
+
+all : tvfs
+
+clean :
+	rm -f tvfs tvfs.o vfs.o tvfs.ppf
+
+
+tvfs : tvfs.o vfs.o
+	$(CXXLINK) -o tvfs tvfs.o vfs.o $(SOPHYASLBLIST)
+
+tvfs.o : tvfs.cc
+	$(CXXCOMPILE) -o tvfs.o tvfs.cc
+
+vfs.o : vfs.cc
+	$(CXXCOMPILE) -o vfs.o vfs.cc
+
+
Index: /trunk/SophyaProg/Examples/MyPPF/tvfs.cc
===================================================================
--- /trunk/SophyaProg/Examples/MyPPF/tvfs.cc	(revision 3420)
+++ /trunk/SophyaProg/Examples/MyPPF/tvfs.cc	(revision 3420)
@@ -0,0 +1,70 @@
+#include "machdefs.h"
+
+#include <iostream>
+
+#include "pexceptions.h"
+#include "vfs.h"
+
+//------------------------------------------------------
+// An example to illustrate how to make a class 
+//  persistent using the SOPHYA PPF services
+// (C) LAL-IN2P3/CNRS   (C) DAPNIA-SPP/CEA 
+// ----------------------------------------------------
+
+using namespace SOPHYA;   
+
+//--- The main program ----
+
+int main(int narg, char* arg[])
+{
+  
+  cout << " --------- tvfs.cc  test of class Vfs and ObjFileIO<Vfs>  ---------- "
+       << endl;
+  
+  // We have to register the PPersist handler for our class Vfs
+  // This should be performed at initialization
+  // The following two lines (CPP macros) do the job :
+
+  // First, register the PPF handler ObjFileIO<Vfs> 
+  PPRegister(ObjFileIO<Vfs>);
+  // Register the list of classes which can be handled by ObjFileIO<Vfs> 
+  DObjRegister(ObjFileIO<Vfs>, Vfs);
+
+
+  try {
+    Vfs xa(5);
+    xa.Set(0, 0., "Zero");
+    xa.Set(1, 1., "Un");
+    xa.Set(2, 2., "Deux");
+    xa.Set(3, 3., "Trois");
+    xa.Set(4, 4., "Quatre");
+    cout << xa ;
+    {
+    // We save our objet ito a POutPersist flow
+      POutPersist po("tvfs.ppf");
+      po << xa;
+    }
+    {
+    // We try to read in the saved Vfs xa object
+      Vfs xb;
+      cout << " Vfs xb before reading : \n " << xb << endl;
+      PInPersist pi("tvfs.ppf");
+      pi >> xb;
+      cout << " After reading pi >> xb : \n " << xb << endl;
+    }
+    
+  }
+
+  catch (PThrowable & pex) {
+    cerr << " tvfs.cc/Error - Exception catched " << (string)typeid(pex).name()
+	 << " - Msg= " << pex.Msg() << endl;
+  }
+  catch (...) {
+    cerr << " tx.cc/Error - Exception (...) catched " << endl;
+    }
+      
+  cout << " ----------- End of tx.cc  ------------- " << endl;
+
+  return(0);
+ 
+}
Index: /trunk/SophyaProg/Examples/MyPPF/vfs.cc
===================================================================
--- /trunk/SophyaProg/Examples/MyPPF/vfs.cc	(revision 3420)
+++ /trunk/SophyaProg/Examples/MyPPF/vfs.cc	(revision 3420)
@@ -0,0 +1,95 @@
+#include "vfs.h"
+#include "pexceptions.h"
+#include "fiondblock.h"  // To use NDataBlock PPF services
+
+/* Vfs class constructor */
+Vfs::Vfs(int sz) 
+    : mFVal(sz)
+{
+  for(int k=0; k<sz; k++)
+    mSVal.push_back("");
+}
+
+void Vfs::Set(int k, r_4 fv, string const  sv)
+{
+  if ((k < 0) || (k>= (int)mFVal.Size())) 
+    throw SOPHYA::RangeCheckError("Vfs::Set() Out of range index!");
+  mFVal(k) = fv;
+  mSVal[k] = sv;  
+}
+
+r_4 Vfs::GetF(int k)
+{
+  if ((k < 0) || (k>= (int)mFVal.Size())) 
+    throw SOPHYA::RangeCheckError("Vfs::GetF() Out of range index!");
+  return mFVal(k);
+}
+
+string Vfs::GetS(int k)
+{
+  if ((k < 0) || (k>= (int)mFVal.Size())) 
+    throw SOPHYA::RangeCheckError("Vfs::GetS() Out of range index!");
+  return mSVal[k];
+}
+
+void Vfs::Print(ostream& os) const
+{
+  os << "Vfs::Print() - Size= " << mFVal.Size() << endl;
+  for(int k=0; k<(int)mFVal.Size(); k++)
+    os << "K=" << k << " FVal= " << mFVal(k) << " SVal=" << mSVal[k] << endl;
+  os << endl;  
+}
+
+//-----------------------------------------------------------------------
+//  The PPF handler : ObjFileIO<T> is in namespace SOPHYA , 
+//  We declare ObjFileIO<Vfs> in the SOPHYA namespace ...
+//  Only, the WriteSelf() and ReadSelf() methods have to be provided
+//-----------------------------------------------------------------------
+
+namespace SOPHYA {
+
+DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
+void ObjFileIO<Vfs>::WriteSelf(POutPersist& s) const
+{
+//  On ecrit 2 uint_4 .... 
+//  0: Numero de version,  2 : reserve
+  uint_4 itab[2];
+  itab[0] = 1;  // Numero de version a 1
+  itab[1] = 0;  // Reserved for future use
+  s.Put(itab, 2); 
+  s << dobj->mFVal;  // We write the float data block 
+// We write now the string vector , as a series of strings 
+  for(int k=0; k<(int)dobj->mFVal.Size(); k++)
+      s.PutStr(dobj->mSVal[k]);
+}
+
+DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
+void ObjFileIO<Vfs>::ReadSelf(PInPersist& s)
+{
+// We read in the same order as the write
+    // First the two integer containing the version numer
+  uint_4 itab[2];
+  s.Get(itab, 2); 
+// next, we read in the float data vector 
+  s >> dobj->mFVal;  
+// We resest the  vector<string> dobj->mSVal
+  dobj->mSVal.clear();
+// We read in the mFVal.Size() and keep them in dobj->mSVal
+  string buff; 
+  for(int k=0; k<(int)dobj->mFVal.Size(); k++) {
+    s.GetStr(buff);  
+    dobj->mSVal.push_back(buff);
+  }  
+}
+
+// We force the instanciation of the template class ObjFileIO<Vfs>
+#ifdef __CXX_PRAGMA_TEMPLATES__
+#pragma define_template ObjFileIO<Vfs>
+#endif
+
+#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
+template class ObjFileIO<Vfs>;
+#endif
+
+} // End of namespace SOPHYA 
+
Index: /trunk/SophyaProg/Examples/MyPPF/vfs.h
===================================================================
--- /trunk/SophyaProg/Examples/MyPPF/vfs.h	(revision 3420)
+++ /trunk/SophyaProg/Examples/MyPPF/vfs.h	(revision 3420)
@@ -0,0 +1,58 @@
+#ifndef VFS_H_SEEN
+#define VFS_H_SEEN
+
+#include "machdefs.h"
+
+#include <string>
+#include <vector>
+
+#include "ndatablock.h"
+#include "objfio.h"
+
+//------------------------------------------------------
+// An example to illustrate how to make a class 
+//  persistent using the SOPHYA PPF services
+// (C) LAL-IN2P3/CNRS   (C) DAPNIA-SPP/CEA 
+// ----------------------------------------------------
+
+// A simple class to hold pairs(float, string)
+// we want to make this class persistent using SOPHYA PPF services
+
+class Vfs : public SOPHYA::AnyDataObj {
+public:
+// We need a default constructor , if we want to use the ObjFileIO<Vfs> class
+            Vfs(int sz=10);
+  virtual   ~Vfs() { };
+
+// Setting element k
+  void      Set(int k, r_4 fv, string const sv);
+// Accessing float part of element k
+  r_4       GetF(int k);
+// Accessing string part of element k
+  string    GetS(int k);
+// display/print object content
+  void      Print(ostream& os) const ; 
+//  For persistence handling
+  friend class SOPHYA::ObjFileIO<Vfs> ;
+ private:
+	  SOPHYA::NDataBlock<r_4> mFVal;
+	  vector<string> mSVal;	  	  
+};
+
+// For easy printing of Vfs through cout << x ;
+inline ostream& operator << (ostream& s, Vfs const & x)
+  {  x.Print(s);  return(s);  }
+
+/* Writes the object in the POutPersist stream  os */
+inline SOPHYA::POutPersist& operator << (SOPHYA::POutPersist& os, Vfs & obj)
+{ SOPHYA::ObjFileIO<Vfs> fio(&obj);  fio.Write(os);  return(os); }
+/* Reads the object from the PInPersist stream  is */
+inline SOPHYA::PInPersist& operator >> (SOPHYA::PInPersist& is, Vfs & obj)
+{ SOPHYA::ObjFileIO<Vfs> fio(&obj);  fio.Read(is);  return(is); }
+
+
+#endif
+
+
+
+
