diff --git a/src/xercesc/internal/XSerializeEngine.cpp b/src/xercesc/internal/XSerializeEngine.cpp index 96db11fd93de6f595825ae88a4a4c80d0e0a657c..521e6a0472e5e6cad0a7e49b466ee7bc7a53a00f 100644 --- a/src/xercesc/internal/XSerializeEngine.cpp +++ b/src/xercesc/internal/XSerializeEngine.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/10/07 19:38:31 peiyongz + * API for Template_Class Object Serialization/Deserialization + * * Revision 1.5 2003/09/25 22:22:00 peiyongz * Introduction of readString/writeString * @@ -94,8 +97,9 @@ static const int noDataFollowed = -1; static const XSerializeEngine::XSerializedObjectId_t fgNullObjectTag = 0; // indicating null ptrs static const XSerializeEngine::XSerializedObjectId_t fgNewClassTag = 0xFFFFFFFF; // indicating new class +static const XSerializeEngine::XSerializedObjectId_t fgTemplateObjTag = 0xFFFFFFFE; // indicating template object static const XSerializeEngine::XSerializedObjectId_t fgClassMask = 0x80000000; // indicates class tag -static const XSerializeEngine::XSerializedObjectId_t fgMaxObjectCount = 0x3FFFFFFE; +static const XSerializeEngine::XSerializedObjectId_t fgMaxObjectCount = 0x3FFFFFFD; static XMLCh value1[16]; static XMLCh value2[16]; @@ -987,5 +991,80 @@ inline void XSerializeEngine::ensureBufferLen(int bufferLen) const } +// --------------------------------------------------------------------------- +// Template object +// --------------------------------------------------------------------------- +/*** + * + * Search the store pool to see if the address has been seen before or not. + * + * If yes, write the corresponding object Tag to the internal buffer + * and return true. + * + * Otherwise, add the address to the store pool and return false + * to notifiy the client application code to store the template object. + * + ***/ +bool XSerializeEngine::needToWriteTemplateObject(void* const templateObjectToWrite) +{ + ensureStoring(); //don't ensurePointer here !!! + + XSerializedObjectId_t objIndex = 0; + + if (!templateObjectToWrite) + { + *this << fgNullObjectTag; // null pointer + return false; + } + else if (objIndex = lookupStorePool(templateObjectToWrite)) + { + *this << objIndex; // write an object reference tag + return false; + } + else + { + *this << fgTemplateObjTag; // write fgTemplateObjTag to denote that actual + // template object follows + addStorePool(templateObjectToWrite); // put the address into StorePool + return true; + } + +} + +bool XSerializeEngine::needToReadTemplateObject(void** templateObjectToRead) +{ + ensureLoading(); + + XSerializedObjectId_t obTag; + + *this >> obTag; + + if (obTag == fgTemplateObjTag) + { + /*** + * what follows fgTemplateObjTag is the actual template object + * We need the client application to create a template object + * and register it through registerTemplateObject(), and deserialize + * template object + ***/ + return true; + } + else + { + /*** + * We hava a reference to an existing template object, get it. + */ + *templateObjectToRead = lookupLoadPool(obTag); + return false; + } + +} + +void XSerializeEngine::registerTemplateObject(void* const templateObjectToRegister) +{ + ensureLoading(); + addLoadPool(templateObjectToRegister); +} + XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/internal/XSerializeEngine.hpp b/src/xercesc/internal/XSerializeEngine.hpp index ff4bda95a05f48b474cac06fa18cfc8398851076..c30015858bf1cfac77cc309ec9414c210491b2e3 100644 --- a/src/xercesc/internal/XSerializeEngine.hpp +++ b/src/xercesc/internal/XSerializeEngine.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.4 2003/10/07 19:38:31 peiyongz + * API for Template_Class Object Serialization/Deserialization + * * Revision 1.3 2003/09/25 22:22:00 peiyongz * Introduction of readString/writeString * @@ -358,6 +361,47 @@ public: , int& dataLen = defaultDataLen , bool toReadBufLen = false); + + /*** + * + * Check if the template object has been stored or not + * + * Param + * objectPtr: the template object pointer + * + * Return: true : the object has NOT been stored yet + * false : otherwise + * + ***/ + bool needToWriteTemplateObject(void* objectToWrite); + + /*** + * + * Check if the template object has been loaded or not + * + * Param + * objectPtr: the address of the template object pointer + * + * Return: true : the object has NOT been loaded yet + * false : otherwise + * + ***/ + bool needToReadTemplateObject(void** objectToRead); + + /*** + * + * In the case of needToReadTemplateObject() return true, the client + * application needs to instantiate an expected template object, and + * register the address to the engine. + * + * Param + * objectPtr: the template object pointer newly instantiated + * + * Return: + * + ***/ + void registerTemplateObject(void* const objectToRegister); + static const bool toReadBufferLen; static int defaultBufferLen;