You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2004/03/02 00:19:03 UTC
cvs commit: xml-xerces/c/src/xercesc/internal XSerializeEngine.cpp XSerializeEngine.hpp
peiyongz 2004/03/01 15:19:03
Modified: c/src/xercesc/internal XSerializeEngine.cpp
XSerializeEngine.hpp
Log:
Grant XSerializeEngine access to GrammarPool
Revision Changes Path
1.16 +100 -30 xml-xerces/c/src/xercesc/internal/XSerializeEngine.cpp
Index: XSerializeEngine.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XSerializeEngine.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XSerializeEngine.cpp 20 Feb 2004 20:57:39 -0000 1.15
+++ XSerializeEngine.cpp 1 Mar 2004 23:19:03 -0000 1.16
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.16 2004/03/01 23:19:03 peiyongz
+ * Grant XSerializeEngine access to GrammarPool
+ *
* Revision 1.15 2004/02/20 20:57:39 peiyongz
* Bug#27046: path from David Bertoni
*
@@ -113,6 +116,10 @@
#include <xercesc/util/HashPtr.hpp>
+#include <xercesc/framework/XMLGrammarPool.hpp>
+#include <xercesc/framework/BinOutputStream.hpp>
+#include <xercesc/util/BinInputStream.hpp>
+
XERCES_CPP_NAMESPACE_BEGIN
const bool XSerializeEngine::toWriteBufferLen = true;
@@ -130,11 +137,11 @@
if (condition) \
{ \
XMLCh value1[17]; \
- XMLString::binToText(data, value1, 16, 10, fMemoryManager); \
+ XMLString::binToText(data, value1, 16, 10, getMemoryManager()); \
ThrowXMLwithMemMgr1(XSerializationException \
, err_msg \
, value1 \
- , fMemoryManager); \
+ , getMemoryManager()); \
}
#define TEST_THROW_ARG2(condition, data1, data2, err_msg) \
@@ -142,32 +149,48 @@
{ \
XMLCh value1[17]; \
XMLCh value2[17]; \
- XMLString::binToText(data1, value1, 16, 10, fMemoryManager); \
- XMLString::binToText(data2, value2, 16, 10, fMemoryManager); \
+ XMLString::binToText(data1, value1, 16, 10, getMemoryManager()); \
+ XMLString::binToText(data2, value2, 16, 10, getMemoryManager()); \
ThrowXMLwithMemMgr2(XSerializationException \
, err_msg \
, value1 \
, value2 \
- , fMemoryManager); \
+ , getMemoryManager()); \
}
// ---------------------------------------------------------------------------
// Constructor and Destructor
// ---------------------------------------------------------------------------
+XSerializeEngine::~XSerializeEngine()
+{
+ if (isStoring())
+ {
+ flush();
+ delete fStorePool;
+ }
+ else
+ {
+ delete fLoadPool;
+ }
+
+ getMemoryManager()->deallocate(fBufStart);
+
+}
+
XSerializeEngine::XSerializeEngine(BinInputStream* inStream
- , MemoryManager* const manager
+ , XMLGrammarPool* const gramPool
, unsigned long bufSize)
:fStoreLoad(mode_Load)
-,fMemoryManager(manager)
+,fGrammarPool(gramPool)
,fInputStream(inStream)
,fOutputStream(0)
,fBufSize(bufSize)
-,fBufStart( (XMLByte*) fMemoryManager->allocate(bufSize))
+,fBufStart( (XMLByte*) gramPool->getMemoryManager()->allocate(bufSize))
,fBufEnd(0)
,fBufCur(fBufStart)
,fBufLoadMax(fBufStart)
,fStorePool(0)
-,fLoadPool( new (fMemoryManager) ValueVectorOf<void*>(29, fMemoryManager, false))
+,fLoadPool( new (gramPool->getMemoryManager()) ValueVectorOf<void*>(29, gramPool->getMemoryManager(), false))
,fObjectCount(0)
{
/***
@@ -178,39 +201,70 @@
}
XSerializeEngine::XSerializeEngine(BinOutputStream* outStream
- , MemoryManager* const manager
+ , XMLGrammarPool* const gramPool
, unsigned long bufSize)
:fStoreLoad(mode_Store)
-,fMemoryManager(manager)
+,fGrammarPool(gramPool)
,fInputStream(0)
,fOutputStream(outStream)
,fBufSize(bufSize)
-,fBufStart((XMLByte*) fMemoryManager->allocate(bufSize))
+,fBufStart((XMLByte*) gramPool->getMemoryManager()->allocate(bufSize))
,fBufEnd(fBufStart+bufSize)
,fBufCur(fBufStart)
,fBufLoadMax(0)
-,fStorePool( new (fMemoryManager) RefHashTableOf<XSerializedObjectId>(29, true, new HashPtr(), fMemoryManager) )
+,fStorePool( new (gramPool->getMemoryManager()) RefHashTableOf<XSerializedObjectId>(29, true, new HashPtr(), gramPool->getMemoryManager()) )
,fLoadPool(0)
,fObjectCount(0)
{
//initialize store pool
- fStorePool->put(0, new (fMemoryManager) XSerializedObjectId(fgNullObjectTag));
+ fStorePool->put(0, new (gramPool->getMemoryManager()) XSerializedObjectId(fgNullObjectTag));
}
-XSerializeEngine::~XSerializeEngine()
+// ---------------------------------------------------------------------------
+// Deprecated Constructor
+// ---------------------------------------------------------------------------
+XSerializeEngine::XSerializeEngine(BinInputStream* inStream
+ , MemoryManager* const manager
+ , unsigned long bufSize)
+:fStoreLoad(mode_Load)
+,fGrammarPool(0)
+,fInputStream(inStream)
+,fOutputStream(0)
+,fBufSize(bufSize)
+,fBufStart( (XMLByte*) manager->allocate(bufSize))
+,fBufEnd(0)
+,fBufCur(fBufStart)
+,fBufLoadMax(fBufStart)
+,fStorePool(0)
+,fLoadPool( new (manager) ValueVectorOf<void*>(29, manager, false))
+,fObjectCount(0)
{
- if (isStoring())
- {
- flush();
- delete fStorePool;
- }
- else
- {
- delete fLoadPool;
- }
+ /***
+ * initialize buffer from the inStream
+ ***/
+ fillBuffer(1);
- fMemoryManager->deallocate(fBufStart);
+}
+
+XSerializeEngine::XSerializeEngine(BinOutputStream* outStream
+ , MemoryManager* const manager
+ , unsigned long bufSize)
+:fStoreLoad(mode_Store)
+,fGrammarPool(0)
+,fInputStream(0)
+,fOutputStream(outStream)
+,fBufSize(bufSize)
+,fBufStart((XMLByte*) manager->allocate(bufSize))
+,fBufEnd(fBufStart+bufSize)
+,fBufCur(fBufStart)
+,fBufLoadMax(0)
+,fStorePool( new (manager) RefHashTableOf<XSerializedObjectId>(29, true, new HashPtr(), manager) )
+,fLoadPool(0)
+,fObjectCount(0)
+{
+ //initialize store pool
+ fStorePool->put(0, new (manager) XSerializedObjectId(fgNullObjectTag));
}
@@ -418,7 +472,7 @@
else
{
// create the object from the prototype
- objRet = protoType->fCreateObject(fMemoryManager);
+ objRet = protoType->fCreateObject(getMemoryManager());
Assert((objRet != 0), XMLExcepts::XSer_CreateObject_Fail);
// put it into load pool
@@ -453,7 +507,7 @@
{
// what follows fgNewClassTag is the prototype object info
// for the object anticipated, go and verify the info
- XProtoType::load(*this, protoType->fClassName, fMemoryManager);
+ XProtoType::load(*this, protoType->fClassName, getMemoryManager());
addLoadPool((void*)protoType);
}
@@ -575,7 +629,7 @@
dataLen = bufferLen++;
}
- toRead = (XMLCh*) fMemoryManager->allocate(bufferLen * sizeof(XMLCh));
+ toRead = (XMLCh*) getMemoryManager()->allocate(bufferLen * sizeof(XMLCh));
read(toRead, dataLen);
toRead[dataLen] = 0;
}
@@ -606,7 +660,7 @@
dataLen = bufferLen++;
}
- toRead = (XMLByte*) fMemoryManager->allocate(bufferLen * sizeof(XMLByte));
+ toRead = (XMLByte*) getMemoryManager()->allocate(bufferLen * sizeof(XMLByte));
read(toRead, dataLen);
toRead[dataLen] = 0;
@@ -1105,6 +1159,22 @@
{
ensureLoading();
addLoadPool(templateObjectToRegister);
+}
+
+XMLGrammarPool* XSerializeEngine::getGrammarPool() const
+{
+ return fGrammarPool;
+}
+
+XMLStringPool* XSerializeEngine::getStringPool() const
+{
+ return fGrammarPool->getURIStringPool();
+}
+
+MemoryManager* XSerializeEngine::getMemoryManager() const
+{
+ //todo: changed to return fGrammarPool->getMemoryManager()
+ return fGrammarPool ? fGrammarPool->getMemoryManager() : XMLPlatformUtils::fgMemoryManager;
}
XERCES_CPP_NAMESPACE_END
1.16 +78 -16 xml-xerces/c/src/xercesc/internal/XSerializeEngine.hpp
Index: XSerializeEngine.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XSerializeEngine.hpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XSerializeEngine.hpp 20 Feb 2004 20:57:39 -0000 1.15
+++ XSerializeEngine.hpp 1 Mar 2004 23:19:03 -0000 1.16
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.16 2004/03/01 23:19:03 peiyongz
+ * Grant XSerializeEngine access to GrammarPool
+ *
* Revision 1.15 2004/02/20 20:57:39 peiyongz
* Bug#27046: path from David Bertoni
*
@@ -108,19 +111,22 @@
#if !defined(XSERIALIZE_ENGINE_HPP)
#define XSERIALIZE_ENGINE_HPP
-#include <xercesc/framework/BinOutputStream.hpp>
-#include <xercesc/util/BinInputStream.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
-#include <xercesc/internal/XSerializationException.hpp>
#include <xercesc/util/XMLExceptMsgs.hpp>
+#include <xercesc/internal/XSerializationException.hpp>
+
XERCES_CPP_NAMESPACE_BEGIN
class XSerializable;
class XProtoType;
class MemoryManager;
class XSerializedObjectId;
+class BinOutputStream;
+class BinInputStream;
+class XMLGrammarPool;
+class XMLStringPool;
class XMLUTIL_EXPORT XSerializeEngine
{
@@ -152,6 +158,46 @@
*
* Param
* inStream input stream
+ * gramPool Grammar Pool
+ * bufSize the size of the internal buffer
+ *
+ ***/
+ XSerializeEngine(BinInputStream* inStream
+ , XMLGrammarPool* const gramPool
+ , unsigned long bufSize = 8192 );
+
+
+ /***
+ *
+ * Constructor for serialization(storing)
+ *
+ * Application needs to make sure that the instance of
+ * BinOutputStream, persists beyond the life of this
+ * SerializeEngine.
+ *
+ * Param
+ * outStream output stream
+ * gramPool Grammar Pool
+ * bufSize the size of the internal buffer
+ *
+ ***/
+ XSerializeEngine(BinOutputStream* outStream
+ , XMLGrammarPool* const gramPool
+ , unsigned long bufSize = 8192 );
+
+
+ /***
+ *
+ * Deprecated
+ *
+ * Constructor for de-serialization(loading)
+ *
+ * Application needs to make sure that the instance of
+ * BinInputStream, persists beyond the life of this
+ * SerializeEngine.
+ *
+ * Param
+ * inStream input stream
* manager MemoryManager
* bufSize the size of the internal buffer
*
@@ -160,8 +206,11 @@
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
, unsigned long bufSize = 8192 );
+
/***
*
+ * Deprecated
+ *
* Constructor for serialization(storing)
*
* Application needs to make sure that the instance of
@@ -209,12 +258,30 @@
/***
*
+ * Get the GrammarPool
+ *
+ * Return: XMLGrammarPool
+ *
+ ***/
+ XMLGrammarPool* getGrammarPool() const;
+
+ /***
+ *
+ * Get the StringPool
+ *
+ * Return: XMLStringPool
+ *
+ ***/
+ XMLStringPool* getStringPool() const;
+
+ /***
+ *
* Get the embeded Memory Manager
*
* Return: MemoryManager
*
***/
- inline MemoryManager* getMemoryManager() const;
+ MemoryManager* getMemoryManager() const;
/***
*
@@ -634,9 +701,9 @@
// fStoreLoad:
// Indicator: storing(serialization) or loading(de-serialization)
//
- // fMemoryManager:
- // used to allocate memory for internal consumption and/or
- // allocate memory for object created in de-serialization.
+ // fGrammarPool:
+ // Thw owning GrammarPool which instantiate this SerializeEngine
+ // instance
//
// fInputStream:
// Binary stream to read from (de-serialization), provided
@@ -670,8 +737,8 @@
//
// fMapCount:
// -------------------------------------------------------------------------------
- const short fStoreLoad;
- MemoryManager* const fMemoryManager;
+ const short fStoreLoad;
+ XMLGrammarPool* const fGrammarPool;
BinInputStream* const fInputStream;
BinOutputStream* const fOutputStream;
@@ -718,11 +785,6 @@
return (fStoreLoad == mode_Load);
}
-inline MemoryManager* XSerializeEngine::getMemoryManager() const
-{
- return fMemoryManager;
-}
-
inline XSerializeEngine& operator<<(XSerializeEngine& serEng
, XSerializable* const serObj)
{
@@ -747,7 +809,7 @@
{
if (!toEval)
{
- ThrowXMLwithMemMgr(XSerializationException, toThrow, fMemoryManager);
+ ThrowXMLwithMemMgr(XSerializationException, toThrow, getMemoryManager());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org