From e66e8ccdca5719f2a9820298bd61805f74445969 Mon Sep 17 00:00:00 2001 From: PeiYong Zhang <peiyongz@apache.org> Date: Tue, 7 Oct 2003 19:38:31 +0000 Subject: [PATCH] API for Template_Class Object Serialization/Deserialization git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175256 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/internal/XSerializeEngine.cpp | 81 ++++++++++++++++++++++- src/xercesc/internal/XSerializeEngine.hpp | 44 ++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/src/xercesc/internal/XSerializeEngine.cpp b/src/xercesc/internal/XSerializeEngine.cpp index 96db11fd9..521e6a047 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 ff4bda95a..c30015858 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; -- GitLab