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