[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 | #if !defined(ABSTRACTVECTOROF_HPP) |
---|
| 18 | #define ABSTRACTVECTOROF_HPP |
---|
| 19 | |
---|
| 20 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> |
---|
| 21 | #include <xercesc/util/XMLEnumerator.hpp> |
---|
| 22 | #include <xercesc/util/PlatformUtils.hpp> |
---|
| 23 | #include <xercesc/framework/MemoryManager.hpp> |
---|
| 24 | |
---|
| 25 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Abstract base class for the xerces internal representation of Vector. |
---|
| 29 | * |
---|
| 30 | * The destructor is abstract, forcing each of RefVectorOf and |
---|
| 31 | * RefArrayVectorOf to implement their own appropriate one. |
---|
| 32 | * |
---|
| 33 | */ |
---|
| 34 | template <class TElem> class BaseRefVectorOf : public XMemory |
---|
| 35 | { |
---|
| 36 | public : |
---|
| 37 | // ----------------------------------------------------------------------- |
---|
| 38 | // Constructors and Destructor |
---|
| 39 | // ----------------------------------------------------------------------- |
---|
| 40 | BaseRefVectorOf |
---|
| 41 | ( |
---|
| 42 | const unsigned int maxElems |
---|
| 43 | , const bool adoptElems = true |
---|
| 44 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 45 | ); |
---|
| 46 | virtual ~BaseRefVectorOf(); |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // ----------------------------------------------------------------------- |
---|
| 50 | // Element management |
---|
| 51 | // ----------------------------------------------------------------------- |
---|
| 52 | void addElement(TElem* const toAdd); |
---|
| 53 | virtual void setElementAt(TElem* const toSet, const unsigned int setAt); |
---|
| 54 | void insertElementAt(TElem* const toInsert, const unsigned int insertAt); |
---|
| 55 | TElem* orphanElementAt(const unsigned int orphanAt); |
---|
| 56 | virtual void removeAllElements(); |
---|
| 57 | virtual void removeElementAt(const unsigned int removeAt); |
---|
| 58 | virtual void removeLastElement(); |
---|
| 59 | bool containsElement(const TElem* const toCheck); |
---|
| 60 | virtual void cleanup(); |
---|
| 61 | void reinitialize(); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | // ----------------------------------------------------------------------- |
---|
| 65 | // Getter methods |
---|
| 66 | // ----------------------------------------------------------------------- |
---|
| 67 | unsigned int curCapacity() const; |
---|
| 68 | const TElem* elementAt(const unsigned int getAt) const; |
---|
| 69 | TElem* elementAt(const unsigned int getAt); |
---|
| 70 | unsigned int size() const; |
---|
| 71 | MemoryManager* getMemoryManager() const; |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | // ----------------------------------------------------------------------- |
---|
| 75 | // Miscellaneous |
---|
| 76 | // ----------------------------------------------------------------------- |
---|
| 77 | void ensureExtraCapacity(const unsigned int length); |
---|
| 78 | |
---|
| 79 | private: |
---|
| 80 | // ----------------------------------------------------------------------- |
---|
| 81 | // Unimplemented constructors and operators |
---|
| 82 | // ----------------------------------------------------------------------- |
---|
| 83 | BaseRefVectorOf(const BaseRefVectorOf<TElem>& copy); |
---|
| 84 | BaseRefVectorOf& operator=(const BaseRefVectorOf<TElem>& copy); |
---|
| 85 | |
---|
| 86 | protected: |
---|
| 87 | // ----------------------------------------------------------------------- |
---|
| 88 | // Data members |
---|
| 89 | // ----------------------------------------------------------------------- |
---|
| 90 | bool fAdoptedElems; |
---|
| 91 | unsigned int fCurCount; |
---|
| 92 | unsigned int fMaxCount; |
---|
| 93 | TElem** fElemList; |
---|
| 94 | MemoryManager* fMemoryManager; |
---|
| 95 | }; |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | // |
---|
| 99 | // An enumerator for a vector. It derives from the basic enumerator |
---|
| 100 | // class, so that value vectors can be generically enumerated. |
---|
| 101 | // |
---|
| 102 | template <class TElem> class BaseRefVectorEnumerator : public XMLEnumerator<TElem>, public XMemory |
---|
| 103 | { |
---|
| 104 | public : |
---|
| 105 | // ----------------------------------------------------------------------- |
---|
| 106 | // Constructors and Destructor |
---|
| 107 | // ----------------------------------------------------------------------- |
---|
| 108 | BaseRefVectorEnumerator |
---|
| 109 | ( |
---|
| 110 | BaseRefVectorOf<TElem>* const toEnum |
---|
| 111 | , const bool adopt = false |
---|
| 112 | ); |
---|
| 113 | virtual ~BaseRefVectorEnumerator(); |
---|
| 114 | |
---|
| 115 | BaseRefVectorEnumerator(const BaseRefVectorEnumerator<TElem>& copy); |
---|
| 116 | // ----------------------------------------------------------------------- |
---|
| 117 | // Enum interface |
---|
| 118 | // ----------------------------------------------------------------------- |
---|
| 119 | bool hasMoreElements() const; |
---|
| 120 | TElem& nextElement(); |
---|
| 121 | void Reset(); |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | private : |
---|
| 125 | // ----------------------------------------------------------------------- |
---|
| 126 | // Unimplemented constructors and operators |
---|
| 127 | // ----------------------------------------------------------------------- |
---|
| 128 | BaseRefVectorEnumerator& operator=(const BaseRefVectorEnumerator<TElem>& copy); |
---|
| 129 | // ----------------------------------------------------------------------- |
---|
| 130 | // Data Members |
---|
| 131 | // |
---|
| 132 | // fAdopted |
---|
| 133 | // Indicates whether we have adopted the passed vector. If so then |
---|
| 134 | // we delete the vector when we are destroyed. |
---|
| 135 | // |
---|
| 136 | // fCurIndex |
---|
| 137 | // This is the current index into the vector. |
---|
| 138 | // |
---|
| 139 | // fToEnum |
---|
| 140 | // The reference vector being enumerated. |
---|
| 141 | // ----------------------------------------------------------------------- |
---|
| 142 | bool fAdopted; |
---|
| 143 | unsigned int fCurIndex; |
---|
| 144 | BaseRefVectorOf<TElem>* fToEnum; |
---|
| 145 | }; |
---|
| 146 | |
---|
| 147 | XERCES_CPP_NAMESPACE_END |
---|
| 148 | |
---|
| 149 | #if !defined(XERCES_TMPLSINC) |
---|
| 150 | #include <xercesc/util/BaseRefVectorOf.c> |
---|
| 151 | #endif |
---|
| 152 | |
---|
| 153 | #endif |
---|