[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: ValueVectorOf.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #if !defined(VALUEVECTOROF_HPP) |
---|
| 24 | #define VALUEVECTOROF_HPP |
---|
| 25 | |
---|
| 26 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> |
---|
| 27 | #include <xercesc/util/XMLEnumerator.hpp> |
---|
| 28 | #include <xercesc/util/PlatformUtils.hpp> |
---|
| 29 | #include <xercesc/framework/MemoryManager.hpp> |
---|
| 30 | |
---|
| 31 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 32 | |
---|
| 33 | template <class TElem> class ValueVectorOf : public XMemory |
---|
| 34 | { |
---|
| 35 | public : |
---|
| 36 | // ----------------------------------------------------------------------- |
---|
| 37 | // Constructors and Destructor |
---|
| 38 | // ----------------------------------------------------------------------- |
---|
| 39 | ValueVectorOf |
---|
| 40 | ( |
---|
| 41 | const unsigned int maxElems |
---|
| 42 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 43 | , const bool toCallDestructor = false |
---|
| 44 | ); |
---|
| 45 | ValueVectorOf(const ValueVectorOf<TElem>& toCopy); |
---|
| 46 | ~ValueVectorOf(); |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // ----------------------------------------------------------------------- |
---|
| 50 | // Operators |
---|
| 51 | // ----------------------------------------------------------------------- |
---|
| 52 | ValueVectorOf<TElem>& operator=(const ValueVectorOf<TElem>& toAssign); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | // ----------------------------------------------------------------------- |
---|
| 56 | // Element management |
---|
| 57 | // ----------------------------------------------------------------------- |
---|
| 58 | void addElement(const TElem& toAdd); |
---|
| 59 | void setElementAt(const TElem& toSet, const unsigned int setAt); |
---|
| 60 | void insertElementAt(const TElem& toInsert, const unsigned int insertAt); |
---|
| 61 | void removeElementAt(const unsigned int removeAt); |
---|
| 62 | void removeAllElements(); |
---|
| 63 | bool containsElement(const TElem& toCheck, const unsigned int startIndex = 0); |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | // ----------------------------------------------------------------------- |
---|
| 67 | // Getter methods |
---|
| 68 | // ----------------------------------------------------------------------- |
---|
| 69 | const TElem& elementAt(const unsigned int getAt) const; |
---|
| 70 | TElem& elementAt(const unsigned int getAt); |
---|
| 71 | unsigned int curCapacity() const; |
---|
| 72 | unsigned int size() const; |
---|
| 73 | MemoryManager* getMemoryManager() const; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | // ----------------------------------------------------------------------- |
---|
| 77 | // Miscellaneous |
---|
| 78 | // ----------------------------------------------------------------------- |
---|
| 79 | void ensureExtraCapacity(const unsigned int length); |
---|
| 80 | const TElem* rawData() const; |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | private: |
---|
| 84 | // ----------------------------------------------------------------------- |
---|
| 85 | // Data members |
---|
| 86 | // |
---|
| 87 | // fCurCount |
---|
| 88 | // The count of values current added to the vector, which may be |
---|
| 89 | // less than the internal capacity. |
---|
| 90 | // |
---|
| 91 | // fMaxCount |
---|
| 92 | // The current capacity of the vector. |
---|
| 93 | // |
---|
| 94 | // fElemList |
---|
| 95 | // The list of elements, which is dynamically allocated to the needed |
---|
| 96 | // size. |
---|
| 97 | // ----------------------------------------------------------------------- |
---|
| 98 | bool fCallDestructor; |
---|
| 99 | unsigned int fCurCount; |
---|
| 100 | unsigned int fMaxCount; |
---|
| 101 | TElem* fElemList; |
---|
| 102 | MemoryManager* fMemoryManager; |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | // |
---|
| 107 | // An enumerator for a value vector. It derives from the basic enumerator |
---|
| 108 | // class, so that value vectors can be generically enumerated. |
---|
| 109 | // |
---|
| 110 | template <class TElem> class ValueVectorEnumerator : public XMLEnumerator<TElem>, public XMemory |
---|
| 111 | { |
---|
| 112 | public : |
---|
| 113 | // ----------------------------------------------------------------------- |
---|
| 114 | // Constructors and Destructor |
---|
| 115 | // ----------------------------------------------------------------------- |
---|
| 116 | ValueVectorEnumerator |
---|
| 117 | ( |
---|
| 118 | ValueVectorOf<TElem>* const toEnum |
---|
| 119 | , const bool adopt = false |
---|
| 120 | ); |
---|
| 121 | virtual ~ValueVectorEnumerator(); |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | // ----------------------------------------------------------------------- |
---|
| 125 | // Enum interface |
---|
| 126 | // ----------------------------------------------------------------------- |
---|
| 127 | bool hasMoreElements() const; |
---|
| 128 | TElem& nextElement(); |
---|
| 129 | void Reset(); |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | private : |
---|
| 133 | // ----------------------------------------------------------------------- |
---|
| 134 | // Unimplemented constructors and operators |
---|
| 135 | // ----------------------------------------------------------------------- |
---|
| 136 | ValueVectorEnumerator(const ValueVectorEnumerator<TElem>&); |
---|
| 137 | ValueVectorEnumerator<TElem>& operator=(const ValueVectorEnumerator<TElem>&); |
---|
| 138 | |
---|
| 139 | // ----------------------------------------------------------------------- |
---|
| 140 | // Data Members |
---|
| 141 | // |
---|
| 142 | // fAdopted |
---|
| 143 | // Indicates whether we have adopted the passed vector. If so then |
---|
| 144 | // we delete the vector when we are destroyed. |
---|
| 145 | // |
---|
| 146 | // fCurIndex |
---|
| 147 | // This is the current index into the vector. |
---|
| 148 | // |
---|
| 149 | // fToEnum |
---|
| 150 | // The value vector being enumerated. |
---|
| 151 | // ----------------------------------------------------------------------- |
---|
| 152 | bool fAdopted; |
---|
| 153 | unsigned int fCurIndex; |
---|
| 154 | ValueVectorOf<TElem>* fToEnum; |
---|
| 155 | }; |
---|
| 156 | |
---|
| 157 | XERCES_CPP_NAMESPACE_END |
---|
| 158 | |
---|
| 159 | #if !defined(XERCES_TMPLSINC) |
---|
| 160 | #include <xercesc/util/ValueVectorOf.c> |
---|
| 161 | #endif |
---|
| 162 | |
---|
| 163 | #endif |
---|