peiyongz    2003/10/29 08:18:41

  Modified:    c/src/xercesc/util StringPool.cpp StringPool.hpp
  Log:
  Implement serialization/deserialization
  
  Revision  Changes    Path
  1.7       +52 -2     xml-xerces/c/src/xercesc/util/StringPool.cpp
  
  Index: StringPool.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/StringPool.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StringPool.cpp    9 Oct 2003 13:49:30 -0000       1.6
  +++ StringPool.cpp    29 Oct 2003 16:18:41 -0000      1.7
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.7  2003/10/29 16:18:41  peiyongz
  + * Implement serialization/deserialization
  + *
    * Revision 1.6  2003/10/09 13:49:30  neilg
    * make StringPool functions virtual so that we can implement a synchronized 
version of StringPool for thread-safe updates.
    *
  @@ -104,7 +107,7 @@
   //  Includes
   // ---------------------------------------------------------------------------
   #include <xercesc/util/StringPool.hpp>
  -
  +#include <assert.h>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -268,6 +271,53 @@
       // Bump the current id and return the id of the new elem we just added
       fCurId++;
       return newElem->fId;
  +}
  +
  +/***
  + * Support for Serialization/De-serialization
  + ***/
  +
  +IMPL_XSERIALIZABLE_TOCREATE(XMLStringPool)
  +
  +void XMLStringPool::serialize(XSerializeEngine& serEng)
  +{
  +    /***
  +     * Since we are pretty sure that fIdMap and fHashTable is 
  +     * not shared by any other object, therefore there is no owned/referenced
  +     * issue. Thus we can serialize the raw data only, rather than serializing 
  +     * both fIdMap and fHashTable.
  +     *
  +     * And we can rebuild the fIdMap and fHashTable out of the raw data during
  +     * deserialization.
  +     *
  +    ***/
  +    if (serEng.isStoring())
  +    {
  +        serEng<<fCurId;
  +        for (unsigned int index = 1; index < fCurId; index++)
  +        {
  +            const XMLCh* stringData = getValueForId(index);
  +            serEng.writeString(stringData);
  +        }
  +    }
  +    else
  +    {
  +        unsigned int mapSize;
  +        serEng>>mapSize;
  +        assert(1 == fCurId);  //make sure empty
  +
  +        for (unsigned int index = 1; index < mapSize; index++)
  +        {
  +            XMLCh* stringData;
  +            serEng.readString(stringData);
  +            addNewEntry(stringData);            
  +        }
  +    }
  +}
  +
  +XMLStringPool::XMLStringPool(MemoryManager* const manager)
  +{
  +    XMLStringPool(109, manager);
   }
   
   XERCES_CPP_NAMESPACE_END
  
  
  
  1.7       +12 -1     xml-xerces/c/src/xercesc/util/StringPool.hpp
  
  Index: StringPool.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/StringPool.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StringPool.hpp    9 Oct 2003 13:49:30 -0000       1.6
  +++ StringPool.hpp    29 Oct 2003 16:18:41 -0000      1.7
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.7  2003/10/29 16:18:41  peiyongz
  + * Implement serialization/deserialization
  + *
    * Revision 1.6  2003/10/09 13:49:30  neilg
    * make StringPool functions virtual so that we can implement a synchronized 
version of StringPool for thread-safe updates.
    *
  @@ -99,6 +102,8 @@
   
   #include <xercesc/util/RefHashTableOf.hpp>
   
  +#include <xercesc/internal/XSerializable.hpp>
  +
   XERCES_CPP_NAMESPACE_BEGIN
   
   //
  @@ -114,7 +119,7 @@
   //  other than flushing it completely, and because ids are assigned
   //  sequentially from 1.
   //
  -class XMLUTIL_EXPORT XMLStringPool : public XMemory
  +class XMLUTIL_EXPORT XMLStringPool : public XSerializable, public XMemory
   {
   public :
       // -----------------------------------------------------------------------
  @@ -139,6 +144,12 @@
       virtual const XMLCh* getValueForId(const unsigned int id) const;
       virtual unsigned int getStringCount() const;
   
  +    /***
  +     * Support for Serialization/De-serialization
  +     ***/
  +    DECL_XSERIALIZABLE(XMLStringPool)
  +
  +    XMLStringPool(MemoryManager* const manager);
   
   private :
       // -----------------------------------------------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to