source: obsolete/trunk/VUT/GtpVisibilityPreprocessor/support/xerces/include/xercesc/util/ValueStackOf.c @ 358

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