knoaman 2003/05/27 09:52:17 Modified: c/src/xercesc/util RefArrayVectorOf.hpp RefArrayVectorOf.c BaseRefVectorOf.hpp Log: Use manager when deallocating memory in the case of RefArrayVectorOf. Revision Changes Path 1.3 +8 -0 xml-xerces/c/src/xercesc/util/RefArrayVectorOf.hpp Index: RefArrayVectorOf.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefArrayVectorOf.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RefArrayVectorOf.hpp 16 May 2003 06:01:52 -0000 1.2 +++ RefArrayVectorOf.hpp 27 May 2003 16:52:16 -0000 1.3 @@ -24,6 +24,14 @@ // ----------------------------------------------------------------------- ~RefArrayVectorOf(); + // ----------------------------------------------------------------------- + // Element management + // ----------------------------------------------------------------------- + void setElementAt(TElem* const toSet, const unsigned int setAt); + void removeAllElements(); + void removeElementAt(const unsigned int removeAt); + void removeLastElement(); + void cleanup(); }; XERCES_CPP_NAMESPACE_END 1.6 +73 -1 xml-xerces/c/src/xercesc/util/RefArrayVectorOf.c Index: RefArrayVectorOf.c =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefArrayVectorOf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- RefArrayVectorOf.c 16 May 2003 06:01:52 -0000 1.5 +++ RefArrayVectorOf.c 27 May 2003 16:52:16 -0000 1.6 @@ -25,10 +25,82 @@ if (fAdoptedElems) { for (unsigned int index = 0; index < fCurCount; index++) - fMemoryManager->deallocate(fElemList[index]);//delete[] fElemList[index]; + fMemoryManager->deallocate(fElemList[index]);//delete[] fElemList[index]; } fMemoryManager->deallocate(fElemList);//delete [] fElemList; } +template <class TElem> void +RefArrayVectorOf<TElem>::setElementAt(TElem* const toSet, const unsigned int setAt) +{ + if (setAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); + + if (fAdoptedElems) + fMemoryManager->deallocate(fElemList[setAt]); + + fElemList[setAt] = toSet; +} + +template <class TElem> void RefArrayVectorOf<TElem>::removeAllElements() +{ + for (unsigned int index = 0; index < fCurCount; index++) + { + if (fAdoptedElems) + fMemoryManager->deallocate(fElemList[index]); + + // Keep unused elements zero for sanity's sake + fElemList[index] = 0; + } + fCurCount = 0; +} + +template <class TElem> void RefArrayVectorOf<TElem>:: +removeElementAt(const unsigned int removeAt) +{ + if (removeAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); + + if (fAdoptedElems) + fMemoryManager->deallocate(fElemList[removeAt]); + + // Optimize if its the last element + if (removeAt == fCurCount-1) + { + fElemList[removeAt] = 0; + fCurCount--; + return; + } + + // Copy down every element above remove point + for (unsigned int index = removeAt; index < fCurCount-1; index++) + fElemList[index] = fElemList[index+1]; + + // Keep unused elements zero for sanity's sake + fElemList[fCurCount-1] = 0; + + // And bump down count + fCurCount--; +} + +template <class TElem> void RefArrayVectorOf<TElem>::removeLastElement() +{ + if (!fCurCount) + return; + fCurCount--; + + if (fAdoptedElems) + fMemoryManager->deallocate(fElemList[fCurCount]); +} + +template <class TElem> void RefArrayVectorOf<TElem>::cleanup() +{ + if (fAdoptedElems) + { + for (unsigned int index = 0; index < fCurCount; index++) + fMemoryManager->deallocate(fElemList[index]); + } + fMemoryManager->deallocate(fElemList);//delete [] fElemList; +} XERCES_CPP_NAMESPACE_END 1.5 +5 -5 xml-xerces/c/src/xercesc/util/BaseRefVectorOf.hpp Index: BaseRefVectorOf.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/BaseRefVectorOf.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- BaseRefVectorOf.hpp 16 May 2003 21:36:59 -0000 1.4 +++ BaseRefVectorOf.hpp 27 May 2003 16:52:16 -0000 1.5 @@ -89,14 +89,14 @@ // Element management // ----------------------------------------------------------------------- void addElement(TElem* const toAdd); - void setElementAt(TElem* const toSet, const unsigned int setAt); + virtual void setElementAt(TElem* const toSet, const unsigned int setAt); void insertElementAt(TElem* const toInsert, const unsigned int insertAt); TElem* orphanElementAt(const unsigned int orphanAt); - void removeAllElements(); - void removeElementAt(const unsigned int removeAt); - void removeLastElement(); + virtual void removeAllElements(); + virtual void removeElementAt(const unsigned int removeAt); + virtual void removeLastElement(); bool containsElement(const TElem* const toCheck); - void cleanup(); + virtual void cleanup(); void reinitialize();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]