source: icXML/icXML-devel/src/xercesc/util/RefStackOf.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.9 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 * $Id: RefStackOf.c 676911 2008-07-15 13:27:32Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#if defined(XERCES_TMPLSINC)
27#include <xercesc/util/RefStackOf.hpp>
28#endif
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32// ---------------------------------------------------------------------------
33//  RefStackOf: Constructors and Destructor
34// ---------------------------------------------------------------------------
35template <class TElem>
36RefStackOf<TElem>::RefStackOf(const XMLSize_t initElems,
37                              const bool adoptElems,
38                              MemoryManager* const manager) :
39
40    fVector(initElems, adoptElems, manager)
41{
42}
43
44template <class TElem> RefStackOf<TElem>::~RefStackOf()
45{
46}
47
48
49// ---------------------------------------------------------------------------
50//  RefStackOf: Element management methods
51// ---------------------------------------------------------------------------
52template <class TElem> const TElem* RefStackOf<TElem>::
53elementAt(const XMLSize_t index) const
54{
55    if (index >= fVector.size())
56        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager());
57    return fVector.elementAt(index);
58}
59
60template <class TElem> TElem* RefStackOf<TElem>::popAt(const XMLSize_t index)
61{
62    if (index >= fVector.size())
63        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager());
64
65    // Orphan off the element from the slot in the vector
66    return fVector.orphanElementAt(index);
67}
68
69template <class TElem> void RefStackOf<TElem>::push(TElem* const toPush)
70{
71    fVector.addElement(toPush);
72}
73
74template <class TElem> const TElem* RefStackOf<TElem>::peek() const
75{
76    const XMLSize_t curSize = fVector.size();
77    if (curSize == 0)
78        ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
79
80    return fVector.elementAt(curSize-1);
81}
82
83template <class TElem> TElem* RefStackOf<TElem>::pop()
84{
85    const XMLSize_t curSize = fVector.size();
86    if (curSize == 0)
87        ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
88
89    // Orphan off the element from the last slot in the vector
90    return fVector.orphanElementAt(curSize-1);
91}
92
93template <class TElem> void RefStackOf<TElem>::removeAllElements()
94{
95    fVector.removeAllElements();
96}
97
98
99// ---------------------------------------------------------------------------
100//  RefStackOf: Getter methods
101// ---------------------------------------------------------------------------
102template <class TElem> bool RefStackOf<TElem>::empty()
103{
104    return (fVector.size() == 0);
105}
106
107template <class TElem> XMLSize_t RefStackOf<TElem>::curCapacity()
108{
109    return fVector.curCapacity();
110}
111
112template <class TElem> XMLSize_t RefStackOf<TElem>::size()
113{
114    return fVector.size();
115}
116
117
118
119
120// ---------------------------------------------------------------------------
121//  RefStackEnumerator: Constructors and Destructor
122// ---------------------------------------------------------------------------
123template <class TElem> RefStackEnumerator<TElem>::
124RefStackEnumerator(         RefStackOf<TElem>* const    toEnum
125                    , const bool                        adopt) :
126    fAdopted(adopt)
127    , fCurIndex(0)
128    , fToEnum(toEnum)
129    , fVector(&toEnum->fVector)
130{
131}
132
133template <class TElem> RefStackEnumerator<TElem>::~RefStackEnumerator()
134{
135    if (fAdopted)
136        delete fToEnum;
137}
138
139
140// ---------------------------------------------------------------------------
141//  RefStackEnumerator: Enum interface
142// ---------------------------------------------------------------------------
143template <class TElem> bool RefStackEnumerator<TElem>::hasMoreElements() const
144{
145    if (fCurIndex >= fVector->size())
146        return false;
147    return true;
148}
149
150template <class TElem> TElem& RefStackEnumerator<TElem>::nextElement()
151{
152    return *fVector->elementAt(fCurIndex++);
153}
154
155template <class TElem> void RefStackEnumerator<TElem>::Reset()
156{
157    fCurIndex = 0;
158}
159
160XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.