Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:13

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 
0023 // ---------------------------------------------------------------------------
0024 //  Includes
0025 // ---------------------------------------------------------------------------
0026 #if defined(XERCES_TMPLSINC)
0027 #include <xercesc/util/RefStackOf.hpp>
0028 #endif
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 // ---------------------------------------------------------------------------
0033 //  RefStackOf: Constructors and Destructor
0034 // ---------------------------------------------------------------------------
0035 template <class TElem>
0036 RefStackOf<TElem>::RefStackOf(const XMLSize_t initElems,
0037                               const bool adoptElems,
0038                               MemoryManager* const manager) :
0039 
0040     fVector(initElems, adoptElems, manager)
0041 {
0042 }
0043 
0044 template <class TElem> RefStackOf<TElem>::~RefStackOf()
0045 {
0046 }
0047 
0048 
0049 // ---------------------------------------------------------------------------
0050 //  RefStackOf: Element management methods
0051 // ---------------------------------------------------------------------------
0052 template <class TElem> const TElem* RefStackOf<TElem>::
0053 elementAt(const XMLSize_t index) const
0054 {
0055     if (index >= fVector.size())
0056         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager());
0057     return fVector.elementAt(index);
0058 }
0059 
0060 template <class TElem> TElem* RefStackOf<TElem>::popAt(const XMLSize_t index)
0061 {
0062     if (index >= fVector.size())
0063         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager());
0064 
0065     // Orphan off the element from the slot in the vector
0066     return fVector.orphanElementAt(index);
0067 }
0068 
0069 template <class TElem> void RefStackOf<TElem>::push(TElem* const toPush)
0070 {
0071     fVector.addElement(toPush);
0072 }
0073 
0074 template <class TElem> const TElem* RefStackOf<TElem>::peek() const
0075 {
0076     const XMLSize_t curSize = fVector.size();
0077     if (curSize == 0)
0078         ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
0079 
0080     return fVector.elementAt(curSize-1);
0081 }
0082 
0083 template <class TElem> TElem* RefStackOf<TElem>::pop()
0084 {
0085     const XMLSize_t curSize = fVector.size();
0086     if (curSize == 0)
0087         ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
0088 
0089     // Orphan off the element from the last slot in the vector
0090     return fVector.orphanElementAt(curSize-1);
0091 }
0092 
0093 template <class TElem> void RefStackOf<TElem>::removeAllElements()
0094 {
0095     fVector.removeAllElements();
0096 }
0097 
0098 
0099 // ---------------------------------------------------------------------------
0100 //  RefStackOf: Getter methods
0101 // ---------------------------------------------------------------------------
0102 template <class TElem> bool RefStackOf<TElem>::empty()
0103 {
0104     return (fVector.size() == 0);
0105 }
0106 
0107 template <class TElem> XMLSize_t RefStackOf<TElem>::curCapacity()
0108 {
0109     return fVector.curCapacity();
0110 }
0111 
0112 template <class TElem> XMLSize_t RefStackOf<TElem>::size()
0113 {
0114     return fVector.size();
0115 }
0116 
0117 
0118 
0119 
0120 // ---------------------------------------------------------------------------
0121 //  RefStackEnumerator: Constructors and Destructor
0122 // ---------------------------------------------------------------------------
0123 template <class TElem> RefStackEnumerator<TElem>::
0124 RefStackEnumerator(         RefStackOf<TElem>* const    toEnum
0125                     , const bool                        adopt) :
0126     fAdopted(adopt)
0127     , fCurIndex(0)
0128     , fToEnum(toEnum)
0129     , fVector(&toEnum->fVector)
0130 {
0131 }
0132 
0133 template <class TElem> RefStackEnumerator<TElem>::~RefStackEnumerator()
0134 {
0135     if (fAdopted)
0136         delete fToEnum;
0137 }
0138 
0139 
0140 // ---------------------------------------------------------------------------
0141 //  RefStackEnumerator: Enum interface
0142 // ---------------------------------------------------------------------------
0143 template <class TElem> bool RefStackEnumerator<TElem>::hasMoreElements() const
0144 {
0145     if (fCurIndex >= fVector->size())
0146         return false;
0147     return true;
0148 }
0149 
0150 template <class TElem> TElem& RefStackEnumerator<TElem>::nextElement()
0151 {
0152     return *fVector->elementAt(fCurIndex++);
0153 }
0154 
0155 template <class TElem> void RefStackEnumerator<TElem>::Reset()
0156 {
0157     fCurIndex = 0;
0158 }
0159 
0160 XERCES_CPP_NAMESPACE_END