Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:12

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 
0023 // ---------------------------------------------------------------------------
0024 //  Includes
0025 // ---------------------------------------------------------------------------
0026 #if defined(XERCES_TMPLSINC)
0027 #include <xercesc/util/RefArrayOf.hpp>
0028 #endif
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 // ---------------------------------------------------------------------------
0033 //  RefArrayOf: Constructors and Destructor
0034 // ---------------------------------------------------------------------------
0035 template <class TElem>
0036 RefArrayOf<TElem>::RefArrayOf(const XMLSize_t size,
0037                               MemoryManager* const manager) :
0038 
0039     fSize(size)
0040     , fArray(0)
0041     , fMemoryManager(manager)
0042 {
0043     fArray = (TElem**) fMemoryManager->allocate(fSize * sizeof(TElem*));//new TElem*[fSize];
0044     for (XMLSize_t index = 0; index < fSize; index++)
0045         fArray[index] = 0;
0046 }
0047 
0048 template <class TElem>
0049 RefArrayOf<TElem>::RefArrayOf(TElem* values[],
0050                               const XMLSize_t size,
0051                               MemoryManager* const manager) :
0052 
0053     fSize(size)
0054     , fArray(0)
0055     , fMemoryManager(manager)
0056 {
0057     fArray = (TElem**) fMemoryManager->allocate(fSize * sizeof(TElem*));//new TElem*[fSize];
0058     for (XMLSize_t index = 0; index < fSize; index++)
0059         fArray[index] = values[index];
0060 }
0061 
0062 template <class TElem> RefArrayOf<TElem>::
0063 RefArrayOf(const RefArrayOf<TElem>& source) :
0064 
0065     fSize(source.fSize)
0066     , fArray(0)
0067     , fMemoryManager(source.fMemoryManager)
0068 {
0069     fArray = (TElem**) fMemoryManager->allocate(fSize * sizeof(TElem*));//new TElem*[fSize];
0070     for (XMLSize_t index = 0; index < fSize; index++)
0071         fArray[index] = source.fArray[index];
0072 }
0073 
0074 template <class TElem> RefArrayOf<TElem>::~RefArrayOf()
0075 {
0076     fMemoryManager->deallocate(fArray);//delete [] fArray;
0077 }
0078 
0079 
0080 // ---------------------------------------------------------------------------
0081 //  RefArrayOf: Public operators
0082 // ---------------------------------------------------------------------------
0083 template <class TElem> TElem*& RefArrayOf<TElem>::
0084 operator[](const XMLSize_t index)
0085 {
0086     if (index >= fSize)
0087         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0088     return fArray[index];
0089 }
0090 
0091 template <class TElem> const TElem* RefArrayOf<TElem>::
0092 operator[](const XMLSize_t index) const
0093 {
0094     if (index >= fSize)
0095         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0096     return fArray[index];
0097 }
0098 
0099 template <class TElem> RefArrayOf<TElem>& RefArrayOf<TElem>::
0100 operator=(const RefArrayOf<TElem>& toAssign)
0101 {
0102     if (this == &toAssign)
0103         return *this;
0104 
0105     // Reallocate if not the same size
0106     if (toAssign.fSize != fSize)
0107     {
0108         fMemoryManager->deallocate(fArray);//delete [] fArray;
0109         fSize = toAssign.fSize;
0110         fArray = (TElem**) fMemoryManager->allocate(fSize * sizeof(TElem*));//new TElem*[fSize];
0111     }
0112 
0113     // Copy over the source elements
0114     for (XMLSize_t index = 0; index < fSize; index++)
0115         fArray[index] = toAssign.fArray[index];
0116 
0117     return *this;
0118 }
0119 
0120 template <class TElem> bool RefArrayOf<TElem>::
0121 operator==(const RefArrayOf<TElem>& toCompare) const
0122 {
0123     if (this == &toCompare)
0124         return true;
0125 
0126     if (fSize != toCompare.fSize)
0127         return false;
0128 
0129     for (XMLSize_t index = 0; index < fSize; index++)
0130     {
0131         if (fArray[index] != toCompare.fArray[index])
0132             return false;
0133     }
0134     return true;
0135 }
0136 
0137 template <class TElem> bool RefArrayOf<TElem>::
0138 operator!=(const RefArrayOf<TElem>& toCompare) const
0139 {
0140     return !operator==(toCompare);
0141 }
0142 
0143 
0144 // ---------------------------------------------------------------------------
0145 //  RefArrayOf: Copy operations
0146 // ---------------------------------------------------------------------------
0147 template <class TElem> XMLSize_t RefArrayOf<TElem>::
0148 copyFrom(const RefArrayOf<TElem>& srcArray)
0149 {
0150     //
0151     //  Copy over as many of the source elements as will fit into
0152     //  this array.
0153     //
0154     const XMLSize_t count = fSize < srcArray.fSize ?
0155                                     fSize : srcArray.fSize;
0156 
0157     for (XMLSize_t index = 0; index < fSize; index++)
0158         fArray[index] = srcArray.fArray[index];
0159 
0160     return count;
0161 }
0162 
0163 
0164 // ---------------------------------------------------------------------------
0165 //  RefArrayOf: Getter methods
0166 // ---------------------------------------------------------------------------
0167 template <class TElem> XMLSize_t RefArrayOf<TElem>::length() const
0168 {
0169     return fSize;
0170 }
0171 
0172 template <class TElem> TElem** RefArrayOf<TElem>::rawData() const
0173 {
0174     return fArray;
0175 }
0176 
0177 
0178 // ---------------------------------------------------------------------------
0179 //  RefArrayOf: Element management methods
0180 // ---------------------------------------------------------------------------
0181 template <class TElem> void RefArrayOf<TElem>::deleteAt(const XMLSize_t index)
0182 {
0183     if (index >= fSize)
0184         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0185 
0186     delete fArray[index];
0187     fArray[index] = 0;
0188 }
0189 
0190 template <class TElem> void RefArrayOf<TElem>::deleteAllElements()
0191 {
0192     for (XMLSize_t index = 0; index < fSize; index++)
0193     {
0194         delete fArray[index];
0195         fArray[index] = 0;
0196     }
0197 }
0198 
0199 template <class TElem> void RefArrayOf<TElem>::resize(const XMLSize_t newSize)
0200 {
0201     if (newSize == fSize)
0202         return;
0203 
0204     if (newSize < fSize)
0205         ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Array_BadNewSize, fMemoryManager);
0206 
0207     // Allocate the new array
0208     TElem** newArray = (TElem**) fMemoryManager->allocate
0209     (
0210         newSize * sizeof(TElem*)
0211     );//new TElem*[newSize];
0212 
0213     // Copy the existing values
0214     XMLSize_t index = 0;
0215     for (; index < fSize; index++)
0216         newArray[index] = fArray[index];
0217 
0218     for (; index < newSize; index++)
0219         newArray[index] = 0;
0220 
0221     // Delete the old array and update our members
0222     fMemoryManager->deallocate(fArray);//delete [] fArray;
0223     fArray = newArray;
0224     fSize = newSize;
0225 }
0226 
0227 
0228 
0229 
0230 // ---------------------------------------------------------------------------
0231 //  RefArrayEnumerator: Constructors and Destructor
0232 // ---------------------------------------------------------------------------
0233 template <class TElem> RefArrayEnumerator<TElem>::
0234 RefArrayEnumerator(         RefArrayOf<TElem>* const    toEnum
0235                     , const bool                        adopt) :
0236     fAdopted(adopt)
0237     , fCurIndex(0)
0238     , fToEnum(toEnum)
0239 {
0240 }
0241 
0242 template <class TElem> RefArrayEnumerator<TElem>::~RefArrayEnumerator()
0243 {
0244     if (fAdopted)
0245         delete fToEnum;
0246 }
0247 
0248 
0249 // ---------------------------------------------------------------------------
0250 //  RefArrayEnumerator: Enum interface
0251 // ---------------------------------------------------------------------------
0252 template <class TElem> bool RefArrayEnumerator<TElem>::hasMoreElements() const
0253 {
0254     if (fCurIndex >= fToEnum->length())
0255         return false;
0256     return true;
0257 }
0258 
0259 template <class TElem> TElem& RefArrayEnumerator<TElem>::nextElement()
0260 {
0261     return *(*fToEnum)[fCurIndex++];
0262 }
0263 
0264 template <class TElem> void RefArrayEnumerator<TElem>::Reset()
0265 {
0266     fCurIndex = 0;
0267 }
0268 
0269 XERCES_CPP_NAMESPACE_END