source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/ValueStackOf.c @ 2674

Revision 2674, 4.4 KB checked in by mattausch, 16 years ago (diff)
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: ValueStackOf.c 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#if defined(XERCES_TMPLSINC)
27#include <xercesc/util/ValueStackOf.hpp>
28#endif
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32
33// ---------------------------------------------------------------------------
34//  ValueStackOf: Constructors and Destructor
35// ---------------------------------------------------------------------------
36template <class TElem>
37ValueStackOf<TElem>::ValueStackOf(const unsigned int fInitCapacity,
38                                  MemoryManager* const manager,
39                                  const bool toCallDestructor) :
40
41    fVector(fInitCapacity, manager, toCallDestructor)
42{
43}
44
45template <class TElem> ValueStackOf<TElem>::~ValueStackOf()
46{
47}
48
49
50// ---------------------------------------------------------------------------
51//  ValueStackOf: Element management methods
52// ---------------------------------------------------------------------------
53template <class TElem> void ValueStackOf<TElem>::push(const TElem& toPush)
54{
55    fVector.addElement(toPush);
56}
57
58template <class TElem> const TElem& ValueStackOf<TElem>::peek() const
59{
60    const int curSize = fVector.size();
61    if (curSize == 0)
62        ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
63
64    return fVector.elementAt(curSize-1);
65}
66
67template <class TElem> TElem ValueStackOf<TElem>::pop()
68{
69    const int curSize = fVector.size();
70    if (curSize == 0)
71        ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager());
72
73    TElem retVal = fVector.elementAt(curSize-1);
74    fVector.removeElementAt(curSize-1);
75    return retVal;
76}
77
78template <class TElem> void ValueStackOf<TElem>::removeAllElements()
79{
80    fVector.removeAllElements();
81}
82
83
84// ---------------------------------------------------------------------------
85//  ValueStackOf: Getter methods
86// ---------------------------------------------------------------------------
87template <class TElem> bool ValueStackOf<TElem>::empty()
88{
89    return (fVector.size() == 0);
90}
91
92template <class TElem> unsigned int ValueStackOf<TElem>::curCapacity()
93{
94    return fVector.curCapacity();
95}
96
97template <class TElem> unsigned int ValueStackOf<TElem>::size()
98{
99    return fVector.size();
100}
101
102
103
104
105// ---------------------------------------------------------------------------
106//  ValueStackEnumerator: Constructors and Destructor
107// ---------------------------------------------------------------------------
108template <class TElem> ValueStackEnumerator<TElem>::
109ValueStackEnumerator(       ValueStackOf<TElem>* const  toEnum
110                    , const bool                        adopt) :
111
112    fAdopted(adopt)
113    , fCurIndex(0)
114    , fToEnum(toEnum)
115    , fVector(&toEnum->fVector)
116{
117}
118
119template <class TElem> ValueStackEnumerator<TElem>::~ValueStackEnumerator()
120{
121    if (fAdopted)
122        delete fToEnum;
123}
124
125
126// ---------------------------------------------------------------------------
127//  ValueStackEnumerator: Enum interface
128// ---------------------------------------------------------------------------
129template <class TElem> bool ValueStackEnumerator<TElem>::hasMoreElements() const
130{
131    if (fCurIndex >= fVector->size())
132        return false;
133    return true;
134}
135
136template <class TElem> TElem& ValueStackEnumerator<TElem>::nextElement()
137{
138    return fVector->elementAt(fCurIndex++);
139}
140
141template <class TElem> void ValueStackEnumerator<TElem>::Reset()
142{
143    fCurIndex = 0;
144}
145
146XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.