1 | /*
|
---|
2 | * Copyright 1999-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.hpp,v $
|
---|
19 | * Revision 1.7 2004/09/08 13:56:23 peiyongz
|
---|
20 | * Apache License Version 2.0
|
---|
21 | *
|
---|
22 | * Revision 1.6 2004/01/29 11:48:46 cargilld
|
---|
23 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
24 | *
|
---|
25 | * Revision 1.5 2003/05/16 06:01:52 knoaman
|
---|
26 | * Partial implementation of the configurable memory manager.
|
---|
27 | *
|
---|
28 | * Revision 1.4 2003/05/15 19:07:45 knoaman
|
---|
29 | * Partial implementation of the configurable memory manager.
|
---|
30 | *
|
---|
31 | * Revision 1.3 2002/11/04 15:22:04 tng
|
---|
32 | * C++ Namespace Support.
|
---|
33 | *
|
---|
34 | * Revision 1.2 2002/08/21 17:45:00 tng
|
---|
35 | * [Bug 7087] compiler warnings when using gcc.
|
---|
36 | *
|
---|
37 | * Revision 1.1.1.1 2002/02/01 22:22:12 peiyongz
|
---|
38 | * sane_include
|
---|
39 | *
|
---|
40 | * Revision 1.4 2000/03/02 19:54:45 roddey
|
---|
41 | * This checkin includes many changes done while waiting for the
|
---|
42 | * 1.1.0 code to be finished. I can't list them all here, but a list is
|
---|
43 | * available elsewhere.
|
---|
44 | *
|
---|
45 | * Revision 1.3 2000/02/24 20:05:25 abagchi
|
---|
46 | * Swat for removing Log from API docs
|
---|
47 | *
|
---|
48 | * Revision 1.2 2000/02/06 07:48:03 rahulj
|
---|
49 | * Year 2K copyright swat.
|
---|
50 | *
|
---|
51 | * Revision 1.1.1.1 1999/11/09 01:05:03 twl
|
---|
52 | * Initial checkin
|
---|
53 | *
|
---|
54 | * Revision 1.2 1999/11/08 20:45:13 rahul
|
---|
55 | * Swat for adding in Product name and CVS comment log variable.
|
---|
56 | *
|
---|
57 | */
|
---|
58 |
|
---|
59 | #if !defined(REFSTACKOF_HPP)
|
---|
60 | #define REFSTACKOF_HPP
|
---|
61 |
|
---|
62 | #include <xercesc/util/RefVectorOf.hpp>
|
---|
63 | #include <xercesc/util/EmptyStackException.hpp>
|
---|
64 |
|
---|
65 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
66 |
|
---|
67 | //
|
---|
68 | // Forward declare the enumerator so he can be our friend. Can you say
|
---|
69 | // friend? Sure...
|
---|
70 | //
|
---|
71 | template <class TElem> class RefStackEnumerator;
|
---|
72 |
|
---|
73 |
|
---|
74 | template <class TElem> class RefStackOf : public XMemory
|
---|
75 | {
|
---|
76 | public :
|
---|
77 | // -----------------------------------------------------------------------
|
---|
78 | // Constructors and Destructor
|
---|
79 | // -----------------------------------------------------------------------
|
---|
80 | RefStackOf(const unsigned int initElems,
|
---|
81 | const bool adoptElems = true,
|
---|
82 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
83 | ~RefStackOf();
|
---|
84 |
|
---|
85 |
|
---|
86 | // -----------------------------------------------------------------------
|
---|
87 | // Element management methods
|
---|
88 | // -----------------------------------------------------------------------
|
---|
89 | const TElem* elementAt(const unsigned int index) const;
|
---|
90 | void push(TElem* const toPush);
|
---|
91 | const TElem* peek() const;
|
---|
92 | TElem* pop();
|
---|
93 | void removeAllElements();
|
---|
94 |
|
---|
95 |
|
---|
96 | // -----------------------------------------------------------------------
|
---|
97 | // Getter methods
|
---|
98 | // -----------------------------------------------------------------------
|
---|
99 | bool empty();
|
---|
100 | unsigned int curCapacity();
|
---|
101 | unsigned int size();
|
---|
102 |
|
---|
103 |
|
---|
104 | private :
|
---|
105 | // -----------------------------------------------------------------------
|
---|
106 | // Declare our friends
|
---|
107 | // -----------------------------------------------------------------------
|
---|
108 | friend class RefStackEnumerator<TElem>;
|
---|
109 |
|
---|
110 | // -----------------------------------------------------------------------
|
---|
111 | // Unimplemented constructors and operators
|
---|
112 | // -----------------------------------------------------------------------
|
---|
113 | RefStackOf(const RefStackOf<TElem>&);
|
---|
114 | RefStackOf<TElem>& operator=(const RefStackOf<TElem>&);
|
---|
115 |
|
---|
116 | // -----------------------------------------------------------------------
|
---|
117 | // Data Members
|
---|
118 | //
|
---|
119 | // fVector
|
---|
120 | // The vector that is used as the backing data structure for the
|
---|
121 | // stack.
|
---|
122 | // -----------------------------------------------------------------------
|
---|
123 | RefVectorOf<TElem> fVector;
|
---|
124 | };
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 | //
|
---|
129 | // An enumerator for a value stack. It derives from the basic enumerator
|
---|
130 | // class, so that value stacks can be generically enumerated.
|
---|
131 | //
|
---|
132 | template <class TElem> class RefStackEnumerator : public XMLEnumerator<TElem>, public XMemory
|
---|
133 | {
|
---|
134 | public :
|
---|
135 | // -----------------------------------------------------------------------
|
---|
136 | // Constructors and Destructor
|
---|
137 | // -----------------------------------------------------------------------
|
---|
138 | RefStackEnumerator
|
---|
139 | (
|
---|
140 | RefStackOf<TElem>* const toEnum
|
---|
141 | , const bool adopt = false
|
---|
142 | );
|
---|
143 | virtual ~RefStackEnumerator();
|
---|
144 |
|
---|
145 |
|
---|
146 | // -----------------------------------------------------------------------
|
---|
147 | // Enum interface
|
---|
148 | // -----------------------------------------------------------------------
|
---|
149 | bool hasMoreElements() const;
|
---|
150 | TElem& nextElement();
|
---|
151 | void Reset();
|
---|
152 |
|
---|
153 |
|
---|
154 | private :
|
---|
155 | // -----------------------------------------------------------------------
|
---|
156 | // Unimplemented constructors and operators
|
---|
157 | // -----------------------------------------------------------------------
|
---|
158 | RefStackEnumerator(const RefStackEnumerator<TElem>&);
|
---|
159 | RefStackEnumerator<TElem>& operator=(const RefStackEnumerator<TElem>&);
|
---|
160 | // -----------------------------------------------------------------------
|
---|
161 | // Data Members
|
---|
162 | //
|
---|
163 | // fAdopted
|
---|
164 | // Indicates whether we have adopted the passed stack. If so then
|
---|
165 | // we delete the stack when we are destroyed.
|
---|
166 | //
|
---|
167 | // fCurIndex
|
---|
168 | // This is the current index into the vector inside the stack being
|
---|
169 | // enumerated.
|
---|
170 | //
|
---|
171 | // fToEnum
|
---|
172 | // The stack that is being enumerated. This is just kept for
|
---|
173 | // adoption purposes, since we really are enumerating the vector
|
---|
174 | // inside of it.
|
---|
175 | // -----------------------------------------------------------------------
|
---|
176 | bool fAdopted;
|
---|
177 | unsigned int fCurIndex;
|
---|
178 | RefVectorOf<TElem>* fVector;
|
---|
179 | RefStackOf<TElem>* fToEnum;
|
---|
180 | };
|
---|
181 |
|
---|
182 | XERCES_CPP_NAMESPACE_END
|
---|
183 |
|
---|
184 | #if !defined(XERCES_TMPLSINC)
|
---|
185 | #include <xercesc/util/RefStackOf.c>
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | #endif
|
---|