source: icXML/icXML-devel/src/xercesc/util/RefArrayVectorOf.c @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.1 KB
Line 
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//  Includes
20// ---------------------------------------------------------------------------
21#if defined(XERCES_TMPLSINC)
22#include "RefArrayVectorOf.hpp"
23#endif
24
25XERCES_CPP_NAMESPACE_BEGIN
26
27// ---------------------------------------------------------------------------
28//  RefArrayVectorOf: Constructor and Destructor
29// ---------------------------------------------------------------------------
30template <class TElem>
31RefArrayVectorOf<TElem>::RefArrayVectorOf( const XMLSize_t maxElems
32                                         , const bool adoptElems
33                                         , MemoryManager* const manager)
34    : BaseRefVectorOf<TElem>(maxElems, adoptElems, manager)
35{
36}
37
38
39template <class TElem> RefArrayVectorOf<TElem>::~RefArrayVectorOf()
40{
41    if (this->fAdoptedElems)
42    {
43        for (XMLSize_t index = 0; index < this->fCurCount; index++)
44            this->fMemoryManager->deallocate(this->fElemList[index]);//delete[] fElemList[index];
45    }
46    this->fMemoryManager->deallocate(this->fElemList);//delete [] fElemList;
47}
48
49template <class TElem> void
50RefArrayVectorOf<TElem>::setElementAt(TElem* const toSet, const XMLSize_t setAt)
51{
52    if (setAt >= this->fCurCount)
53        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, this->fMemoryManager);
54
55    if (this->fAdoptedElems)
56        this->fMemoryManager->deallocate(this->fElemList[setAt]);
57
58    this->fElemList[setAt] = toSet;
59}
60
61template <class TElem> void RefArrayVectorOf<TElem>::removeAllElements()
62{
63    for (XMLSize_t index = 0; index < this->fCurCount; index++)
64    {
65        if (this->fAdoptedElems)
66            this->fMemoryManager->deallocate(this->fElemList[index]);
67
68        // Keep unused elements zero for sanity's sake
69        this->fElemList[index] = 0;
70    }
71    this->fCurCount = 0;
72}
73
74template <class TElem> void RefArrayVectorOf<TElem>::
75removeElementAt(const XMLSize_t removeAt)
76{
77    if (removeAt >= this->fCurCount)
78        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, this->fMemoryManager);
79
80    if (this->fAdoptedElems)
81        this->fMemoryManager->deallocate(this->fElemList[removeAt]);
82
83    // Optimize if its the last element
84    if (removeAt == this->fCurCount-1)
85    {
86        this->fElemList[removeAt] = 0;
87        this->fCurCount--;
88        return;
89    }
90
91    // Copy down every element above remove point
92    for (XMLSize_t index = removeAt; index < this->fCurCount-1; index++)
93        this->fElemList[index] = this->fElemList[index+1];
94
95    // Keep unused elements zero for sanity's sake
96    this->fElemList[this->fCurCount-1] = 0;
97
98    // And bump down count
99    this->fCurCount--;
100}
101
102template <class TElem> void RefArrayVectorOf<TElem>::removeLastElement()
103{
104    if (!this->fCurCount)
105        return;
106    this->fCurCount--;
107
108    if (this->fAdoptedElems)
109        this->fMemoryManager->deallocate(this->fElemList[this->fCurCount]);
110}
111
112template <class TElem> void RefArrayVectorOf<TElem>::cleanup()
113{
114    if (this->fAdoptedElems)
115    {
116        for (XMLSize_t index = 0; index < this->fCurCount; index++)
117            this->fMemoryManager->deallocate(this->fElemList[index]);
118    }
119    this->fMemoryManager->deallocate(this->fElemList);//delete [] fElemList;
120}
121
122XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.