Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:25

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 //  Includes
0020 // ---------------------------------------------------------------------------
0021 #if defined(XERCES_TMPLSINC)
0022 #include "RefArrayVectorOf.hpp"
0023 #endif
0024 
0025 XERCES_CPP_NAMESPACE_BEGIN
0026 
0027 // ---------------------------------------------------------------------------
0028 //  RefArrayVectorOf: Constructor and Destructor
0029 // ---------------------------------------------------------------------------
0030 template <class TElem>
0031 RefArrayVectorOf<TElem>::RefArrayVectorOf( const XMLSize_t maxElems
0032                                          , const bool adoptElems
0033                                          , MemoryManager* const manager)
0034     : BaseRefVectorOf<TElem>(maxElems, adoptElems, manager)
0035 {
0036 }
0037 
0038 
0039 template <class TElem> RefArrayVectorOf<TElem>::~RefArrayVectorOf()
0040 {
0041     if (this->fAdoptedElems)
0042     {
0043         for (XMLSize_t index = 0; index < this->fCurCount; index++)
0044             this->fMemoryManager->deallocate(this->fElemList[index]);//delete[] fElemList[index];
0045     }
0046     this->fMemoryManager->deallocate(this->fElemList);//delete [] fElemList;
0047 }
0048 
0049 template <class TElem> void
0050 RefArrayVectorOf<TElem>::setElementAt(TElem* const toSet, const XMLSize_t setAt)
0051 {
0052     if (setAt >= this->fCurCount)
0053         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, this->fMemoryManager);
0054 
0055     if (this->fAdoptedElems)
0056         this->fMemoryManager->deallocate(this->fElemList[setAt]);
0057 
0058     this->fElemList[setAt] = toSet;
0059 }
0060 
0061 template <class TElem> void RefArrayVectorOf<TElem>::removeAllElements()
0062 {
0063     for (XMLSize_t index = 0; index < this->fCurCount; index++)
0064     {
0065         if (this->fAdoptedElems)
0066             this->fMemoryManager->deallocate(this->fElemList[index]);
0067 
0068         // Keep unused elements zero for sanity's sake
0069         this->fElemList[index] = 0;
0070     }
0071     this->fCurCount = 0;
0072 }
0073 
0074 template <class TElem> void RefArrayVectorOf<TElem>::
0075 removeElementAt(const XMLSize_t removeAt)
0076 {
0077     if (removeAt >= this->fCurCount)
0078         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, this->fMemoryManager);
0079 
0080     if (this->fAdoptedElems)
0081         this->fMemoryManager->deallocate(this->fElemList[removeAt]);
0082 
0083     // Optimize if its the last element
0084     if (removeAt == this->fCurCount-1)
0085     {
0086         this->fElemList[removeAt] = 0;
0087         this->fCurCount--;
0088         return;
0089     }
0090 
0091     // Copy down every element above remove point
0092     for (XMLSize_t index = removeAt; index < this->fCurCount-1; index++)
0093         this->fElemList[index] = this->fElemList[index+1];
0094 
0095     // Keep unused elements zero for sanity's sake
0096     this->fElemList[this->fCurCount-1] = 0;
0097 
0098     // And bump down count
0099     this->fCurCount--;
0100 }
0101 
0102 template <class TElem> void RefArrayVectorOf<TElem>::removeLastElement()
0103 {
0104     if (!this->fCurCount)
0105         return;
0106     this->fCurCount--;
0107 
0108     if (this->fAdoptedElems)
0109         this->fMemoryManager->deallocate(this->fElemList[this->fCurCount]);
0110 }
0111 
0112 template <class TElem> void RefArrayVectorOf<TElem>::cleanup()
0113 {
0114     if (this->fAdoptedElems)
0115     {
0116         for (XMLSize_t index = 0; index < this->fCurCount; index++)
0117             this->fMemoryManager->deallocate(this->fElemList[index]);
0118     }
0119     this->fMemoryManager->deallocate(this->fElemList);//delete [] fElemList;
0120 }
0121 
0122 XERCES_CPP_NAMESPACE_END