|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: RefStackOf.c 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Includes |
|
41 // --------------------------------------------------------------------------- |
|
42 #if defined(XERCES_TMPLSINC) |
|
43 #include <xercesc/util/RefStackOf.hpp> |
|
44 #endif |
|
45 |
|
46 XERCES_CPP_NAMESPACE_BEGIN |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // RefStackOf: Constructors and Destructor |
|
50 // --------------------------------------------------------------------------- |
|
51 template <class TElem> |
|
52 RefStackOf<TElem>::RefStackOf(const unsigned int initElems, |
|
53 const bool adoptElems, |
|
54 MemoryManager* const manager) : |
|
55 |
|
56 fVector(initElems, adoptElems, manager) |
|
57 { |
|
58 } |
|
59 |
|
60 template <class TElem> RefStackOf<TElem>::~RefStackOf() |
|
61 { |
|
62 } |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // RefStackOf: Element management methods |
|
67 // --------------------------------------------------------------------------- |
|
68 template <class TElem> const TElem* RefStackOf<TElem>:: |
|
69 elementAt(const unsigned int index) const |
|
70 { |
|
71 if (index > fVector.size()) |
|
72 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Stack_BadIndex, fVector.getMemoryManager()); |
|
73 return fVector.elementAt(index); |
|
74 } |
|
75 |
|
76 template <class TElem> void RefStackOf<TElem>::push(TElem* const toPush) |
|
77 { |
|
78 fVector.addElement(toPush); |
|
79 } |
|
80 |
|
81 template <class TElem> const TElem* RefStackOf<TElem>::peek() const |
|
82 { |
|
83 const int curSize = fVector.size(); |
|
84 if (curSize == 0) |
|
85 ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager()); |
|
86 |
|
87 return fVector.elementAt(curSize-1); |
|
88 } |
|
89 |
|
90 template <class TElem> TElem* RefStackOf<TElem>::pop() |
|
91 { |
|
92 const int curSize = fVector.size(); |
|
93 if (curSize == 0) |
|
94 ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::Stack_EmptyStack, fVector.getMemoryManager()); |
|
95 |
|
96 // Orphan off the element from the last slot in the vector |
|
97 return fVector.orphanElementAt(curSize-1); |
|
98 } |
|
99 |
|
100 template <class TElem> void RefStackOf<TElem>::removeAllElements() |
|
101 { |
|
102 fVector.removeAllElements(); |
|
103 } |
|
104 |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // RefStackOf: Getter methods |
|
108 // --------------------------------------------------------------------------- |
|
109 template <class TElem> bool RefStackOf<TElem>::empty() |
|
110 { |
|
111 return (fVector.size() == 0); |
|
112 } |
|
113 |
|
114 template <class TElem> unsigned int RefStackOf<TElem>::curCapacity() |
|
115 { |
|
116 return fVector.curCapacity(); |
|
117 } |
|
118 |
|
119 template <class TElem> unsigned int RefStackOf<TElem>::size() |
|
120 { |
|
121 return fVector.size(); |
|
122 } |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // RefStackEnumerator: Constructors and Destructor |
|
129 // --------------------------------------------------------------------------- |
|
130 template <class TElem> RefStackEnumerator<TElem>:: |
|
131 RefStackEnumerator( RefStackOf<TElem>* const toEnum |
|
132 , const bool adopt) : |
|
133 fAdopted(adopt) |
|
134 , fCurIndex(0) |
|
135 , fToEnum(toEnum) |
|
136 , fVector(&toEnum->fVector) |
|
137 { |
|
138 } |
|
139 |
|
140 template <class TElem> RefStackEnumerator<TElem>::~RefStackEnumerator() |
|
141 { |
|
142 if (fAdopted) |
|
143 delete fToEnum; |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // RefStackEnumerator: Enum interface |
|
149 // --------------------------------------------------------------------------- |
|
150 template <class TElem> bool RefStackEnumerator<TElem>::hasMoreElements() const |
|
151 { |
|
152 if (fCurIndex >= fVector->size()) |
|
153 return false; |
|
154 return true; |
|
155 } |
|
156 |
|
157 template <class TElem> TElem& RefStackEnumerator<TElem>::nextElement() |
|
158 { |
|
159 return *fVector->elementAt(fCurIndex++); |
|
160 } |
|
161 |
|
162 template <class TElem> void RefStackEnumerator<TElem>::Reset() |
|
163 { |
|
164 fCurIndex = 0; |
|
165 } |
|
166 |
|
167 XERCES_CPP_NAMESPACE_END |