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