[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: RefStackOf.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #if !defined(REFSTACKOF_HPP) |
---|
| 23 | #define REFSTACKOF_HPP |
---|
| 24 | |
---|
| 25 | #include <xercesc/util/RefVectorOf.hpp> |
---|
| 26 | #include <xercesc/util/EmptyStackException.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 RefStackEnumerator; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | template <class TElem> class RefStackOf : public XMemory |
---|
| 38 | { |
---|
| 39 | public : |
---|
| 40 | // ----------------------------------------------------------------------- |
---|
| 41 | // Constructors and Destructor |
---|
| 42 | // ----------------------------------------------------------------------- |
---|
| 43 | RefStackOf(const unsigned int initElems, |
---|
| 44 | const bool adoptElems = true, |
---|
| 45 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 46 | ~RefStackOf(); |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // ----------------------------------------------------------------------- |
---|
| 50 | // Element management methods |
---|
| 51 | // ----------------------------------------------------------------------- |
---|
| 52 | const TElem* elementAt(const unsigned int index) const; |
---|
| 53 | void push(TElem* const toPush); |
---|
| 54 | const TElem* peek() const; |
---|
| 55 | TElem* pop(); |
---|
| 56 | void removeAllElements(); |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | // ----------------------------------------------------------------------- |
---|
| 60 | // Getter methods |
---|
| 61 | // ----------------------------------------------------------------------- |
---|
| 62 | bool empty(); |
---|
| 63 | unsigned int curCapacity(); |
---|
| 64 | unsigned int size(); |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | private : |
---|
| 68 | // ----------------------------------------------------------------------- |
---|
| 69 | // Declare our friends |
---|
| 70 | // ----------------------------------------------------------------------- |
---|
| 71 | friend class RefStackEnumerator<TElem>; |
---|
| 72 | |
---|
| 73 | // ----------------------------------------------------------------------- |
---|
| 74 | // Unimplemented constructors and operators |
---|
| 75 | // ----------------------------------------------------------------------- |
---|
| 76 | RefStackOf(const RefStackOf<TElem>&); |
---|
| 77 | RefStackOf<TElem>& operator=(const RefStackOf<TElem>&); |
---|
| 78 | |
---|
| 79 | // ----------------------------------------------------------------------- |
---|
| 80 | // Data Members |
---|
| 81 | // |
---|
| 82 | // fVector |
---|
| 83 | // The vector that is used as the backing data structure for the |
---|
| 84 | // stack. |
---|
| 85 | // ----------------------------------------------------------------------- |
---|
| 86 | RefVectorOf<TElem> fVector; |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | // |
---|
| 92 | // An enumerator for a value stack. It derives from the basic enumerator |
---|
| 93 | // class, so that value stacks can be generically enumerated. |
---|
| 94 | // |
---|
| 95 | template <class TElem> class RefStackEnumerator : public XMLEnumerator<TElem>, public XMemory |
---|
| 96 | { |
---|
| 97 | public : |
---|
| 98 | // ----------------------------------------------------------------------- |
---|
| 99 | // Constructors and Destructor |
---|
| 100 | // ----------------------------------------------------------------------- |
---|
| 101 | RefStackEnumerator |
---|
| 102 | ( |
---|
| 103 | RefStackOf<TElem>* const toEnum |
---|
| 104 | , const bool adopt = false |
---|
| 105 | ); |
---|
| 106 | virtual ~RefStackEnumerator(); |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | // ----------------------------------------------------------------------- |
---|
| 110 | // Enum interface |
---|
| 111 | // ----------------------------------------------------------------------- |
---|
| 112 | bool hasMoreElements() const; |
---|
| 113 | TElem& nextElement(); |
---|
| 114 | void Reset(); |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | private : |
---|
| 118 | // ----------------------------------------------------------------------- |
---|
| 119 | // Unimplemented constructors and operators |
---|
| 120 | // ----------------------------------------------------------------------- |
---|
| 121 | RefStackEnumerator(const RefStackEnumerator<TElem>&); |
---|
| 122 | RefStackEnumerator<TElem>& operator=(const RefStackEnumerator<TElem>&); |
---|
| 123 | // ----------------------------------------------------------------------- |
---|
| 124 | // Data Members |
---|
| 125 | // |
---|
| 126 | // fAdopted |
---|
| 127 | // Indicates whether we have adopted the passed stack. If so then |
---|
| 128 | // we delete the stack when we are destroyed. |
---|
| 129 | // |
---|
| 130 | // fCurIndex |
---|
| 131 | // This is the current index into the vector inside the stack being |
---|
| 132 | // enumerated. |
---|
| 133 | // |
---|
| 134 | // fToEnum |
---|
| 135 | // The stack that is being enumerated. This is just kept for |
---|
| 136 | // adoption purposes, since we really are enumerating the vector |
---|
| 137 | // inside of it. |
---|
| 138 | // ----------------------------------------------------------------------- |
---|
| 139 | bool fAdopted; |
---|
| 140 | unsigned int fCurIndex; |
---|
| 141 | RefVectorOf<TElem>* fVector; |
---|
| 142 | RefStackOf<TElem>* fToEnum; |
---|
| 143 | }; |
---|
| 144 | |
---|
| 145 | XERCES_CPP_NAMESPACE_END |
---|
| 146 | |
---|
| 147 | #if !defined(XERCES_TMPLSINC) |
---|
| 148 | #include <xercesc/util/RefStackOf.c> |
---|
| 149 | #endif |
---|
| 150 | |
---|
| 151 | #endif |
---|