Index: /trunk/SophyaLib/BaseTools/ppersist.cc
===================================================================
--- /trunk/SophyaLib/BaseTools/ppersist.cc	(revision 2475)
+++ /trunk/SophyaLib/BaseTools/ppersist.cc	(revision 2476)
@@ -180,4 +180,16 @@
 }
 
+static inline void bswap8_hash(void* p)
+{
+  uint_8 tmp = *(uint_8*)p;
+  *(uint_8*)p = ((tmp >> (7*8)) & 0x000000FF) | 
+                ((tmp >> (5*8)) & 0x0000FF00) |
+                ((tmp >> (3*8)) & 0x00FF0000) |
+                ((tmp >> (1*8)) & 0xFF000000) |
+                ((tmp & 0xFF000000) << (1*8))  |
+                ((tmp & 0x00FF0000) << (3*8))  |
+                ((tmp & 0x0000FF00) << (5*8))  |
+                ((tmp & 0x000000FF) << (7*8));
+}
 
 
@@ -190,6 +202,6 @@
 	uint_8 hash2 =   *((uint_8*) (ctx.buf+8));
 #if IS_BIG_ENDIAN
-	bswap8(&hash1);
-	bswap8(&hash2);
+	bswap8_hash(&hash1);
+	bswap8_hash(&hash2);
 #endif
 	
@@ -628,5 +640,7 @@
     objreftag rt;
     rt.ppsoid = id;
+    //    cout << " DBG-rt.ppspos = s->tellp(); " << endl;
     rt.ppspos = s->tellp();
+    // cout << " DBG-rt.ppspos = s->tellp(); = " << rt.ppspos << endl;
     objList[mid] = rt;
   }
Index: /trunk/SophyaLib/BaseTools/ppfbinstream.cc
===================================================================
--- /trunk/SophyaLib/BaseTools/ppfbinstream.cc	(revision 2475)
+++ /trunk/SophyaLib/BaseTools/ppfbinstream.cc	(revision 2476)
@@ -50,9 +50,9 @@
 
 
-PPFBinaryInputStream::PPFBinaryInputStream()
-{
-  s = NULL;
-  version = 0;
-  bigEndian = true;
+PPFBinaryInputStream::PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan)
+{
+  s = is;
+  _ads = ad;
+  Init(scan);
 }
 
@@ -64,5 +64,16 @@
 {
   s = new RawInFileStream(flnm.c_str());
-
+  _ads = true;
+  Init(scan);
+}
+
+PPFBinaryInputStream::~PPFBinaryInputStream()
+{
+  if (_ads && (s!=NULL) ) delete s;
+}
+
+void
+PPFBinaryInputStream::Init(bool scan)
+{
   // Read and check header
 
@@ -75,5 +86,5 @@
   version = atoi(rbuf+25);
   if (version < 2) {
-    cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << flnm << ") Version(=" << version 
+    cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << FileName() << ") Version(=" << version 
 	 << ") < 2 not supported !" << endl;
     throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream() - Unsupported (Old) Version");
@@ -104,15 +115,13 @@
 
   creationdate = mktime(&tm);
-  filename = flnm;  // keep the filename
   seqread = true;   // To flag non sequential reads
-  if (scan && s->isSeekable()) Scan();
-}
-
-
-
-PPFBinaryInputStream::~PPFBinaryInputStream()
-{
-  if (s) delete s;
-}
+  if (scan && s->isSeekable()) { 
+    if (Version() >= 3) ReadNameTagTable();
+    else ReadNameTagTableV2();
+  }
+}
+
+
+
 
 
@@ -126,8 +135,6 @@
 
 void
-PPFBinaryInputStream::Scan()
-{
-  // On cherche la liste des tags, a la fin du fichier
-
+PPFBinaryInputStream::ReadNameTagTable()
+{
   unsigned char ppstype;
   int_8 debut;
@@ -138,5 +145,46 @@
   GetTypeTag(ppstype);
   if (ppstype != PPS_EOF)
-    throw FileFormatExc("PPFBinaryInputStream::Scan   corrupted file, no eof entry at end of file");
+    throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable()  Corrupted file, no EOF tag at end of file");
+
+  // Lecture position NameTagTable
+  int_8 pos;
+  GetRawI8(pos);
+  if (pos < 0) {  // no tags
+    s->seekg(debut);
+    return;
+  }
+  
+  // On se positionne au debut du NameTagTable
+  s->seekg(pos);
+  GetTypeTag(ppstype);
+  if (ppstype != PPS_NAMETAG_TABLE)
+    throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable()  Corrupted file PPS_NAMETAG_TABLE not found");
+  uint_8 ttsz,it;
+  GetU8(ttsz);
+  for(it=0; it<ttsz; it++) {
+    int_8 tpos;
+    string tname;
+    GetI8(tpos);
+    GetStr(tname);
+    tags[tname] = tpos;
+  }
+  // On revient au debut du float, juste apres l'entete
+  s->seekg(debut);
+}
+
+void
+PPFBinaryInputStream::ReadNameTagTableV2()
+{
+  // On cherche la liste des tags, a la fin du fichier
+
+  unsigned char ppstype;
+  int_8 debut;
+  debut = s->tellg();
+
+  s->seekg(-(sizeof(int_8)+1), ios::end);
+
+  GetTypeTag(ppstype);
+  if (ppstype != PPS_EOF)
+    throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, no eof entry at end of file");
 
   int_8 pos;
@@ -154,5 +202,5 @@
     
     if (ppstype != PPS_NAMETAG_TABLE)
-      throw FileFormatExc("PPFBinaryInputStream::Scan   corrupted file, bad tag entry");
+      throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, bad tag entry");
 
     GetRawI8(pos);
@@ -160,5 +208,5 @@
     GetRawI4(len);
     if (len > MAXTAGLEN_V2) 
-      throw FileFormatExc("PPFBinaryInputStream::Scan   corrupted file, tag name too long");
+      throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, tag name too long");
     GetRawBytes(buffer, len);
     buffer[len] = '\0';
@@ -242,8 +290,22 @@
 
 bool
-PPFBinaryInputStream::SkipItem()
+PPFBinaryInputStream::SkipNextItem()
 {
   // A FAIRE NOV 2003 - REZA
   return true;
+}
+
+char
+PPFBinaryInputStream::NextItemTag(short datasz, size_t sz)
+{
+  datasz = 0;
+  sz = 0;
+  return 0;
+}
+
+void 
+PPFBinaryInputStream::SkipItem(bool fgrdt, char itag)
+{
+  return;
 }
 
@@ -888,11 +950,27 @@
 //--
 
-PPFBinaryOutputStream::PPFBinaryOutputStream()
-{
-  s = NULL;
-  version = 0;
+PPFBinaryOutputStream::PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness)
+{
+  s = os;
+  _ads = ad;
+  Init(endianness);
 }
 
 PPFBinaryOutputStream::PPFBinaryOutputStream(string const& flnm, int endianness)
+{
+  // Output stream creation
+  s = new RawOutFileStream(flnm.c_str());
+  _ads = true;
+  Init(endianness);
+}
+
+PPFBinaryOutputStream::~PPFBinaryOutputStream()
+{
+  WriteNameTagTable();
+  if (_ads && (s != NULL)) delete s;   // Close the stream
+}
+
+void
+PPFBinaryOutputStream::Init(int endianness)
 {
   if (endianness == -1)
@@ -901,6 +979,4 @@
     bigEndian = endianness;
 
-  // Output stream creation
-  s = new RawOutFileStream(flnm.c_str());
   version = 3;
   // Header
@@ -917,8 +993,31 @@
   datestring[32] = '\0'; 
   PutRawBytes(datestring, 32);
-  filename = flnm;
-}
-
-PPFBinaryOutputStream::~PPFBinaryOutputStream()
+}
+
+void
+PPFBinaryOutputStream::WriteNameTagTable()
+{  
+  if (tags.size() == 0) {
+    PutRawUByte(PPS_EOF);
+    PutRawI8(-1);
+  } 
+  else {
+    int_8 tagPos;
+    tagPos = s->tellp();
+    PutRawUByte(PPS_NAMETAG_TABLE);                       // This is a tag
+    PutU8((uint_8)tags.size());    // Number of tags
+    for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
+      int_8 pos = (*i).second;
+      PutI8(pos);
+      PutStr((*i).first);
+    }
+    PutRawUByte(PPS_EOF);
+    PutRawI8(tagPos);
+  }
+  
+}
+
+void
+PPFBinaryOutputStream::WriteNameTagTableV2()
 {
   if (tags.size() == 0) {
@@ -940,6 +1039,6 @@
   }
 
-  delete s;   // Close the stream
-}
+}
+
 
 int_8
Index: /trunk/SophyaLib/BaseTools/ppfbinstream.h
===================================================================
--- /trunk/SophyaLib/BaseTools/ppfbinstream.h	(revision 2475)
+++ /trunk/SophyaLib/BaseTools/ppfbinstream.h	(revision 2476)
@@ -55,13 +55,11 @@
   };
   
-  PPFBinaryIOStream();
-  virtual ~PPFBinaryIOStream();
+  PPFBinaryIOStream() { }
+  virtual ~PPFBinaryIOStream() { }
   int    Version() {return version;}  // PIn/OutPersist version number
-  string FileName() { return filename; }   // Retourne le nom de fichier
   
 protected:
   
   map<string, int_8> tags;
-  string filename;
   int version;     // PPersist(In/Out) version 
 };
@@ -71,7 +69,9 @@
 class PPFBinaryInputStream : public PPFBinaryIOStream {
 public:
-  PPFBinaryInputStream();
+  PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan=false);
   PPFBinaryInputStream(string const& flnm, bool scan=true);
   virtual  ~PPFBinaryInputStream();
+
+  inline string FileName() { return s->getFileName(); }   // Retourne le nom de fichier
   
   // Gestion des tags
@@ -85,6 +85,9 @@
   // Saut jusqu'au prochain objet 
   bool   SkipToNextObject();
-  // Saut d'un item de base (tag+donnees correspondantes)
-  bool   SkipItem();
+  // Saut d'un item de base (tag+donnees correspondantes), le suivant ds le flot
+  bool   SkipNextItem();
+  // Lecture du tag de type next item + infos correspondantes
+  // Le stream est re-positionne avant le tag 
+  char   NextItemTag(short datasz, size_t sz);
   
   // Lecture donnees de base et tableaux de donnees de base
@@ -157,4 +160,10 @@
   
 protected:
+  void   Init(bool scan);
+  void   ReadNameTagTableV2();
+  void   ReadNameTagTable();
+
+  void   SkipItem(bool fgrdi, char itag);
+
   void   CheckTag   (short datasz, short datatype);
   void   CheckArrayTag(short datasz, size_t sz, short datatype);
@@ -168,7 +177,6 @@
   void   GetRawU8   (uint_8&);
   
-  void   Scan();
-  
   RawInOutStream* s;
+  bool _ads; // delete/close the stream at the end
   
   bool bigEndian;
@@ -181,7 +189,9 @@
 class PPFBinaryOutputStream : public PPFBinaryIOStream {
 public:
-  PPFBinaryOutputStream();
+  PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness = PPS_NATIVE);
   PPFBinaryOutputStream(string const& flnm, int endianness = PPS_NATIVE);
   virtual ~PPFBinaryOutputStream();
+
+  inline string FileName() { return s->getFileName(); }   // Retourne le nom de fichier
   
   // Ecriture de tags
@@ -253,7 +263,8 @@
   
 protected:
-  RawInOutStream* s;
-  bool bigEndian;
-  
+  void     Init(int endianness);
+  void     WriteNameTagTable();
+  void     WriteNameTagTableV2();
+
   void     PutArrayTag(short datasz, size_t sz, short datatype);
   void     PutRawByte (char);
@@ -264,5 +275,11 @@
   void     PutRawU8   (uint_8);
   void     PutRawBytes(void const* ptr, size_t bytes);
-  
+
+  // Attributs, variables
+  RawInOutStream* s;
+  bool _ads; // delete/close the stream at the end
+
+  bool bigEndian;
+
 };
   
Index: /trunk/SophyaLib/BaseTools/rawstream.h
===================================================================
--- /trunk/SophyaLib/BaseTools/rawstream.h	(revision 2475)
+++ /trunk/SophyaLib/BaseTools/rawstream.h	(revision 2476)
@@ -28,4 +28,8 @@
   virtual RawInOutStream& seekp(int_8, int sd = ios::beg);
   virtual RawInOutStream& write(const char* s, uint_8 n);
+  inline  std::string     getFileName() const { return _filename; }
+protected:
+  std::string _filename;
+
 };
 
@@ -43,8 +47,6 @@
   virtual RawInOutStream& read(char* s, uint_8 n); 
 
-  inline  std::string     getFileName() const { return _filename; }
 protected:
   FILE * fip;
-  std::string _filename;
 };
 
@@ -62,8 +64,6 @@
   virtual RawInOutStream& write(const char* s, uint_8 n);
 
-  inline  std::string     getFileName() const { return _filename; }
 protected:
   FILE * fip;
-  std::string _filename;  
 };
 
Index: /trunk/SophyaLib/BaseTools/sversion.h
===================================================================
--- /trunk/SophyaLib/BaseTools/sversion.h	(revision 2475)
+++ /trunk/SophyaLib/BaseTools/sversion.h	(revision 2476)
@@ -3,5 +3,5 @@
 
 #define SOPHYA_VERSION   1.8
-#define SOPHYA_REVISION  1
+#define SOPHYA_REVISION  2
 #define SOPHYA_TAG       "V_Oct2003"
 
