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