source: NonGTP/Xerces/xerces/include/xercesc/util/RefArrayVectorOf.c @ 358

Revision 358, 4.0 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// ---------------------------------------------------------------------------
18//  Includes
19// ---------------------------------------------------------------------------
20#if defined(XERCES_TMPLSINC)
21#include "RefArrayVectorOf.hpp"
22#endif
23
24XERCES_CPP_NAMESPACE_BEGIN
25
26// ---------------------------------------------------------------------------
27//  RefArrayVectorOf: Constructor and Destructor
28// ---------------------------------------------------------------------------
29template <class TElem>
30RefArrayVectorOf<TElem>::RefArrayVectorOf( const unsigned int maxElems
31                                         , const bool adoptElems
32                                         , MemoryManager* const manager)
33    : BaseRefVectorOf<TElem>(maxElems, adoptElems, manager)
34{
35}
36
37
38template <class TElem> RefArrayVectorOf<TElem>::~RefArrayVectorOf()
39{
40    if (this->fAdoptedElems)
41    {
42      for (unsigned int index = 0; index < this->fCurCount; index++)
43            this->fMemoryManager->deallocate(this->fElemList[index]);//delete[] fElemList[index];
44    }
45    this->fMemoryManager->deallocate(this->fElemList);//delete [] fElemList;
46}
47
48template <class TElem> void
49RefArrayVectorOf<TElem>::setElementAt(TElem* const toSet, const unsigned int setAt)
50{
51    if (setAt >= this->fCurCount)
52        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, this->fMemoryManager);
53
54    if (this->fAdoptedElems)
55        this->fMemoryManager->deallocate(this->fElemList[setAt]);
56
57    this->fElemList[setAt] = toSet;
58}
59
60template <class TElem> void RefArrayVectorOf<TElem>::removeAllElements()
61{
62    for (unsigned int index = 0; index < this->fCurCount; index++)
63    {
64        if (this->fAdoptedElems)
65          this->fMemoryManager->deallocate(this->fElemList[index]);
66
67        // Keep unused elements zero for sanity's sake
68        this->fElemList[index] = 0;
69    }
70    this->fCurCount = 0;
71}
72
73template <class TElem> void RefArrayVectorOf<TElem>::
74removeElementAt(const unsigned int removeAt)
75{
76    if (removeAt >= this->fCurCount)
77        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, this->fMemoryManager);
78
79    if (this->fAdoptedElems)
80        this->fMemoryManager->deallocate(this->fElemList[removeAt]);
81
82    // Optimize if its the last element
83    if (removeAt == this->fCurCount-1)
84    {
85        this->fElemList[removeAt] = 0;
86        this->fCurCount--;
87        return;
88    }
89
90    // Copy down every element above remove point
91    for (unsigned int index = removeAt; index < this->fCurCount-1; index++)
92        this->fElemList[index] = this->fElemList[index+1];
93
94    // Keep unused elements zero for sanity's sake
95    this->fElemList[this->fCurCount-1] = 0;
96
97    // And bump down count
98    this->fCurCount--;
99}
100
101template <class TElem> void RefArrayVectorOf<TElem>::removeLastElement()
102{
103    if (!this->fCurCount)
104        return;
105    this->fCurCount--;
106
107    if (this->fAdoptedElems)
108        this->fMemoryManager->deallocate(this->fElemList[this->fCurCount]);
109}
110
111template <class TElem> void RefArrayVectorOf<TElem>::cleanup()
112{
113    if (this->fAdoptedElems)
114    {
115        for (unsigned int index = 0; index < this->fCurCount; index++)
116            this->fMemoryManager->deallocate(this->fElemList[index]);
117    }
118    this->fMemoryManager->deallocate(this->fElemList);//delete [] fElemList;
119}
120
121XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.