Index: trunk/SophyaLib/BaseTools/ppersist.h
===================================================================
--- trunk/SophyaLib/BaseTools/ppersist.h	(revision 754)
+++ trunk/SophyaLib/BaseTools/ppersist.h	(revision 802)
@@ -7,4 +7,5 @@
 //
 // E. Aubourg     CEA DAPNIA/SPP  1999
+// R. Ansari      LAL IN2P3/CNRS  03/2000
 
 
@@ -51,9 +52,14 @@
 
     virtual AnyDataObj* DataObj()=0;       // Retourne l'objet reel 
-    virtual void       SetDataObj(AnyDataObj &)=0;       
-
+    virtual void       SetDataObj(AnyDataObj &)=0;     
+
+    virtual uint_8     getMemOId() const ;      // Renvoie l'identificateur de l'objet  - par defaut=0
+    // Ces deux methodes doivent etre redefinies si   getMemOId() renvoie non nul (>0)
+    virtual void       ShareDataReference(PPersist &);       
+    virtual PPersist*  CloneSharedReference();
+                                                // doit etre surcharge pour renvoyer un mem-oid correct
   protected:  
     virtual void       ReadSelf(PInPersist&)=0;           
-    virtual void       WriteSelf(POutPersist&) const=0;  
+    virtual void       WriteSelf(POutPersist&) const=0;
 
     friend class       PInPersist;
@@ -71,6 +77,16 @@
     typedef PPersist*            (*ClassCreatorFunc)();
   
-    static void                  RegisterClass(uint_8 classId, string typname, ClassCreatorFunc f);
+    static void                  RegisterPPHandlerClass(uint_8 classId, string ppclass_name, ClassCreatorFunc f);
+    static void                  RegisterDataObjClass(uint_8 classId, string class_name);
+
     static ClassCreatorFunc      FindCreatorFunc(uint_8 classId);
+
+    static string                getPPClassName(uint_8 classId);
+    static uint_8                getPPClassId(string const & typ_name);
+    static uint_8                getPPClassId(PPersist const & ppo);
+    static string                getDataObjClassName(uint_8 classId);
+    static uint_8                getDataObjClassId(string const & typ_name);
+    static uint_8                getDataObjClassId(AnyDataObj const & o);
+
     static uint_8 Hash(string const& typname) {
 	md5_init(&ctx);
@@ -82,11 +98,14 @@
   
     static void Initialize();   // Pour initialiser classList
-    static uint_8 getTypeId(string s) {return (*typeids)[s];}
+
+    string FileName() { return filename; }   // Retourne le nom de fichier
+
   private:
 
     typedef map<uint_8, ClassCreatorFunc, less<uint_8> > ClassList;  
     // Pas de createur appele pour objets statiques sur Linux - $CHECK$ Reza 26/04/99
-    static ClassList *           classList;  
-    static map<string, uint_8> * typeids;
+    static ClassList *           ppclassList;      // PPersist class list  
+    static map<string, uint_8> * ppclassNameList;  // PPersist classId = f(PPersistClassName)
+    static map<string, uint_8> * dobjclassNameList;  // PPersist classId = f(DataObjClassName)
 
   protected:
@@ -98,13 +117,19 @@
           PPS_TAG = 4,              // tag entries
 	  PPS_EOF = 5,              // Just before tag infomation, offset to PPS_TAG
-	  PPS_LINE = 6,             // '\n'-terminated, deprecated ?
-          PPS_TAG_MARK = 7,         // to reset object count when skipped
+	  PPS_ENDOBJECT = 6,        // marks the end of a given object information
+          PPS_TAG_MARK = 7,         // To have a name tag, position marker in a file
           PPS_SIMPLE = 16,          // 16 + number of bytes, up to 8 bytes
-          PPS_SIMPLE_ARRAY = 32,    // 32 + number of bytes, up to 8 bytes, then 2 bytes of length
-          PPS_SIMPLE_ARRAY4 = 64,   // 64 + number of bytes, up to 8 bytes, then 4 bytes of length
-          PPS_SIMPLE_ARRAY8 = 128   // 64 + number of bytes, up to 8 bytes, then 8 bytes of length
+          PPS_SIMPLE_ARRAY4 = 32,   // 32 + number of bytes, up to 8 bytes, then 4 bytes of length
+          PPS_SIMPLE_ARRAY8 = 48    // 48 + number of bytes, up to 8 bytes, then 8 bytes of length
+    };
+	  // The following values are used PPS_SIMPLE and PPS_SIMPLE_ARRAY (Using OR)
+   enum  {PPS_DATATYPE_CHAR = 0,        // 0  : DataType=character
+          PPS_DATATYPE_FLOAT = 64,      // 64 : DataType=float 
+          PPS_DATATYPE_INTEGER = 128,   // 128 :DataType=integer 
+          PPS_DATATYPE_UNSIGNED = 192   // 192 :DataType=Unsigned integer 
    };
 
     map<string, int_8> tags;
+    string filename;
   };
 
@@ -121,4 +146,5 @@
     bool   GotoTagNum(int itag);  // 0..NbTags-1
     string GetTagName(int itag);  // 0..NbTags-1
+    string GetTagClassName(int itag);  // 0..NbTags-1
     vector<string> const &  GetTagNames();  
 
@@ -163,15 +189,28 @@
     void   Get(string& x) {GetStr(x);}
   
+    //   Object Reading 
     PPersist*  ReadObject();
-
+    void       GetObject(AnyDataObj & o);
+    void       GetObject(AnyDataObj & o, string  tagname);
+    PPersist*  GetPPObject(AnyDataObj * po=NULL);
 
     int    Version() {return version;}
     time_t CreationDate() { return creationdate; }
+    string CreationDateStr(); 
+
+    void   AnalyseTags(int lev=0);   // List (all or some) tags ...
+
+    //  Reza 03/2000
+    //  Methodes qui pourraient etre protected, mais doivent etre utilisables par PPersist 
+    void   ReadReference(PPersist & ppo);  // Fill the ppo object from the reference tag
+    PPersist * ReadReference();            // Creates object from the reference tag
+    void   KeepOId(uint_8 oid, PPersist & ppo);        // Keeps the ppo in the objList
 
   protected:
-    void   CheckTag   (short datasz);
-    void   CheckArrayTag(short datasz, size_t sz);
-    void   GetTypeTag (char& c);
+    void   CheckTag   (short datasz, short datatype);
+    void   CheckArrayTag(short datasz, size_t sz, short datatype);
+    void   GetTypeTag (unsigned char& c);
     void   GetRawByte (char& c);
+    void   GetRawUByte (unsigned char& c);
     void   GetRawBytes(void* ptr, size_t bytes);
     void   GetRawI2   (int_2&);
@@ -179,8 +218,6 @@
     void   GetRawI8   (int_8&);
     void   GetRawU8   (uint_8&);
-    void   GetObject(PPersist*);               // Object has been allocated with correct type
-    int_4  assignObjectId(PPersist* x);
+
     void   Scan();
-    char*  GetCStr(uint_2 l);
 
     istream* s;
@@ -191,8 +228,9 @@
     time_t creationdate;
 
-    // already read objects, id = order in array 
-    typedef vector<PPersist*> ObjList;
+    // already read objects 
+    typedef map<uint_8, PPersist * > ObjList;
     ObjList objList;
-
+    // Si on a fait une lecture non sequentielle  -> seqread = false
+    bool seqread;
     friend class PPersist;
   };
@@ -225,5 +263,8 @@
     void PutLine (char const* ptr, size_t len=0); // deprecated ?
     void PutStr  (string const&);
-    void PutObject (PPersist const*); // Like doing Write(stream) on object
+    void PutPPObject (PPersist const*); // Like doing Write(stream) on PPersist object
+
+    void PutObject(AnyDataObj & o);   // Creates the corresponding PPersist Object and call Write()
+    void PutObject(AnyDataObj & o, string tagname);
 
     void   Put(char   c) {PutByte(c);}
@@ -245,5 +286,5 @@
     void   Put(int_8 const*  x, size_t n) {PutI8s(x,n);}
     void   Put(string const& s) {PutStr(s);}
-    void   Put(PPersist const* x) {PutObject(x);}
+    void   Put(PPersist const* x) {PutPPObject(x);}
 
 
@@ -252,6 +293,7 @@
     bool bigEndian;
 
-    void     PutArrayTag(short datasz, size_t sz);
+    void     PutArrayTag(short datasz, size_t sz, short datatype);
     void     PutRawByte (char);
+    void     PutRawUByte (unsigned char);
     void     PutRawI2   (int_2);
     void     PutRawI4   (int_4);
@@ -260,10 +302,14 @@
     void     PutRawBytes(void const* ptr, size_t bytes);
     bool     serializeNullAndRepeat(PPersist const* x);
-    int_4    findObjectId(PPersist const* x);
-    int_4    assignObjectId(PPersist const* x);
-
-    // already serialized objects
-    typedef map<PPersist const*, int_4, less<PPersist const*> >  ObjList;
+    uint_8   findObjectId(PPersist const* x, int_8 & pos);
+    uint_8   assignObjectId(PPersist const* x);
+
+    // objreftag contains the assigned POutStream Object Id and the stream position 
+    // of the original written object
+    typedef struct { uint_8 ppsoid; int_8 ppspos; } objreftag;
+    // already serialized objects are kept in a map as a function of the Objects memory Id
+    typedef map<uint_8, objreftag, less<uint_8> >  ObjList;
     ObjList objList;
+    uint_8 pps_OId;    // PPS Object Id 
   };
   
@@ -306,16 +352,19 @@
 #endif
   
-  inline POutPersist& operator << (POutPersist& c, PPersist const& obj)
-    {
-      obj.Write(c);
-      return c;
-    }
-  
-  inline PInPersist& operator >> (PInPersist& c, PPersist& obj)
-    {
-      obj.Read(c);
-      return c;
-    }
-  
+
+// --- Cela risque d'etre dangereux --- On le laisse au niveau des DataObj
+//                           Reza 24/3/2000 
+//   inline POutPersist& operator << (POutPersist& c, PPersist const& obj)
+//     {
+//       obj.Write(c);
+//       return c;
+//     }
+  
+//   inline PInPersist& operator >> (PInPersist& c, PPersist& obj)
+//     {
+//       obj.Read(c);
+//       return c;
+//     }
+
   // Utility class to
   //   - compute the class ID from a MD5 hash of the class name
@@ -326,5 +375,5 @@
     public:
       static PPersist* Create() {return new T();}
-      static void Register(string id) {PIOPersist::RegisterClass(Hash(id),typeid(T).name(),Create);}
+      static void Register(string id) { PIOPersist::RegisterPPHandlerClass(Hash(id), typeid(T).name(), Create); }
       static uint_8 Hash(string id) {
 	return PIOPersist::Hash(id);
@@ -333,4 +382,5 @@
   
 #define PPRegister(className) PPersistRegistrar<className>::Register(#className);
+#define DObjRegister(ppclassName, className) PIOPersist::RegisterDataObjClass(PIOPersist::Hash(#ppclassName), typeid(className).name());
 
 } // namespace
