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: ValueStackOf.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/ValueStackOf.hpp> 00028 #endif 00029 00030 XERCES_CPP_NAMESPACE_BEGIN 00031 00032 00033 // --------------------------------------------------------------------------- 00034 // ValueStackOf: Constructors and Destructor 00035 // --------------------------------------------------------------------------- 00036 template <class TElem> 00037 ValueStackOf<TElem>::ValueStackOf(const XMLSize_t fInitCapacity, 00038 MemoryManager* const manager, 00039 const bool toCallDestructor) : 00040 00041 fVector(fInitCapacity, manager, toCallDestructor) 00042 { 00043 } 00044 00045 template <class TElem> ValueStackOf<TElem>::~ValueStackOf() 00046 { 00047 } 00048 00049 00050 // --------------------------------------------------------------------------- 00051 // ValueStackOf: Element management methods 00052 // --------------------------------------------------------------------------- 00053 template <class TElem> void ValueStackOf<TElem>::push(const TElem& toPush) 00054 { 00055 fVector.addElement(toPush); 00056 } 00057 00058 template <class TElem> const TElem& ValueStackOf<TElem>::peek() const 00059 { 00060 const XMLSize_t curSize = fVector.size(); 00061 if (curSize == 0) 00062 ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager()); 00063 00064 return fVector.elementAt(curSize-1); 00065 } 00066 00067 template <class TElem> TElem ValueStackOf<TElem>::pop() 00068 { 00069 const XMLSize_t curSize = fVector.size(); 00070 if (curSize == 0) 00071 ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager()); 00072 00073 TElem retVal = fVector.elementAt(curSize-1); 00074 fVector.removeElementAt(curSize-1); 00075 return retVal; 00076 } 00077 00078 template <class TElem> void ValueStackOf<TElem>::removeAllElements() 00079 { 00080 fVector.removeAllElements(); 00081 } 00082 00083 00084 // --------------------------------------------------------------------------- 00085 // ValueStackOf: Getter methods 00086 // --------------------------------------------------------------------------- 00087 template <class TElem> bool ValueStackOf<TElem>::empty() 00088 { 00089 return (fVector.size() == 0); 00090 } 00091 00092 template <class TElem> XMLSize_t ValueStackOf<TElem>::curCapacity() 00093 { 00094 return fVector.curCapacity(); 00095 } 00096 00097 template <class TElem> XMLSize_t ValueStackOf<TElem>::size() 00098 { 00099 return fVector.size(); 00100 } 00101 00102 00103 00104 00105 // --------------------------------------------------------------------------- 00106 // ValueStackEnumerator: Constructors and Destructor 00107 // --------------------------------------------------------------------------- 00108 template <class TElem> ValueStackEnumerator<TElem>:: 00109 ValueStackEnumerator( ValueStackOf<TElem>* const toEnum 00110 , const bool adopt) : 00111 00112 fAdopted(adopt) 00113 , fCurIndex(0) 00114 , fToEnum(toEnum) 00115 , fVector(&toEnum->fVector) 00116 { 00117 } 00118 00119 template <class TElem> ValueStackEnumerator<TElem>::~ValueStackEnumerator() 00120 { 00121 if (fAdopted) 00122 delete fToEnum; 00123 } 00124 00125 00126 // --------------------------------------------------------------------------- 00127 // ValueStackEnumerator: Enum interface 00128 // --------------------------------------------------------------------------- 00129 template <class TElem> bool ValueStackEnumerator<TElem>::hasMoreElements() const 00130 { 00131 if (fCurIndex >= fVector->size()) 00132 return false; 00133 return true; 00134 } 00135 00136 template <class TElem> TElem& ValueStackEnumerator<TElem>::nextElement() 00137 { 00138 return fVector->elementAt(fCurIndex++); 00139 } 00140 00141 template <class TElem> void ValueStackEnumerator<TElem>::Reset() 00142 { 00143 fCurIndex = 0; 00144 } 00145 00146 XERCES_CPP_NAMESPACE_END