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

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

xerces added

Line 
1/*
2 * Copyright 1999-2000,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 * $Log: RefStackOf.c,v $
19 * Revision 1.5  2004/09/08 13:56:23  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.4  2003/12/17 00:18:35  cargilld
23 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
24 *
25 * Revision 1.3  2003/05/16 06:01:52  knoaman
26 * Partial implementation of the configurable memory manager.
27 *
28 * Revision 1.2  2002/11/04 15:22:04  tng
29 * C++ Namespace Support.
30 *
31 * Revision 1.1.1.1  2002/02/01 22:22:12  peiyongz
32 * sane_include
33 *
34 * Revision 1.3  2000/03/02 19:54:44  roddey
35 * This checkin includes many changes done while waiting for the
36 * 1.1.0 code to be finished. I can't list them all here, but a list is
37 * available elsewhere.
38 *
39 * Revision 1.2  2000/02/06 07:48:03  rahulj
40 * Year 2K copyright swat.
41 *
42 * Revision 1.1.1.1  1999/11/09 01:05:02  twl
43 * Initial checkin
44 *
45 * Revision 1.2  1999/11/08 20:45:13  rahul
46 * Swat for adding in Product name and CVS comment log variable.
47 *
48 */
49
50
51// ---------------------------------------------------------------------------
52//  Includes
53// ---------------------------------------------------------------------------
54#if defined(XERCES_TMPLSINC)
55#include <xercesc/util/RefStackOf.hpp>
56#endif
57
58XERCES_CPP_NAMESPACE_BEGIN
59
60// ---------------------------------------------------------------------------
61//  RefStackOf: Constructors and Destructor
62// ---------------------------------------------------------------------------
63template <class TElem>
64RefStackOf<TElem>::RefStackOf(const unsigned int initElems,
65                              const bool adoptElems,
66                              MemoryManager* const manager) :
67
68    fVector(initElems, adoptElems, manager)
69{
70}
71
72template <class TElem> RefStackOf<TElem>::~RefStackOf()
73{
74}
75
76
77// ---------------------------------------------------------------------------
78//  RefStackOf: Element management methods
79// ---------------------------------------------------------------------------
80template <class TElem> const TElem* RefStackOf<TElem>::
81elementAt(const unsigned int index) const
82{
83    if (index > fVector.size())
84        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager());
85    return fVector.elementAt(index);
86}
87
88template <class TElem> void RefStackOf<TElem>::push(TElem* const toPush)
89{
90    fVector.addElement(toPush);
91}
92
93template <class TElem> const TElem* RefStackOf<TElem>::peek() const
94{
95    const int curSize = fVector.size();
96    if (curSize == 0)
97        ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
98
99    return fVector.elementAt(curSize-1);
100}
101
102template <class TElem> TElem* RefStackOf<TElem>::pop()
103{
104    const int curSize = fVector.size();
105    if (curSize == 0)
106        ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
107
108    // Orphan off the element from the last slot in the vector
109    return fVector.orphanElementAt(curSize-1);
110}
111
112template <class TElem> void RefStackOf<TElem>::removeAllElements()
113{
114    fVector.removeAllElements();
115}
116
117
118// ---------------------------------------------------------------------------
119//  RefStackOf: Getter methods
120// ---------------------------------------------------------------------------
121template <class TElem> bool RefStackOf<TElem>::empty()
122{
123    return (fVector.size() == 0);
124}
125
126template <class TElem> unsigned int RefStackOf<TElem>::curCapacity()
127{
128    return fVector.curCapacity();
129}
130
131template <class TElem> unsigned int RefStackOf<TElem>::size()
132{
133    return fVector.size();
134}
135
136
137
138
139// ---------------------------------------------------------------------------
140//  RefStackEnumerator: Constructors and Destructor
141// ---------------------------------------------------------------------------
142template <class TElem> RefStackEnumerator<TElem>::
143RefStackEnumerator(         RefStackOf<TElem>* const    toEnum
144                    , const bool                        adopt) :
145    fAdopted(adopt)
146    , fCurIndex(0)
147    , fToEnum(toEnum)
148    , fVector(&toEnum->fVector)
149{
150}
151
152template <class TElem> RefStackEnumerator<TElem>::~RefStackEnumerator()
153{
154    if (fAdopted)
155        delete fToEnum;
156}
157
158
159// ---------------------------------------------------------------------------
160//  RefStackEnumerator: Enum interface
161// ---------------------------------------------------------------------------
162template <class TElem> bool RefStackEnumerator<TElem>::hasMoreElements() const
163{
164    if (fCurIndex >= fVector->size())
165        return false;
166    return true;
167}
168
169template <class TElem> TElem& RefStackEnumerator<TElem>::nextElement()
170{
171    return *fVector->elementAt(fCurIndex++);
172}
173
174template <class TElem> void RefStackEnumerator<TElem>::Reset()
175{
176    fCurIndex = 0;
177}
178
179XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.