Warning, file /include/xercesc/util/ValueVectorOf.c was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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/ValueVectorOf.hpp>
0028 #endif
0029 #include <string.h>
0030
0031 XERCES_CPP_NAMESPACE_BEGIN
0032
0033
0034
0035
0036 template <class TElem>
0037 ValueVectorOf<TElem>::ValueVectorOf(const XMLSize_t maxElems,
0038 MemoryManager* const manager,
0039 const bool toCallDestructor) :
0040
0041 fCallDestructor(toCallDestructor)
0042 , fCurCount(0)
0043 , fMaxCount(maxElems)
0044 , fElemList(0)
0045 , fMemoryManager(manager)
0046 {
0047 fElemList = (TElem*) fMemoryManager->allocate
0048 (
0049 fMaxCount * sizeof(TElem)
0050 );
0051
0052 memset(fElemList, 0, fMaxCount * sizeof(TElem));
0053 }
0054
0055 template <class TElem>
0056 ValueVectorOf<TElem>::ValueVectorOf(const ValueVectorOf<TElem>& toCopy) :
0057 XMemory(toCopy)
0058 , fCallDestructor(toCopy.fCallDestructor)
0059 , fCurCount(toCopy.fCurCount)
0060 , fMaxCount(toCopy.fMaxCount)
0061 , fElemList(0)
0062 , fMemoryManager(toCopy.fMemoryManager)
0063 {
0064 fElemList = (TElem*) fMemoryManager->allocate
0065 (
0066 fMaxCount * sizeof(TElem)
0067 );
0068
0069 memset(fElemList, 0, fMaxCount * sizeof(TElem));
0070 for (XMLSize_t index = 0; index < fCurCount; index++)
0071 fElemList[index] = toCopy.fElemList[index];
0072 }
0073
0074 template <class TElem> ValueVectorOf<TElem>::~ValueVectorOf()
0075 {
0076 if (fCallDestructor) {
0077 for (XMLSize_t index=fMaxCount; index > 0; index--)
0078 fElemList[index-1].~TElem();
0079 }
0080 fMemoryManager->deallocate(fElemList);
0081 }
0082
0083
0084
0085
0086
0087 template <class TElem> ValueVectorOf<TElem>&
0088 ValueVectorOf<TElem>::operator=(const ValueVectorOf<TElem>& toAssign)
0089 {
0090 if (this == &toAssign)
0091 return *this;
0092
0093 if (fCallDestructor) {
0094 for (XMLSize_t index=fMaxCount; index > 0; index--)
0095 fElemList[index-1].~TElem();
0096 }
0097
0098
0099 if (fMaxCount < toAssign.fCurCount)
0100 {
0101 fMemoryManager->deallocate(fElemList);
0102 fElemList = (TElem*) fMemoryManager->allocate
0103 (
0104 toAssign.fMaxCount * sizeof(TElem)
0105 );
0106 fMaxCount = toAssign.fMaxCount;
0107 }
0108
0109 fCurCount = toAssign.fCurCount;
0110 for (XMLSize_t index = 0; index < fCurCount; index++)
0111 fElemList[index] = toAssign.fElemList[index];
0112
0113 return *this;
0114 }
0115
0116
0117
0118
0119
0120 template <class TElem> void ValueVectorOf<TElem>::addElement(const TElem& toAdd)
0121 {
0122 ensureExtraCapacity(1);
0123 fElemList[fCurCount++] = toAdd;
0124 }
0125
0126 template <class TElem> void ValueVectorOf<TElem>::
0127 setElementAt(const TElem& toSet, const XMLSize_t setAt)
0128 {
0129 if (setAt >= fCurCount)
0130 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager);
0131 fElemList[setAt] = toSet;
0132 }
0133
0134 template <class TElem> void ValueVectorOf<TElem>::
0135 insertElementAt(const TElem& toInsert, const XMLSize_t insertAt)
0136 {
0137 if (insertAt == fCurCount)
0138 {
0139 addElement(toInsert);
0140 return;
0141 }
0142
0143 if (insertAt > fCurCount)
0144 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager);
0145
0146
0147 ensureExtraCapacity(1);
0148 for (XMLSize_t index = fCurCount; index > insertAt; index--)
0149 fElemList[index] = fElemList[index-1];
0150
0151
0152 fElemList[insertAt] = toInsert;
0153 fCurCount++;
0154 }
0155
0156 template <class TElem> void ValueVectorOf<TElem>::
0157 removeElementAt(const XMLSize_t removeAt)
0158 {
0159 if (removeAt >= fCurCount)
0160 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager);
0161
0162
0163 for (XMLSize_t index = removeAt; index < fCurCount-1; index++)
0164 fElemList[index] = fElemList[index+1];
0165
0166
0167 fCurCount--;
0168 }
0169
0170 template <class TElem> void ValueVectorOf<TElem>::removeAllElements()
0171 {
0172 fCurCount = 0;
0173 }
0174
0175 template <class TElem>
0176 bool ValueVectorOf<TElem>::containsElement(const TElem& toCheck,
0177 const XMLSize_t startIndex) {
0178
0179 for (XMLSize_t i = startIndex; i < fCurCount; i++) {
0180 if (fElemList[i] == toCheck) {
0181 return true;
0182 }
0183 }
0184
0185 return false;
0186 }
0187
0188
0189
0190
0191
0192 template <class TElem> const TElem& ValueVectorOf<TElem>::
0193 elementAt(const XMLSize_t getAt) const
0194 {
0195 if (getAt >= fCurCount)
0196 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager);
0197 return fElemList[getAt];
0198 }
0199
0200 template <class TElem> TElem& ValueVectorOf<TElem>::
0201 elementAt(const XMLSize_t getAt)
0202 {
0203 if (getAt >= fCurCount)
0204 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager);
0205 return fElemList[getAt];
0206 }
0207
0208 template <class TElem> XMLSize_t ValueVectorOf<TElem>::curCapacity() const
0209 {
0210 return fMaxCount;
0211 }
0212
0213 template <class TElem> XMLSize_t ValueVectorOf<TElem>::size() const
0214 {
0215 return fCurCount;
0216 }
0217
0218 template <class TElem>
0219 MemoryManager* ValueVectorOf<TElem>::getMemoryManager() const
0220 {
0221 return fMemoryManager;
0222 }
0223
0224
0225
0226
0227 template <class TElem> void ValueVectorOf<TElem>::
0228 ensureExtraCapacity(const XMLSize_t length)
0229 {
0230 XMLSize_t newMax = fCurCount + length;
0231
0232 if (newMax > fMaxCount)
0233 {
0234
0235 XMLSize_t minNewMax = (XMLSize_t)((double)fCurCount * 1.25);
0236 if (newMax < minNewMax)
0237 newMax = minNewMax;
0238
0239 TElem* newList = (TElem*) fMemoryManager->allocate
0240 (
0241 newMax * sizeof(TElem)
0242 );
0243 for (XMLSize_t index = 0; index < fCurCount; index++)
0244 newList[index] = fElemList[index];
0245
0246 fMemoryManager->deallocate(fElemList);
0247 fElemList = newList;
0248 fMaxCount = newMax;
0249 }
0250 }
0251
0252 template <class TElem> const TElem* ValueVectorOf<TElem>::rawData() const
0253 {
0254 return fElemList;
0255 }
0256
0257
0258
0259
0260
0261
0262 template <class TElem> ValueVectorEnumerator<TElem>::
0263 ValueVectorEnumerator( ValueVectorOf<TElem>* const toEnum
0264 , const bool adopt) :
0265 fAdopted(adopt)
0266 , fCurIndex(0)
0267 , fToEnum(toEnum)
0268 {
0269 }
0270
0271 template <class TElem> ValueVectorEnumerator<TElem>::~ValueVectorEnumerator()
0272 {
0273 if (fAdopted)
0274 delete fToEnum;
0275 }
0276
0277
0278
0279
0280
0281 template <class TElem> bool
0282 ValueVectorEnumerator<TElem>::hasMoreElements() const
0283 {
0284 if (fCurIndex >= fToEnum->size())
0285 return false;
0286 return true;
0287 }
0288
0289 template <class TElem> TElem& ValueVectorEnumerator<TElem>::nextElement()
0290 {
0291 return fToEnum->elementAt(fCurIndex++);
0292 }
0293
0294 template <class TElem> void ValueVectorEnumerator<TElem>::Reset()
0295 {
0296 fCurIndex = 0;
0297 }
0298
0299 XERCES_CPP_NAMESPACE_END