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: ValueVectorOf.hpp,v $
|
---|
19 | * Revision 1.9 2004/09/08 13:56:23 peiyongz
|
---|
20 | * Apache License Version 2.0
|
---|
21 | *
|
---|
22 | * Revision 1.8 2004/01/29 11:48:46 cargilld
|
---|
23 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
24 | *
|
---|
25 | * Revision 1.7 2003/05/29 13:26:44 knoaman
|
---|
26 | * Fix memory leak when using deprecated dom.
|
---|
27 | *
|
---|
28 | * Revision 1.6 2003/05/16 21:37:00 knoaman
|
---|
29 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
30 | *
|
---|
31 | * Revision 1.5 2003/05/16 06:01:52 knoaman
|
---|
32 | * Partial implementation of the configurable memory manager.
|
---|
33 | *
|
---|
34 | * Revision 1.4 2003/05/15 19:07:46 knoaman
|
---|
35 | * Partial implementation of the configurable memory manager.
|
---|
36 | *
|
---|
37 | * Revision 1.3 2002/11/04 15:22:05 tng
|
---|
38 | * C++ Namespace Support.
|
---|
39 | *
|
---|
40 | * Revision 1.2 2002/08/21 17:45:00 tng
|
---|
41 | * [Bug 7087] compiler warnings when using gcc.
|
---|
42 | *
|
---|
43 | * Revision 1.1.1.1 2002/02/01 22:22:13 peiyongz
|
---|
44 | * sane_include
|
---|
45 | *
|
---|
46 | * Revision 1.6 2002/01/10 17:44:49 knoaman
|
---|
47 | * Fix for bug 5786.
|
---|
48 | *
|
---|
49 | * Revision 1.5 2001/08/09 15:24:37 knoaman
|
---|
50 | * add support for <anyAttribute> declaration.
|
---|
51 | *
|
---|
52 | * Revision 1.4 2000/03/02 19:54:47 roddey
|
---|
53 | * This checkin includes many changes done while waiting for the
|
---|
54 | * 1.1.0 code to be finished. I can't list them all here, but a list is
|
---|
55 | * available elsewhere.
|
---|
56 | *
|
---|
57 | * Revision 1.3 2000/02/24 20:05:26 abagchi
|
---|
58 | * Swat for removing Log from API docs
|
---|
59 | *
|
---|
60 | * Revision 1.2 2000/02/06 07:48:05 rahulj
|
---|
61 | * Year 2K copyright swat.
|
---|
62 | *
|
---|
63 | * Revision 1.1.1.1 1999/11/09 01:05:33 twl
|
---|
64 | * Initial checkin
|
---|
65 | *
|
---|
66 | * Revision 1.2 1999/11/08 20:45:19 rahul
|
---|
67 | * Swat for adding in Product name and CVS comment log variable.
|
---|
68 | *
|
---|
69 | */
|
---|
70 |
|
---|
71 |
|
---|
72 | #if !defined(VALUEVECTOROF_HPP)
|
---|
73 | #define VALUEVECTOROF_HPP
|
---|
74 |
|
---|
75 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
---|
76 | #include <xercesc/util/XMLEnumerator.hpp>
|
---|
77 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
78 | #include <xercesc/framework/MemoryManager.hpp>
|
---|
79 |
|
---|
80 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
81 |
|
---|
82 | template <class TElem> class ValueVectorOf : public XMemory
|
---|
83 | {
|
---|
84 | public :
|
---|
85 | // -----------------------------------------------------------------------
|
---|
86 | // Constructors and Destructor
|
---|
87 | // -----------------------------------------------------------------------
|
---|
88 | ValueVectorOf
|
---|
89 | (
|
---|
90 | const unsigned int maxElems
|
---|
91 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
92 | , const bool toCallDestructor = false
|
---|
93 | );
|
---|
94 | ValueVectorOf(const ValueVectorOf<TElem>& toCopy);
|
---|
95 | ~ValueVectorOf();
|
---|
96 |
|
---|
97 |
|
---|
98 | // -----------------------------------------------------------------------
|
---|
99 | // Operators
|
---|
100 | // -----------------------------------------------------------------------
|
---|
101 | ValueVectorOf<TElem>& operator=(const ValueVectorOf<TElem>& toAssign);
|
---|
102 |
|
---|
103 |
|
---|
104 | // -----------------------------------------------------------------------
|
---|
105 | // Element management
|
---|
106 | // -----------------------------------------------------------------------
|
---|
107 | void addElement(const TElem& toAdd);
|
---|
108 | void setElementAt(const TElem& toSet, const unsigned int setAt);
|
---|
109 | void insertElementAt(const TElem& toInsert, const unsigned int insertAt);
|
---|
110 | void removeElementAt(const unsigned int removeAt);
|
---|
111 | void removeAllElements();
|
---|
112 | bool containsElement(const TElem& toCheck, const unsigned int startIndex = 0);
|
---|
113 |
|
---|
114 |
|
---|
115 | // -----------------------------------------------------------------------
|
---|
116 | // Getter methods
|
---|
117 | // -----------------------------------------------------------------------
|
---|
118 | const TElem& elementAt(const unsigned int getAt) const;
|
---|
119 | TElem& elementAt(const unsigned int getAt);
|
---|
120 | unsigned int curCapacity() const;
|
---|
121 | unsigned int size() const;
|
---|
122 | MemoryManager* getMemoryManager() const;
|
---|
123 |
|
---|
124 |
|
---|
125 | // -----------------------------------------------------------------------
|
---|
126 | // Miscellaneous
|
---|
127 | // -----------------------------------------------------------------------
|
---|
128 | void ensureExtraCapacity(const unsigned int length);
|
---|
129 | const TElem* rawData() const;
|
---|
130 |
|
---|
131 |
|
---|
132 | private:
|
---|
133 | // -----------------------------------------------------------------------
|
---|
134 | // Data members
|
---|
135 | //
|
---|
136 | // fCurCount
|
---|
137 | // The count of values current added to the vector, which may be
|
---|
138 | // less than the internal capacity.
|
---|
139 | //
|
---|
140 | // fMaxCount
|
---|
141 | // The current capacity of the vector.
|
---|
142 | //
|
---|
143 | // fElemList
|
---|
144 | // The list of elements, which is dynamically allocated to the needed
|
---|
145 | // size.
|
---|
146 | // -----------------------------------------------------------------------
|
---|
147 | bool fCallDestructor;
|
---|
148 | unsigned int fCurCount;
|
---|
149 | unsigned int fMaxCount;
|
---|
150 | TElem* fElemList;
|
---|
151 | MemoryManager* fMemoryManager;
|
---|
152 | };
|
---|
153 |
|
---|
154 |
|
---|
155 | //
|
---|
156 | // An enumerator for a value vector. It derives from the basic enumerator
|
---|
157 | // class, so that value vectors can be generically enumerated.
|
---|
158 | //
|
---|
159 | template <class TElem> class ValueVectorEnumerator : public XMLEnumerator<TElem>, public XMemory
|
---|
160 | {
|
---|
161 | public :
|
---|
162 | // -----------------------------------------------------------------------
|
---|
163 | // Constructors and Destructor
|
---|
164 | // -----------------------------------------------------------------------
|
---|
165 | ValueVectorEnumerator
|
---|
166 | (
|
---|
167 | ValueVectorOf<TElem>* const toEnum
|
---|
168 | , const bool adopt = false
|
---|
169 | );
|
---|
170 | virtual ~ValueVectorEnumerator();
|
---|
171 |
|
---|
172 |
|
---|
173 | // -----------------------------------------------------------------------
|
---|
174 | // Enum interface
|
---|
175 | // -----------------------------------------------------------------------
|
---|
176 | bool hasMoreElements() const;
|
---|
177 | TElem& nextElement();
|
---|
178 | void Reset();
|
---|
179 |
|
---|
180 |
|
---|
181 | private :
|
---|
182 | // -----------------------------------------------------------------------
|
---|
183 | // Unimplemented constructors and operators
|
---|
184 | // -----------------------------------------------------------------------
|
---|
185 | ValueVectorEnumerator(const ValueVectorEnumerator<TElem>&);
|
---|
186 | ValueVectorEnumerator<TElem>& operator=(const ValueVectorEnumerator<TElem>&);
|
---|
187 |
|
---|
188 | // -----------------------------------------------------------------------
|
---|
189 | // Data Members
|
---|
190 | //
|
---|
191 | // fAdopted
|
---|
192 | // Indicates whether we have adopted the passed vector. If so then
|
---|
193 | // we delete the vector when we are destroyed.
|
---|
194 | //
|
---|
195 | // fCurIndex
|
---|
196 | // This is the current index into the vector.
|
---|
197 | //
|
---|
198 | // fToEnum
|
---|
199 | // The value vector being enumerated.
|
---|
200 | // -----------------------------------------------------------------------
|
---|
201 | bool fAdopted;
|
---|
202 | unsigned int fCurIndex;
|
---|
203 | ValueVectorOf<TElem>* fToEnum;
|
---|
204 | };
|
---|
205 |
|
---|
206 | XERCES_CPP_NAMESPACE_END
|
---|
207 |
|
---|
208 | #if !defined(XERCES_TMPLSINC)
|
---|
209 | #include <xercesc/util/ValueVectorOf.c>
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | #endif
|
---|