From 26b755f43c744a97f0f8ba1a1da6433cc155e21b Mon Sep 17 00:00:00 2001 From: Alberto Massari <amassari@apache.org> Date: Thu, 1 May 2008 16:54:41 +0000 Subject: [PATCH] Rewrite the storage mechanism to avoid cast (XERCESC-1678) git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@652574 13f79535-47bb-0310-9956-ffa450edef68 --- .../framework/psvi/PSVIAttributeList.cpp | 25 ++++----- .../framework/psvi/PSVIAttributeList.hpp | 55 +++++++++++-------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/xercesc/framework/psvi/PSVIAttributeList.cpp b/src/xercesc/framework/psvi/PSVIAttributeList.cpp index 087a4c37d..ea4a04501 100644 --- a/src/xercesc/framework/psvi/PSVIAttributeList.cpp +++ b/src/xercesc/framework/psvi/PSVIAttributeList.cpp @@ -26,15 +26,11 @@ XERCES_CPP_NAMESPACE_BEGIN PSVIAttributeList::PSVIAttributeList( MemoryManager* const manager ): - fMemoryManager(manager) - , fAttrList(0) - , fAttrNameList(0) - , fAttrNSList(0) - , fAttrPos(0) + fMemoryManager(manager) + , fAttrList(0) + , fAttrPos(0) { - fAttrList= new (fMemoryManager) RefVectorOf<PSVIAttribute> (10, true, fMemoryManager); - fAttrNameList= new (fMemoryManager) RefArrayVectorOf<XMLCh> (10, false, fMemoryManager); - fAttrNSList= new (fMemoryManager) RefArrayVectorOf<XMLCh> (10, false, fMemoryManager); + fAttrList= new (fMemoryManager) RefVectorOf<PSVIAttributeStorage> (10, true, fMemoryManager); } /* @@ -58,7 +54,7 @@ PSVIAttribute *PSVIAttributeList::getAttributePSVIAtIndex(const unsigned int ind { if(index >= fAttrPos) return 0; - return fAttrList->elementAt(index); + return fAttrList->elementAt(index)->fPSVIAttribute; } /* @@ -74,7 +70,7 @@ const XMLCh *PSVIAttributeList::getAttributeNameAtIndex(const unsigned int index if(index >= fAttrPos) return 0; - return fAttrNameList->elementAt(index); + return fAttrList->elementAt(index)->fAttributeName; } /* @@ -89,7 +85,7 @@ const XMLCh *PSVIAttributeList::getAttributeNamespaceAtIndex(const unsigned int { if(index >= fAttrPos) return 0; - return fAttrNSList->elementAt(index); + return fAttrList->elementAt(index)->fAttributeNamespace; } /* @@ -103,9 +99,10 @@ PSVIAttribute *PSVIAttributeList::getAttributePSVIByName(const XMLCh *attrName , const XMLCh * attrNamespace) { for (unsigned int index=0; index < fAttrPos; index++) { - if (XMLString::equals(attrName,fAttrNameList->elementAt(index)) - && XMLString::equals(attrNamespace,fAttrNSList->elementAt(index))) - return fAttrList->elementAt(index); + PSVIAttributeStorage* storage = fAttrList->elementAt(index); + if (XMLString::equals(attrName,storage->fAttributeName) && + XMLString::equals(attrNamespace,storage->fAttributeNamespace)) + return storage->fPSVIAttribute; } return 0; } diff --git a/src/xercesc/framework/psvi/PSVIAttributeList.hpp b/src/xercesc/framework/psvi/PSVIAttributeList.hpp index cb19955fe..1768b91a9 100644 --- a/src/xercesc/framework/psvi/PSVIAttributeList.hpp +++ b/src/xercesc/framework/psvi/PSVIAttributeList.hpp @@ -24,7 +24,7 @@ #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/framework/psvi/PSVIAttribute.hpp> -#include <xercesc/util/ValueVectorOf.hpp> +#include <xercesc/util/RefVectorOf.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -36,6 +36,25 @@ XERCES_CPP_NAMESPACE_BEGIN * under what conditions it may be relied upon to have meaningful contents. */ +class XMLPARSER_EXPORT PSVIAttributeStorage : public XMemory +{ +public: + PSVIAttributeStorage() : + fPSVIAttribute(0) + , fAttributeName(0) + , fAttributeNamespace(0) + { + } + + ~PSVIAttributeStorage() + { + delete fPSVIAttribute; + } + + PSVIAttribute* fPSVIAttribute; + const XMLCh* fAttributeName; + const XMLCh* fAttributeNamespace; +}; class XMLPARSER_EXPORT PSVIAttributeList : public XMemory { @@ -153,47 +172,37 @@ private: // handler to provide dynamically-need memory // fAttrList // list of PSVIAttributes contained by this object - // fAttrNameList - // list of the names of the initialized PSVIAttribute objects contained - // in this listing - // fAttrNSList - // list of the namespaces of the initialized PSVIAttribute objects contained - // in this listing // fAttrPos // current number of initialized PSVIAttributes in fAttrList - MemoryManager* fMemoryManager; - RefVectorOf<PSVIAttribute>* fAttrList; - RefArrayVectorOf<XMLCh>* fAttrNameList; - RefArrayVectorOf<XMLCh>* fAttrNSList; - unsigned int fAttrPos; + MemoryManager* fMemoryManager; + RefVectorOf<PSVIAttributeStorage>* fAttrList; + unsigned int fAttrPos; }; + inline PSVIAttributeList::~PSVIAttributeList() { delete fAttrList; - delete fAttrNameList; - delete fAttrNSList; } inline PSVIAttribute *PSVIAttributeList::getPSVIAttributeToFill( const XMLCh *attrName , const XMLCh * attrNS) { - PSVIAttribute *retAttr = 0; + PSVIAttributeStorage* storage = 0; if(fAttrPos == fAttrList->size()) { - retAttr = new (fMemoryManager)PSVIAttribute(fMemoryManager); - fAttrList->addElement(retAttr); - fAttrNameList->addElement((XMLCh *)attrName); - fAttrNSList->addElement((XMLCh *)attrNS); + storage = new (fMemoryManager) PSVIAttributeStorage(); + storage->fPSVIAttribute = new (fMemoryManager) PSVIAttribute(fMemoryManager); + fAttrList->addElement(storage); } else { - retAttr = fAttrList->elementAt(fAttrPos); - fAttrNameList->setElementAt((XMLCh *)attrName, fAttrPos); - fAttrNSList->setElementAt((XMLCh *)attrNS, fAttrPos); + storage = fAttrList->elementAt(fAttrPos); } + storage->fAttributeName = attrName; + storage->fAttributeNamespace = attrNS; fAttrPos++; - return retAttr; + return storage->fPSVIAttribute; } inline void PSVIAttributeList::reset() -- GitLab