GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: RefStackOf.c 676911 2008-07-15 13:27:32Z amassari $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #if defined(XERCES_TMPLSINC) 00027 #include <xercesc/util/RefStackOf.hpp> 00028 #endif 00029 00030 XERCES_CPP_NAMESPACE_BEGIN 00031 00032 // --------------------------------------------------------------------------- 00033 // RefStackOf: Constructors and Destructor 00034 // --------------------------------------------------------------------------- 00035 template <class TElem> 00036 RefStackOf<TElem>::RefStackOf(const XMLSize_t initElems, 00037 const bool adoptElems, 00038 MemoryManager* const manager) : 00039 00040 fVector(initElems, adoptElems, manager) 00041 { 00042 } 00043 00044 template <class TElem> RefStackOf<TElem>::~RefStackOf() 00045 { 00046 } 00047 00048 00049 // --------------------------------------------------------------------------- 00050 // RefStackOf: Element management methods 00051 // --------------------------------------------------------------------------- 00052 template <class TElem> const TElem* RefStackOf<TElem>:: 00053 elementAt(const XMLSize_t index) const 00054 { 00055 if (index >= fVector.size()) 00056 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager()); 00057 return fVector.elementAt(index); 00058 } 00059 00060 template <class TElem> TElem* RefStackOf<TElem>::popAt(const XMLSize_t index) 00061 { 00062 if (index >= fVector.size()) 00063 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager()); 00064 00065 // Orphan off the element from the slot in the vector 00066 return fVector.orphanElementAt(index); 00067 } 00068 00069 template <class TElem> void RefStackOf<TElem>::push(TElem* const toPush) 00070 { 00071 fVector.addElement(toPush); 00072 } 00073 00074 template <class TElem> const TElem* RefStackOf<TElem>::peek() const 00075 { 00076 const XMLSize_t curSize = fVector.size(); 00077 if (curSize == 0) 00078 ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager()); 00079 00080 return fVector.elementAt(curSize-1); 00081 } 00082 00083 template <class TElem> TElem* RefStackOf<TElem>::pop() 00084 { 00085 const XMLSize_t curSize = fVector.size(); 00086 if (curSize == 0) 00087 ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager()); 00088 00089 // Orphan off the element from the last slot in the vector 00090 return fVector.orphanElementAt(curSize-1); 00091 } 00092 00093 template <class TElem> void RefStackOf<TElem>::removeAllElements() 00094 { 00095 fVector.removeAllElements(); 00096 } 00097 00098 00099 // --------------------------------------------------------------------------- 00100 // RefStackOf: Getter methods 00101 // --------------------------------------------------------------------------- 00102 template <class TElem> bool RefStackOf<TElem>::empty() 00103 { 00104 return (fVector.size() == 0); 00105 } 00106 00107 template <class TElem> XMLSize_t RefStackOf<TElem>::curCapacity() 00108 { 00109 return fVector.curCapacity(); 00110 } 00111 00112 template <class TElem> XMLSize_t RefStackOf<TElem>::size() 00113 { 00114 return fVector.size(); 00115 } 00116 00117 00118 00119 00120 // --------------------------------------------------------------------------- 00121 // RefStackEnumerator: Constructors and Destructor 00122 // --------------------------------------------------------------------------- 00123 template <class TElem> RefStackEnumerator<TElem>:: 00124 RefStackEnumerator( RefStackOf<TElem>* const toEnum 00125 , const bool adopt) : 00126 fAdopted(adopt) 00127 , fCurIndex(0) 00128 , fToEnum(toEnum) 00129 , fVector(&toEnum->fVector) 00130 { 00131 } 00132 00133 template <class TElem> RefStackEnumerator<TElem>::~RefStackEnumerator() 00134 { 00135 if (fAdopted) 00136 delete fToEnum; 00137 } 00138 00139 00140 // --------------------------------------------------------------------------- 00141 // RefStackEnumerator: Enum interface 00142 // --------------------------------------------------------------------------- 00143 template <class TElem> bool RefStackEnumerator<TElem>::hasMoreElements() const 00144 { 00145 if (fCurIndex >= fVector->size()) 00146 return false; 00147 return true; 00148 } 00149 00150 template <class TElem> TElem& RefStackEnumerator<TElem>::nextElement() 00151 { 00152 return *fVector->elementAt(fCurIndex++); 00153 } 00154 00155 template <class TElem> void RefStackEnumerator<TElem>::Reset() 00156 { 00157 fCurIndex = 0; 00158 } 00159 00160 XERCES_CPP_NAMESPACE_END