File indexing completed on 2025-01-18 10:15:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #if defined(XERCES_TMPLSINC)
0027 #include <xercesc/util/ValueArrayOf.hpp>
0028 #endif
0029
0030
0031 XERCES_CPP_NAMESPACE_BEGIN
0032
0033
0034
0035
0036 template <class TElem>
0037 ValueArrayOf<TElem>::ValueArrayOf(const XMLSize_t size,
0038 MemoryManager* const manager) :
0039
0040 fSize(size)
0041 , fArray(0)
0042 , fMemoryManager(manager)
0043 {
0044 fArray = (TElem*) fMemoryManager->allocate(fSize * sizeof(TElem));
0045 }
0046
0047 template <class TElem>
0048 ValueArrayOf<TElem>::ValueArrayOf( const TElem* values
0049 , const XMLSize_t size
0050 , MemoryManager* const manager) :
0051
0052 fSize(size)
0053 , fArray(0)
0054 , fMemoryManager(manager)
0055 {
0056 fArray = (TElem*) fMemoryManager->allocate(fSize * sizeof(TElem));
0057 for (XMLSize_t index = 0; index < fSize; index++)
0058 fArray[index] = values[index];
0059 }
0060
0061 template <class TElem>
0062 ValueArrayOf<TElem>::ValueArrayOf(const ValueArrayOf<TElem>& source) :
0063 XMemory(source)
0064 , fSize(source.fSize)
0065 , fArray(0)
0066 , fMemoryManager(source.fMemoryManager)
0067 {
0068 fArray = (TElem*) fMemoryManager->allocate(fSize * sizeof(TElem));
0069 for (XMLSize_t index = 0; index < fSize; index++)
0070 fArray[index] = source.fArray[index];
0071 }
0072
0073 template <class TElem> ValueArrayOf<TElem>::~ValueArrayOf()
0074 {
0075 fMemoryManager->deallocate(fArray);
0076 }
0077
0078
0079
0080
0081
0082 template <class TElem> TElem& ValueArrayOf<TElem>::
0083 operator[](const XMLSize_t index)
0084 {
0085 if (index >= fSize)
0086 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0087 return fArray[index];
0088 }
0089
0090 template <class TElem> const TElem& ValueArrayOf<TElem>::
0091 operator[](const XMLSize_t index) const
0092 {
0093 if (index >= fSize)
0094 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0095 return fArray[index];
0096 }
0097
0098 template <class TElem> ValueArrayOf<TElem>& ValueArrayOf<TElem>::
0099 operator=(const ValueArrayOf<TElem>& toAssign)
0100 {
0101 if (this == &toAssign)
0102 return *this;
0103
0104
0105 if (toAssign.fSize != fSize)
0106 {
0107 fMemoryManager->deallocate(fArray);
0108 fSize = toAssign.fSize;
0109 fArray = (TElem*) fMemoryManager->allocate(fSize * sizeof(TElem));
0110 }
0111
0112
0113 for (XMLSize_t index = 0; index < fSize; index++)
0114 fArray[index] = toAssign.fArray[index];
0115
0116 return *this;
0117 }
0118
0119 template <class TElem> bool ValueArrayOf<TElem>::
0120 operator==(const ValueArrayOf<TElem>& toCompare) const
0121 {
0122 if (this == &toCompare)
0123 return true;
0124
0125 if (fSize != toCompare.fSize)
0126 return false;
0127
0128 for (XMLSize_t index = 0; index < fSize; index++)
0129 {
0130 if (fArray[index] != toCompare.fArray[index])
0131 return false;
0132 }
0133
0134 return true;
0135 }
0136
0137 template <class TElem> bool ValueArrayOf<TElem>::
0138 operator!=(const ValueArrayOf<TElem>& toCompare) const
0139 {
0140 return !operator==(toCompare);
0141 }
0142
0143
0144
0145
0146
0147 template <class TElem> XMLSize_t ValueArrayOf<TElem>::
0148 copyFrom(const ValueArrayOf<TElem>& srcArray)
0149 {
0150
0151
0152
0153
0154 const XMLSize_t count = fSize < srcArray.fSize ?
0155 fSize : srcArray.fSize;
0156
0157 for (XMLSize_t index = 0; index < count; index++)
0158 fArray[index] = srcArray.fArray[index];
0159
0160 return count;
0161 }
0162
0163
0164
0165
0166
0167 template <class TElem> XMLSize_t ValueArrayOf<TElem>::
0168 length() const
0169 {
0170 return fSize;
0171 }
0172
0173 template <class TElem> TElem* ValueArrayOf<TElem>::
0174 rawData() const
0175 {
0176 return fArray;
0177 }
0178
0179
0180
0181
0182
0183 template <class TElem> void ValueArrayOf<TElem>::
0184 resize(const XMLSize_t newSize)
0185 {
0186 if (newSize == fSize)
0187 return;
0188
0189 if (newSize < fSize)
0190 ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Array_BadNewSize, fMemoryManager);
0191
0192
0193 TElem* newArray = (TElem*) fMemoryManager->allocate
0194 (
0195 newSize * sizeof(TElem)
0196 );
0197
0198
0199 XMLSize_t index = 0;
0200 for (; index < fSize; index++)
0201 newArray[index] = fArray[index];
0202
0203 for (; index < newSize; index++)
0204 newArray[index] = TElem(0);
0205
0206
0207 fMemoryManager->deallocate(fArray);
0208 fArray = newArray;
0209 fSize = newSize;
0210 }
0211
0212
0213
0214
0215
0216
0217 template <class TElem> ValueArrayEnumerator<TElem>::
0218 ValueArrayEnumerator(ValueArrayOf<TElem>* const toEnum, const bool adopt) :
0219 fAdopted(adopt)
0220 , fCurIndex(0)
0221 , fToEnum(toEnum)
0222 {
0223 }
0224
0225 template <class TElem> ValueArrayEnumerator<TElem>::~ValueArrayEnumerator()
0226 {
0227 if (fAdopted)
0228 delete fToEnum;
0229 }
0230
0231
0232
0233
0234
0235 template <class TElem> bool ValueArrayEnumerator<TElem>::hasMoreElements() const
0236 {
0237 if (fCurIndex >= fToEnum->length())
0238 return false;
0239 return true;
0240 }
0241
0242 template <class TElem> TElem& ValueArrayEnumerator<TElem>::nextElement()
0243 {
0244 return (*fToEnum)[fCurIndex++];
0245 }
0246
0247 template <class TElem> void ValueArrayEnumerator<TElem>::Reset()
0248 {
0249 fCurIndex = 0;
0250 }
0251
0252 XERCES_CPP_NAMESPACE_END