[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: ValueArrayOf.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #if !defined(VALUEARRAY_HPP) |
---|
| 24 | #define VALUEARRAY_HPP |
---|
| 25 | |
---|
| 26 | #include <xercesc/util/XMLEnumerator.hpp> |
---|
| 27 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> |
---|
| 28 | #include <xercesc/util/IllegalArgumentException.hpp> |
---|
| 29 | #include <xercesc/util/PlatformUtils.hpp> |
---|
| 30 | #include <xercesc/framework/MemoryManager.hpp> |
---|
| 31 | |
---|
| 32 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 33 | |
---|
| 34 | template <class TElem> class ValueArrayOf : public XMemory |
---|
| 35 | { |
---|
| 36 | public : |
---|
| 37 | // ----------------------------------------------------------------------- |
---|
| 38 | // Contructors and Destructor |
---|
| 39 | // ----------------------------------------------------------------------- |
---|
| 40 | ValueArrayOf |
---|
| 41 | ( |
---|
| 42 | const unsigned int size |
---|
| 43 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 44 | ); |
---|
| 45 | ValueArrayOf |
---|
| 46 | ( |
---|
| 47 | const TElem* values |
---|
| 48 | , const unsigned int size |
---|
| 49 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 50 | ); |
---|
| 51 | ValueArrayOf(const ValueArrayOf<TElem>& source); |
---|
| 52 | ~ValueArrayOf(); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | // ----------------------------------------------------------------------- |
---|
| 56 | // Public operators |
---|
| 57 | // ----------------------------------------------------------------------- |
---|
| 58 | TElem& operator[](const unsigned int index); |
---|
| 59 | const TElem& operator[](const unsigned int index) const; |
---|
| 60 | ValueArrayOf<TElem>& operator=(const ValueArrayOf<TElem>& toAssign); |
---|
| 61 | bool operator==(const ValueArrayOf<TElem>& toCompare) const; |
---|
| 62 | bool operator!=(const ValueArrayOf<TElem>& toCompare) const; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | // ----------------------------------------------------------------------- |
---|
| 66 | // Copy operations |
---|
| 67 | // ----------------------------------------------------------------------- |
---|
| 68 | unsigned int copyFrom(const ValueArrayOf<TElem>& srcArray); |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | // ----------------------------------------------------------------------- |
---|
| 72 | // Getter methods |
---|
| 73 | // ----------------------------------------------------------------------- |
---|
| 74 | unsigned int length() const; |
---|
| 75 | TElem* rawData() const; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | // ----------------------------------------------------------------------- |
---|
| 79 | // Miscellaneous methods |
---|
| 80 | // ----------------------------------------------------------------------- |
---|
| 81 | void resize(const unsigned int newSize); |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | private : |
---|
| 85 | // ----------------------------------------------------------------------- |
---|
| 86 | // Data members |
---|
| 87 | // ----------------------------------------------------------------------- |
---|
| 88 | unsigned int fSize; |
---|
| 89 | TElem* fArray; |
---|
| 90 | MemoryManager* fMemoryManager; |
---|
| 91 | }; |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | // |
---|
| 95 | // An enumerator for a value array. It derives from the basic enumerator |
---|
| 96 | // class, so that value vectors can be generically enumerated. |
---|
| 97 | // |
---|
| 98 | template <class TElem> class ValueArrayEnumerator : public XMLEnumerator<TElem>, public XMemory |
---|
| 99 | { |
---|
| 100 | public : |
---|
| 101 | // ----------------------------------------------------------------------- |
---|
| 102 | // Constructors and Destructor |
---|
| 103 | // ----------------------------------------------------------------------- |
---|
| 104 | ValueArrayEnumerator |
---|
| 105 | ( |
---|
| 106 | ValueArrayOf<TElem>* const toEnum |
---|
| 107 | , const bool adopt = false |
---|
| 108 | ); |
---|
| 109 | virtual ~ValueArrayEnumerator(); |
---|
| 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 | ValueArrayEnumerator(const ValueArrayEnumerator<TElem>&); |
---|
| 125 | ValueArrayEnumerator<TElem>& operator=(const ValueArrayEnumerator<TElem>&); |
---|
| 126 | |
---|
| 127 | // ----------------------------------------------------------------------- |
---|
| 128 | // Data Members |
---|
| 129 | // |
---|
| 130 | // fAdopted |
---|
| 131 | // Indicates whether we have adopted the passed vector. If so then |
---|
| 132 | // we delete the vector when we are destroyed. |
---|
| 133 | // |
---|
| 134 | // fCurIndex |
---|
| 135 | // This is the current index into the vector. |
---|
| 136 | // |
---|
| 137 | // fToEnum |
---|
| 138 | // The value array being enumerated. |
---|
| 139 | // ----------------------------------------------------------------------- |
---|
| 140 | bool fAdopted; |
---|
| 141 | unsigned int fCurIndex; |
---|
| 142 | ValueArrayOf<TElem>* fToEnum; |
---|
| 143 | }; |
---|
| 144 | |
---|
| 145 | XERCES_CPP_NAMESPACE_END |
---|
| 146 | |
---|
| 147 | #if !defined(XERCES_TMPLSINC) |
---|
| 148 | #include <xercesc/util/ValueArrayOf.c> |
---|
| 149 | #endif |
---|
| 150 | |
---|
| 151 | #endif |
---|