[2674] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | * this work for additional information regarding copyright ownership. |
---|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | * (the "License"); you may not use this file except in compliance with |
---|
| 7 | * the License. You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | * See the License for the specific language governing permissions and |
---|
| 15 | * limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | * $Id: ValueStackOf.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #if !defined(VALUESTACKOF_HPP) |
---|
| 23 | #define VALUESTACKOF_HPP |
---|
| 24 | |
---|
| 25 | #include <xercesc/util/EmptyStackException.hpp> |
---|
| 26 | #include <xercesc/util/ValueVectorOf.hpp> |
---|
| 27 | |
---|
| 28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 29 | |
---|
| 30 | // |
---|
| 31 | // Forward declare the enumerator so he can be our friend. Can you say |
---|
| 32 | // friend? Sure... |
---|
| 33 | // |
---|
| 34 | template <class TElem> class ValueStackEnumerator; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | template <class TElem> class ValueStackOf : public XMemory |
---|
| 38 | { |
---|
| 39 | public : |
---|
| 40 | // ----------------------------------------------------------------------- |
---|
| 41 | // Constructors and Destructor |
---|
| 42 | // ----------------------------------------------------------------------- |
---|
| 43 | ValueStackOf |
---|
| 44 | ( |
---|
| 45 | const unsigned int fInitCapacity |
---|
| 46 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 47 | , const bool toCallDestructor = false |
---|
| 48 | ); |
---|
| 49 | ~ValueStackOf(); |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | // ----------------------------------------------------------------------- |
---|
| 53 | // Element management methods |
---|
| 54 | // ----------------------------------------------------------------------- |
---|
| 55 | void push(const TElem& toPush); |
---|
| 56 | const TElem& peek() const; |
---|
| 57 | TElem pop(); |
---|
| 58 | void removeAllElements(); |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | // ----------------------------------------------------------------------- |
---|
| 62 | // Getter methods |
---|
| 63 | // ----------------------------------------------------------------------- |
---|
| 64 | bool empty(); |
---|
| 65 | unsigned int curCapacity(); |
---|
| 66 | unsigned int size(); |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | private : |
---|
| 70 | // ----------------------------------------------------------------------- |
---|
| 71 | // Unimplemented constructors and operators |
---|
| 72 | // ----------------------------------------------------------------------- |
---|
| 73 | ValueStackOf(const ValueStackOf<TElem>&); |
---|
| 74 | ValueStackOf<TElem>& operator=(const ValueStackOf<TElem>&); |
---|
| 75 | |
---|
| 76 | // ----------------------------------------------------------------------- |
---|
| 77 | // Declare our friends |
---|
| 78 | // ----------------------------------------------------------------------- |
---|
| 79 | friend class ValueStackEnumerator<TElem>; |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | // ----------------------------------------------------------------------- |
---|
| 83 | // Data Members |
---|
| 84 | // |
---|
| 85 | // fVector |
---|
| 86 | // The vector that is used as the backing data structure for the |
---|
| 87 | // stack. |
---|
| 88 | // ----------------------------------------------------------------------- |
---|
| 89 | ValueVectorOf<TElem> fVector; |
---|
| 90 | }; |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | // |
---|
| 95 | // An enumerator for a value stack. It derives from the basic enumerator |
---|
| 96 | // class, so that value stacks can be generically enumerated. |
---|
| 97 | // |
---|
| 98 | template <class TElem> class ValueStackEnumerator : public XMLEnumerator<TElem>, public XMemory |
---|
| 99 | { |
---|
| 100 | public : |
---|
| 101 | // ----------------------------------------------------------------------- |
---|
| 102 | // Constructors and Destructor |
---|
| 103 | // ----------------------------------------------------------------------- |
---|
| 104 | ValueStackEnumerator |
---|
| 105 | ( |
---|
| 106 | ValueStackOf<TElem>* const toEnum |
---|
| 107 | , const bool adopt = false |
---|
| 108 | ); |
---|
| 109 | virtual ~ValueStackEnumerator(); |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | // ----------------------------------------------------------------------- |
---|
| 113 | // Enum interface |
---|
| 114 | // ----------------------------------------------------------------------- |
---|
| 115 | bool hasMoreElements() const; |
---|
| 116 | TElem& nextElement(); |
---|
| 117 | void Reset(); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | private : |
---|
| 121 | // ----------------------------------------------------------------------- |
---|
| 122 | // Unimplemented constructors and operators |
---|
| 123 | // ----------------------------------------------------------------------- |
---|
| 124 | ValueStackEnumerator(const ValueStackEnumerator<TElem>&); |
---|
| 125 | ValueStackEnumerator<TElem>& operator=(const ValueStackEnumerator<TElem>&); |
---|
| 126 | |
---|
| 127 | // ----------------------------------------------------------------------- |
---|
| 128 | // Data Members |
---|
| 129 | // |
---|
| 130 | // fAdopted |
---|
| 131 | // Indicates whether we have adopted the passed stack. If so then |
---|
| 132 | // we delete the stack when we are destroyed. |
---|
| 133 | // |
---|
| 134 | // fCurIndex |
---|
| 135 | // This is the current index into the vector inside the stack being |
---|
| 136 | // enumerated. |
---|
| 137 | // |
---|
| 138 | // fToEnum |
---|
| 139 | // The stack that is being enumerated. This is just kept for |
---|
| 140 | // adoption purposes, since we really are enumerating the vector |
---|
| 141 | // inside of it. |
---|
| 142 | // ----------------------------------------------------------------------- |
---|
| 143 | bool fAdopted; |
---|
| 144 | unsigned int fCurIndex; |
---|
| 145 | ValueVectorOf<TElem>* fVector; |
---|
| 146 | ValueStackOf<TElem>* fToEnum; |
---|
| 147 | }; |
---|
| 148 | |
---|
| 149 | XERCES_CPP_NAMESPACE_END |
---|
| 150 | |
---|
| 151 | #if !defined(XERCES_TMPLSINC) |
---|
| 152 | #include <xercesc/util/ValueStackOf.c> |
---|
| 153 | #endif |
---|
| 154 | |
---|
| 155 | #endif |
---|