gareth 2002/12/17 09:17:59 Modified: c/src/xercesc/util Makefile.in RefVectorOf.c RefVectorOf.hpp c/src/xercesc/validators/schema SchemaInfo.hpp TraverseSchema.cpp Added: c/src/xercesc/util BaseRefVectorOf.c BaseRefVectorOf.hpp RefArrayVectorOf.c RefArrayVectorOf.hpp Log: added abstract base class BaseRefVectorOf from which both RefVectorOf and RefArrayVectorOf inherit the new RefArrayVectorOf has proper destructor for array deletion Revision Changes Path 1.24 +7 -0 xml-xerces/c/src/xercesc/util/Makefile.in Index: Makefile.in =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/Makefile.in,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Makefile.in 12 Dec 2002 16:37:09 -0000 1.23 +++ Makefile.in 17 Dec 2002 17:17:58 -0000 1.24 @@ -55,6 +55,10 @@ # # # $Log$ +# Revision 1.24 2002/12/17 17:17:58 gareth +# added abstract base class BaseRefVectorOf from which both RefVectorOf and RefArrayVectorOf inherit +# the new RefArrayVectorOf has proper destructor for array deletion +# # Revision 1.23 2002/12/12 16:37:09 peiyongz # generate message catalog files for all UNIX platform if -miconv specified. # @@ -410,6 +414,7 @@ ArrayIndexOutOfBoundsException.hpp \ AutoSense.hpp \ Base64.hpp \ + BaseRefVectorOf.hpp \ BinFileInputStream.hpp \ BinInputStream.hpp \ BinMemInputStream.hpp \ @@ -441,6 +446,7 @@ PlatformUtils.hpp \ QName.hpp \ RefArrayOf.hpp \ + RefArrayVectorOf.hpp \ RefHash2KeysTableOf.hpp \ RefHash3KeysIdPool.hpp \ RefHashTableOf.hpp \ @@ -497,6 +503,7 @@ UTIL_CPP_PRIVHEADERS = C_FILES = \ + BaseRefVectorOf.c \ CountedPointer.c \ FlagJanitor.c \ Janitor.c \ @@ -504,6 +511,7 @@ KeyValuePair.c \ NameIdPool.c \ RefArrayOf.c \ + RefArrayVectorOf.c \ RefHash2KeysTableOf.c \ RefHash3KeysIdPool.c \ RefHashTableOf.c \ 1.5 +6 -286 xml-xerces/c/src/xercesc/util/RefVectorOf.c Index: RefVectorOf.c =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefVectorOf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- RefVectorOf.c 4 Nov 2002 15:22:04 -0000 1.4 +++ RefVectorOf.c 17 Dec 2002 17:17:58 -0000 1.5 @@ -56,6 +56,10 @@ /** * $Log$ + * Revision 1.5 2002/12/17 17:17:58 gareth + * added abstract base class BaseRefVectorOf from which both RefVectorOf and RefArrayVectorOf inherit + * the new RefArrayVectorOf has proper destructor for array deletion + * * Revision 1.4 2002/11/04 15:22:04 tng * C++ Namespace Support. * @@ -104,302 +108,19 @@ // --------------------------------------------------------------------------- // RefVectorOf: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TElem> RefVectorOf<TElem>:: -RefVectorOf(const unsigned int maxElems, const bool adoptElems) : - - fAdoptedElems(adoptElems) - , fCurCount(0) - , fMaxCount(maxElems) - , fElemList(0) +template <class TElem> RefVectorOf<TElem>::RefVectorOf(const unsigned int maxElems, const bool adoptElems = true) : BaseRefVectorOf<TElem>(maxElems, adoptElems) { - // Allocate and initialize the array - fElemList = new TElem*[maxElems]; - for (unsigned int index = 0; index < maxElems; index++) - fElemList[index] = 0; } template <class TElem> RefVectorOf<TElem>::~RefVectorOf() { if (fAdoptedElems) { - for (unsigned int index = 0; index < fCurCount; index++) - delete fElemList[index]; + for (unsigned int index = 0; index < fCurCount; index++) + delete fElemList[index]; } delete [] fElemList; } - -// --------------------------------------------------------------------------- -// RefVectorOf: Element management -// --------------------------------------------------------------------------- -template <class TElem> void RefVectorOf<TElem>::addElement(TElem* const toAdd) -{ - ensureExtraCapacity(1); - fElemList[fCurCount] = toAdd; - fCurCount++; -} - - -template <class TElem> void -RefVectorOf<TElem>::setElementAt(TElem* const toSet, const unsigned int setAt) -{ - if (setAt >= fCurCount) - ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); - - if (fAdoptedElems) - delete fElemList[setAt]; - fElemList[setAt] = toSet; -} - -template <class TElem> void RefVectorOf<TElem>:: -insertElementAt(TElem* const toInsert, const unsigned int insertAt) -{ - if (insertAt == fCurCount) - { - addElement(toInsert); - return; - } - - if (insertAt > fCurCount) - ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); - - ensureExtraCapacity(1); - - // Make room for the newbie - for (unsigned int index = fCurCount; index > insertAt; index--) - fElemList[index] = fElemList[index-1]; - - // And stick it in and bump the count - fElemList[insertAt] = toInsert; - fCurCount++; -} - -template <class TElem> TElem* RefVectorOf<TElem>:: -orphanElementAt(const unsigned int orphanAt) -{ - if (orphanAt >= fCurCount) - ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); - - // Get the element we are going to orphan - TElem* retVal = fElemList[orphanAt]; - - // Optimize if its the last element - if (orphanAt == fCurCount-1) - { - fElemList[orphanAt] = 0; - fCurCount--; - return retVal; - } - - // Copy down every element above orphan point - for (unsigned int index = orphanAt; 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--; - - return retVal; -} - -template <class TElem> void RefVectorOf<TElem>::removeAllElements() -{ - for (unsigned int index = 0; index < fCurCount; index++) - { - if (fAdoptedElems) - delete fElemList[index]; - - // Keep unused elements zero for sanity's sake - fElemList[index] = 0; - } - fCurCount = 0; -} - -template <class TElem> void RefVectorOf<TElem>:: -removeElementAt(const unsigned int removeAt) -{ - if (removeAt >= fCurCount) - ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); - - if (fAdoptedElems) - delete 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 RefVectorOf<TElem>::removeLastElement() -{ - if (!fCurCount) - return; - fCurCount--; - - if (fAdoptedElems) - delete fElemList[fCurCount]; -} - -template <class TElem> -bool RefVectorOf<TElem>::containsElement(const TElem* const toCheck) { - - for (unsigned int i = 0; i < fCurCount; i++) { - if (fElemList[i] == toCheck) { - return true; - } - } - - return false; -} - -// -// cleanup(): -// similar to destructor -// called to cleanup the memory, in case destructor cannot be called -// -template <class TElem> void RefVectorOf<TElem>::cleanup() -{ - if (fAdoptedElems) - { - for (unsigned int index = 0; index < fCurCount; index++) - delete fElemList[index]; - } - delete [] fElemList; -} - -// -// reinitialize(): -// similar to constructor -// called to re-construct the fElemList from scratch again -// -template <class TElem> void RefVectorOf<TElem>::reinitialize() -{ - // reinitialize the array - if (fElemList) - cleanup(); - - fElemList = new TElem*[fMaxCount]; - for (unsigned int index = 0; index < fMaxCount; index++) - fElemList[index] = 0; - -} - - -// --------------------------------------------------------------------------- -// RefVectorOf: Getter methods -// --------------------------------------------------------------------------- -template <class TElem> unsigned int RefVectorOf<TElem>::curCapacity() const -{ - return fMaxCount; -} - -template <class TElem> const TElem* RefVectorOf<TElem>:: -elementAt(const unsigned int getAt) const -{ - if (getAt >= fCurCount) - ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); - return fElemList[getAt]; -} - -template <class TElem> TElem* -RefVectorOf<TElem>::elementAt(const unsigned int getAt) -{ - if (getAt >= fCurCount) - ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); - return fElemList[getAt]; -} - -template <class TElem> unsigned int RefVectorOf<TElem>::size() const -{ - return fCurCount; -} - - -// --------------------------------------------------------------------------- -// RefVectorOf: Miscellaneous -// --------------------------------------------------------------------------- -template <class TElem> void RefVectorOf<TElem>:: -ensureExtraCapacity(const unsigned int length) -{ - unsigned int newMax = fCurCount + length; - - if (newMax < fMaxCount) - return; - - // Avoid too many reallocations by providing a little more space - if (newMax < fMaxCount + 32) - newMax = fMaxCount + 32; - - // Allocate the new array and copy over the existing stuff - TElem** newList = new TElem*[newMax]; - unsigned int index = 0; - for (; index < fCurCount; index++) - newList[index] = fElemList[index]; - - // Zero out the rest of them - for (; index < newMax; index++) - newList[index] = 0; - - // Clean up the old array and update our members - delete [] fElemList; - fElemList = newList; - fMaxCount = newMax; -} - - - -// --------------------------------------------------------------------------- -// RefVectorEnumerator: Constructors and Destructor -// --------------------------------------------------------------------------- -template <class TElem> RefVectorEnumerator<TElem>:: -RefVectorEnumerator( RefVectorOf<TElem>* const toEnum - , const bool adopt) : - fAdopted(adopt) - , fCurIndex(0) - , fToEnum(toEnum) -{ -} - -template <class TElem> RefVectorEnumerator<TElem>::~RefVectorEnumerator() -{ - if (fAdopted) - delete fToEnum; -} - - -// --------------------------------------------------------------------------- -// RefVectorEnumerator: Enum interface -// --------------------------------------------------------------------------- -template <class TElem> bool RefVectorEnumerator<TElem>::hasMoreElements() const -{ - if (fCurIndex >= fToEnum->size()) - return false; - return true; -} - -template <class TElem> TElem& RefVectorEnumerator<TElem>::nextElement() -{ - return *(fToEnum->elementAt(fCurIndex++)); -} - -template <class TElem> void RefVectorEnumerator<TElem>::Reset() -{ - fCurIndex = 0; -} XERCES_CPP_NAMESPACE_END 1.6 +12 -85 xml-xerces/c/src/xercesc/util/RefVectorOf.hpp Index: RefVectorOf.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefVectorOf.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- RefVectorOf.hpp 4 Dec 2002 02:32:43 -0000 1.5 +++ RefVectorOf.hpp 17 Dec 2002 17:17:58 -0000 1.6 @@ -56,6 +56,10 @@ /* * $Log$ + * Revision 1.6 2002/12/17 17:17:58 gareth + * added abstract base class BaseRefVectorOf from which both RefVectorOf and RefArrayVectorOf inherit + * the new RefArrayVectorOf has proper destructor for array deletion + * * Revision 1.5 2002/12/04 02:32:43 knoaman * #include cleanup. * @@ -99,103 +103,27 @@ #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> #include <xercesc/util/XMLEnumerator.hpp> +#include <xercesc/util/BaseRefVectorOf.hpp> XERCES_CPP_NAMESPACE_BEGIN -template <class TElem> class RefVectorOf +/** + * Class with implementation for vectors of References - implements from the + * Abstract class Vector + */ +template <class TElem> class RefVectorOf : public BaseRefVectorOf<TElem> { public : // ----------------------------------------------------------------------- - // Constructors and Destructor + // Constructor // ----------------------------------------------------------------------- RefVectorOf(const unsigned int maxElems, const bool adoptElems = true); - ~RefVectorOf(); - - - // ----------------------------------------------------------------------- - // Element management - // ----------------------------------------------------------------------- - void addElement(TElem* const toAdd); - 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(); - bool containsElement(const TElem* const toCheck); - void cleanup(); - void reinitialize(); - - - // ----------------------------------------------------------------------- - // Getter methods - // ----------------------------------------------------------------------- - unsigned int curCapacity() const; - const TElem* elementAt(const unsigned int getAt) const; - TElem* elementAt(const unsigned int getAt); - unsigned int size() const; - - - // ----------------------------------------------------------------------- - // Miscellaneous - // ----------------------------------------------------------------------- - void ensureExtraCapacity(const unsigned int length); - -private: // ----------------------------------------------------------------------- - // Data members + // Destructor // ----------------------------------------------------------------------- - bool fAdoptedElems; - unsigned int fCurCount; - unsigned int fMaxCount; - TElem** fElemList; -}; - - -// -// An enumerator for a reference vector. It derives from the basic enumerator -// class, so that value vectors can be generically enumerated. -// -template <class TElem> class RefVectorEnumerator : public XMLEnumerator<TElem> -{ -public : - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - RefVectorEnumerator - ( - RefVectorOf<TElem>* const toEnum - , const bool adopt = false - ); - virtual ~RefVectorEnumerator(); - - - // ----------------------------------------------------------------------- - // Enum interface - // ----------------------------------------------------------------------- - bool hasMoreElements() const; - TElem& nextElement(); - void Reset(); - + ~RefVectorOf(); -private : - // ----------------------------------------------------------------------- - // Data Members - // - // fAdopted - // Indicates whether we have adopted the passed vector. If so then - // we delete the vector when we are destroyed. - // - // fCurIndex - // This is the current index into the vector. - // - // fToEnum - // The reference vector being enumerated. - // ----------------------------------------------------------------------- - bool fAdopted; - unsigned int fCurIndex; - RefVectorOf<TElem>* fToEnum; }; XERCES_CPP_NAMESPACE_END 1.1 xml-xerces/c/src/xercesc/util/BaseRefVectorOf.c Index: BaseRefVectorOf.c =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache\@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation, and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.ibm.com . For more information * on the Apache Software Foundation, please see * <http://www.apache.org/>. */ // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- #if defined(XERCES_TMPLSINC) #include <xercesc/util/BaseRefVectorOf.hpp> #endif XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // BaseRefVectorOf: Constructors and Destructor // --------------------------------------------------------------------------- template <class TElem> BaseRefVectorOf<TElem>:: BaseRefVectorOf(const unsigned int maxElems, const bool adoptElems) : fAdoptedElems(adoptElems) , fCurCount(0) , fMaxCount(maxElems) , fElemList(0) { // Allocate and initialize the array fElemList = new TElem*[maxElems]; for (unsigned int index = 0; index < maxElems; index++) fElemList[index] = 0; } //implemented so code will link template <class TElem> BaseRefVectorOf<TElem>::~BaseRefVectorOf() { } // --------------------------------------------------------------------------- // BaseRefVectorOf: Element management // --------------------------------------------------------------------------- template <class TElem> void BaseRefVectorOf<TElem>::addElement(TElem* const toAdd) { ensureExtraCapacity(1); fElemList[fCurCount] = toAdd; fCurCount++; } template <class TElem> void BaseRefVectorOf<TElem>::setElementAt(TElem* const toSet, const unsigned int setAt) { if (setAt >= fCurCount) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); if (fAdoptedElems) delete fElemList[setAt]; fElemList[setAt] = toSet; } template <class TElem> void BaseRefVectorOf<TElem>:: insertElementAt(TElem* const toInsert, const unsigned int insertAt) { if (insertAt == fCurCount) { addElement(toInsert); return; } if (insertAt > fCurCount) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); ensureExtraCapacity(1); // Make room for the newbie for (unsigned int index = fCurCount; index > insertAt; index--) fElemList[index] = fElemList[index-1]; // And stick it in and bump the count fElemList[insertAt] = toInsert; fCurCount++; } template <class TElem> TElem* BaseRefVectorOf<TElem>:: orphanElementAt(const unsigned int orphanAt) { if (orphanAt >= fCurCount) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); // Get the element we are going to orphan TElem* retVal = fElemList[orphanAt]; // Optimize if its the last element if (orphanAt == fCurCount-1) { fElemList[orphanAt] = 0; fCurCount--; return retVal; } // Copy down every element above orphan point for (unsigned int index = orphanAt; 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--; return retVal; } template <class TElem> void BaseRefVectorOf<TElem>::removeAllElements() { for (unsigned int index = 0; index < fCurCount; index++) { if (fAdoptedElems) delete fElemList[index]; // Keep unused elements zero for sanity's sake fElemList[index] = 0; } fCurCount = 0; } template <class TElem> void BaseRefVectorOf<TElem>:: removeElementAt(const unsigned int removeAt) { if (removeAt >= fCurCount) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); if (fAdoptedElems) delete 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 BaseRefVectorOf<TElem>::removeLastElement() { if (!fCurCount) return; fCurCount--; if (fAdoptedElems) delete fElemList[fCurCount]; } template <class TElem> bool BaseRefVectorOf<TElem>::containsElement(const TElem* const toCheck) { for (unsigned int i = 0; i < fCurCount; i++) { if (fElemList[i] == toCheck) { return true; } } return false; } // // cleanup(): // similar to destructor // called to cleanup the memory, in case destructor cannot be called // template <class TElem> void BaseRefVectorOf<TElem>::cleanup() { if (fAdoptedElems) { for (unsigned int index = 0; index < fCurCount; index++) delete fElemList[index]; } delete [] fElemList; } // // reinitialize(): // similar to constructor // called to re-construct the fElemList from scratch again // template <class TElem> void BaseRefVectorOf<TElem>::reinitialize() { // reinitialize the array if (fElemList) cleanup(); fElemList = new TElem*[fMaxCount]; for (unsigned int index = 0; index < fMaxCount; index++) fElemList[index] = 0; } // --------------------------------------------------------------------------- // BaseRefVectorOf: Getter methods // --------------------------------------------------------------------------- template <class TElem> unsigned int BaseRefVectorOf<TElem>::curCapacity() const { return fMaxCount; } template <class TElem> const TElem* BaseRefVectorOf<TElem>:: elementAt(const unsigned int getAt) const { if (getAt >= fCurCount) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); return fElemList[getAt]; } template <class TElem> TElem* BaseRefVectorOf<TElem>::elementAt(const unsigned int getAt) { if (getAt >= fCurCount) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex); return fElemList[getAt]; } template <class TElem> unsigned int BaseRefVectorOf<TElem>::size() const { return fCurCount; } // --------------------------------------------------------------------------- // BaseRefVectorOf: Miscellaneous // --------------------------------------------------------------------------- template <class TElem> void BaseRefVectorOf<TElem>:: ensureExtraCapacity(const unsigned int length) { unsigned int newMax = fCurCount + length; if (newMax < fMaxCount) return; // Avoid too many reallocations by providing a little more space if (newMax < fMaxCount + 32) newMax = fMaxCount + 32; // Allocate the new array and copy over the existing stuff TElem** newList = new TElem*[newMax]; unsigned int index = 0; for (; index < fCurCount; index++) newList[index] = fElemList[index]; // Zero out the rest of them for (; index < newMax; index++) newList[index] = 0; // Clean up the old array and update our members delete [] fElemList; fElemList = newList; fMaxCount = newMax; } // --------------------------------------------------------------------------- // AbstractBaseRefVectorEnumerator: Constructors and Destructor // --------------------------------------------------------------------------- template <class TElem> BaseRefVectorEnumerator<TElem>:: BaseRefVectorEnumerator( BaseRefVectorOf<TElem>* const toEnum , const bool adopt) : fAdopted(adopt) , fCurIndex(0) , fToEnum(toEnum) { } template <class TElem> BaseRefVectorEnumerator<TElem>::~BaseRefVectorEnumerator() { if (fAdopted) delete fToEnum; } // --------------------------------------------------------------------------- // RefBaseRefVectorEnumerator: Enum interface // --------------------------------------------------------------------------- template <class TElem> bool BaseRefVectorEnumerator<TElem>::hasMoreElements() const { if (fCurIndex >= fToEnum->size()) return false; return true; } template <class TElem> TElem& BaseRefVectorEnumerator<TElem>::nextElement() { return *(fToEnum->elementAt(fCurIndex++)); } template <class TElem> void BaseRefVectorEnumerator<TElem>::Reset() { fCurIndex = 0; } XERCES_CPP_NAMESPACE_END 1.1 xml-xerces/c/src/xercesc/util/BaseRefVectorOf.hpp Index: BaseRefVectorOf.hpp =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache\@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation, and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.ibm.com . For more information * on the Apache Software Foundation, please see * <http://www.apache.org/>. */ #if !defined(ABSTRACTVECTOROF_HPP) #define ABSTRACTVECTOROF_HPP #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> #include <xercesc/util/XMLEnumerator.hpp> XERCES_CPP_NAMESPACE_BEGIN /** * Abstract base class for the xerces internal representation of Vector. * * The destructor is abstract, forcing each of RefVectorOf and * RefArrayVectorOf to implement their own appropriate one. * */ template <class TElem> class BaseRefVectorOf { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- BaseRefVectorOf(const unsigned int maxElems, const bool adoptElems = true); virtual ~BaseRefVectorOf() = 0; // ----------------------------------------------------------------------- // Element management // ----------------------------------------------------------------------- void addElement(TElem* const toAdd); 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(); bool containsElement(const TElem* const toCheck); void cleanup(); void reinitialize(); // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- unsigned int curCapacity() const; const TElem* elementAt(const unsigned int getAt) const; TElem* elementAt(const unsigned int getAt); unsigned int size() const; // ----------------------------------------------------------------------- // Miscellaneous // ----------------------------------------------------------------------- void ensureExtraCapacity(const unsigned int length); protected: // ----------------------------------------------------------------------- // Data members // ----------------------------------------------------------------------- bool fAdoptedElems; unsigned int fCurCount; unsigned int fMaxCount; TElem** fElemList; }; // // An enumerator for a vector. It derives from the basic enumerator // class, so that value vectors can be generically enumerated. // template <class TElem> class BaseRefVectorEnumerator : public XMLEnumerator<TElem> { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- BaseRefVectorEnumerator ( BaseRefVectorOf<TElem>* const toEnum , const bool adopt = false ); virtual ~BaseRefVectorEnumerator(); // ----------------------------------------------------------------------- // Enum interface // ----------------------------------------------------------------------- bool hasMoreElements() const; TElem& nextElement(); void Reset(); private : // ----------------------------------------------------------------------- // Data Members // // fAdopted // Indicates whether we have adopted the passed vector. If so then // we delete the vector when we are destroyed. // // fCurIndex // This is the current index into the vector. // // fToEnum // The reference vector being enumerated. // ----------------------------------------------------------------------- bool fAdopted; unsigned int fCurIndex; BaseRefVectorOf<TElem>* fToEnum; }; XERCES_CPP_NAMESPACE_END #if !defined(XERCES_TMPLSINC) #include <xercesc/util/BaseRefVectorOf.c> #endif #endif 1.1 xml-xerces/c/src/xercesc/util/RefArrayVectorOf.c Index: RefArrayVectorOf.c =================================================================== // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- #if defined(XERCES_TMPLSINC) #include "RefArrayVectorOf.hpp" #endif XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // RefArrayVectorOf: Constructor and Destructor // --------------------------------------------------------------------------- template <class TElem> RefArrayVectorOf<TElem>::RefArrayVectorOf(const unsigned int maxElems, const bool adoptElems = true) : BaseRefVectorOf<TElem>(maxElems, adoptElems) { } template <class TElem> RefArrayVectorOf<TElem>::~RefArrayVectorOf() { if (fAdoptedElems) { for (unsigned int index = 0; index < fCurCount; index++) delete[] fElemList[index]; } delete [] fElemList; } XERCES_CPP_NAMESPACE_END 1.1 xml-xerces/c/src/xercesc/util/RefArrayVectorOf.hpp Index: RefArrayVectorOf.hpp =================================================================== #if !defined(REFARRAYVECTOROF_HPP) #define REFARRAYVECTOROF_HPP #include <xercesc/util/BaseRefVectorOf.hpp> XERCES_CPP_NAMESPACE_BEGIN /** * Class with implementation for vectors of pointers to arrays - implements from * the Abstract class Vector */ template <class TElem> class RefArrayVectorOf : public BaseRefVectorOf<TElem> { public : // ----------------------------------------------------------------------- // Constructor // ----------------------------------------------------------------------- RefArrayVectorOf(const unsigned int maxElems, const bool adoptElems = true); // ----------------------------------------------------------------------- // Destructor // ----------------------------------------------------------------------- ~RefArrayVectorOf(); }; XERCES_CPP_NAMESPACE_END #if !defined(XERCES_TMPLSINC) #include <xercesc/util/RefArrayVectorOf.c> #endif #endif 1.12 +4 -4 xml-xerces/c/src/xercesc/validators/schema/SchemaInfo.hpp Index: SchemaInfo.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaInfo.hpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- SchemaInfo.hpp 6 Dec 2002 13:27:14 -0000 1.11 +++ SchemaInfo.hpp 17 Dec 2002 17:17:58 -0000 1.12 @@ -133,7 +133,7 @@ int getScopeCount() const; unsigned int getNamespaceScopeLevel() const; unsigned short getElemAttrDefaultQualified() const; - RefVectorEnumerator<SchemaInfo> getImportingListEnumerator() const; + BaseRefVectorEnumerator<SchemaInfo> getImportingListEnumerator() const; ValueVectorOf<const DOMElement*>* getRecursingAnonTypes() const; ValueVectorOf<const XMLCh*>* getRecursingTypeNames() const; @@ -249,10 +249,10 @@ return fScopeCount; } -inline RefVectorEnumerator<SchemaInfo> +inline BaseRefVectorEnumerator<SchemaInfo> SchemaInfo::getImportingListEnumerator() const { - return RefVectorEnumerator<SchemaInfo>(fImportingInfoList); + return BaseRefVectorEnumerator<SchemaInfo>(fImportingInfoList); } inline ValueVectorOf<const DOMElement*>* 1.43 +3 -3 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp Index: TraverseSchema.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- TraverseSchema.cpp 13 Dec 2002 21:16:11 -0000 1.42 +++ TraverseSchema.cpp 17 Dec 2002 17:17:58 -0000 1.43 @@ -2453,7 +2453,7 @@ subsElements->addElement(elemDecl); // update related subs. info in case of circular import - RefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator(); + BaseRefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator(); while (importingEnum.hasMoreElements()) { @@ -6247,7 +6247,7 @@ validSubsElements->addElement(elemDecl); // update related subs. info in case of circular import - RefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator(); + BaseRefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator(); while (importingEnum.hasMoreElements()) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]