1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 1999, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Log: CMLeaf.hpp,v $
|
---|
59 | * Revision 1.7 2004/01/29 11:51:21 cargilld
|
---|
60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
61 | *
|
---|
62 | * Revision 1.6 2003/05/30 16:11:45 gareth
|
---|
63 | * Fixes so we compile under VC7.1. Patch by Alberto Massari.
|
---|
64 | *
|
---|
65 | * Revision 1.5 2003/05/18 14:02:06 knoaman
|
---|
66 | * Memory manager implementation: pass per instance manager.
|
---|
67 | *
|
---|
68 | * Revision 1.4 2003/05/16 21:43:20 knoaman
|
---|
69 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
70 | *
|
---|
71 | * Revision 1.3 2003/05/15 18:48:27 knoaman
|
---|
72 | * Partial implementation of the configurable memory manager.
|
---|
73 | *
|
---|
74 | * Revision 1.2 2002/11/04 14:54:58 tng
|
---|
75 | * C++ Namespace Support.
|
---|
76 | *
|
---|
77 | * Revision 1.1.1.1 2002/02/01 22:22:37 peiyongz
|
---|
78 | * sane_include
|
---|
79 | *
|
---|
80 | * Revision 1.6 2001/12/06 17:52:17 tng
|
---|
81 | * Performance Enhancement. The QName that was passed to the CMLeaf
|
---|
82 | * constructor was always being copied, even though the CMLeaf objects
|
---|
83 | * only existed during construction of a DFA. In most cases the original
|
---|
84 | * QName that was passed into the CMLeaf constructor continued to exist long
|
---|
85 | * after the CMLeaf was destroyed; in some cases the QName was constructed
|
---|
86 | * specifically to be passed to the CMLeaf constructor. Added a second CMLeaf constructor that indicated the QName passed in was to be adopted; otherwise the CMLeaf constructor just sets a reference to the QName passed in.
|
---|
87 | * By Henry Zongaro.
|
---|
88 | *
|
---|
89 | * Revision 1.5 2001/10/03 15:08:45 tng
|
---|
90 | * typo fix: remove the extra space which may confuse some compilers while constructing the qname.
|
---|
91 | *
|
---|
92 | * Revision 1.4 2001/05/11 13:27:16 tng
|
---|
93 | * Copyright update.
|
---|
94 | *
|
---|
95 | * Revision 1.3 2001/04/19 18:17:27 tng
|
---|
96 | * Schema: SchemaValidator update, and use QName in Content Model
|
---|
97 | *
|
---|
98 | * Revision 1.2 2001/02/16 14:58:57 tng
|
---|
99 | * Schema: Update Makefile, configure files, project files, and include path in
|
---|
100 | * certain cpp files because of the move of the common Content Model files. By Pei Yong Zhang.
|
---|
101 | *
|
---|
102 | * Revision 1.1 2001/02/16 14:17:29 tng
|
---|
103 | * Schema: Move the common Content Model files that are shared by DTD
|
---|
104 | * and schema from 'DTD' folder to 'common' folder. By Pei Yong Zhang.
|
---|
105 | *
|
---|
106 | * Revision 1.5 2000/03/28 19:43:25 roddey
|
---|
107 | * Fixes for signed/unsigned warnings. New work for two way transcoding
|
---|
108 | * stuff.
|
---|
109 | *
|
---|
110 | * Revision 1.4 2000/03/02 19:55:37 roddey
|
---|
111 | * This checkin includes many changes done while waiting for the
|
---|
112 | * 1.1.0 code to be finished. I can't list them all here, but a list is
|
---|
113 | * available elsewhere.
|
---|
114 | *
|
---|
115 | * Revision 1.3 2000/02/24 20:16:47 abagchi
|
---|
116 | * Swat for removing Log from API docs
|
---|
117 | *
|
---|
118 | * Revision 1.2 2000/02/09 21:42:36 abagchi
|
---|
119 | * Copyright swat
|
---|
120 | *
|
---|
121 | * Revision 1.1.1.1 1999/11/09 01:03:04 twl
|
---|
122 | * Initial checkin
|
---|
123 | *
|
---|
124 | * Revision 1.2 1999/11/08 20:45:36 rahul
|
---|
125 | * Swat for adding in Product name and CVS comment log variable.
|
---|
126 | *
|
---|
127 | */
|
---|
128 |
|
---|
129 | #if !defined(CMLEAF_HPP)
|
---|
130 | #define CMLEAF_HPP
|
---|
131 |
|
---|
132 | #include <xercesc/validators/common/CMNode.hpp>
|
---|
133 |
|
---|
134 |
|
---|
135 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
136 |
|
---|
137 | //
|
---|
138 | // This class represents a leaf in the content spec node tree of an
|
---|
139 | // element's content model. It just has an element qname and a position value,
|
---|
140 | // the latter of which is used during the building of a DFA.
|
---|
141 | //
|
---|
142 | class CMLeaf : public CMNode
|
---|
143 | {
|
---|
144 | public :
|
---|
145 | // -----------------------------------------------------------------------
|
---|
146 | // Constructors
|
---|
147 | // -----------------------------------------------------------------------
|
---|
148 | CMLeaf
|
---|
149 | (
|
---|
150 | QName* const element
|
---|
151 | , const unsigned int position = (~0)
|
---|
152 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
153 | );
|
---|
154 | CMLeaf
|
---|
155 | (
|
---|
156 | QName* const element
|
---|
157 | , const unsigned int position
|
---|
158 | , const bool adopt
|
---|
159 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
160 | );
|
---|
161 | ~CMLeaf();
|
---|
162 |
|
---|
163 |
|
---|
164 | // -----------------------------------------------------------------------
|
---|
165 | // Getter methods
|
---|
166 | // -----------------------------------------------------------------------
|
---|
167 | QName* getElement();
|
---|
168 | const QName* getElement() const;
|
---|
169 | unsigned int getPosition() const;
|
---|
170 |
|
---|
171 |
|
---|
172 | // -----------------------------------------------------------------------
|
---|
173 | // Setter methods
|
---|
174 | // -----------------------------------------------------------------------
|
---|
175 | void setPosition(const unsigned int newPosition);
|
---|
176 |
|
---|
177 |
|
---|
178 | // -----------------------------------------------------------------------
|
---|
179 | // Implementation of public CMNode virtual interface
|
---|
180 | // -----------------------------------------------------------------------
|
---|
181 | bool isNullable() const;
|
---|
182 |
|
---|
183 |
|
---|
184 | protected :
|
---|
185 | // -----------------------------------------------------------------------
|
---|
186 | // Implementation of protected CMNode virtual interface
|
---|
187 | // -----------------------------------------------------------------------
|
---|
188 | void calcFirstPos(CMStateSet& toSet) const;
|
---|
189 | void calcLastPos(CMStateSet& toSet) const;
|
---|
190 |
|
---|
191 |
|
---|
192 | private :
|
---|
193 | // -----------------------------------------------------------------------
|
---|
194 | // Private data members
|
---|
195 | //
|
---|
196 | // fElement
|
---|
197 | // This is the element that this leaf represents.
|
---|
198 | //
|
---|
199 | // fPosition
|
---|
200 | // Part of the algorithm to convert a regex directly to a DFA
|
---|
201 | // numbers each leaf sequentially. If its -1, that means its an
|
---|
202 | // epsilon node. All others are non-epsilon positions.
|
---|
203 | //
|
---|
204 | // fAdopt
|
---|
205 | // This node is responsible for the storage of the fElement QName.
|
---|
206 | // -----------------------------------------------------------------------
|
---|
207 | QName* fElement;
|
---|
208 | unsigned int fPosition;
|
---|
209 | bool fAdopt;
|
---|
210 |
|
---|
211 | // -----------------------------------------------------------------------
|
---|
212 | // Unimplemented constructors and operators
|
---|
213 | // -----------------------------------------------------------------------
|
---|
214 | CMLeaf(const CMLeaf&);
|
---|
215 | CMLeaf& operator=(const CMLeaf&);
|
---|
216 | };
|
---|
217 |
|
---|
218 |
|
---|
219 | // -----------------------------------------------------------------------
|
---|
220 | // Constructors
|
---|
221 | // -----------------------------------------------------------------------
|
---|
222 | inline CMLeaf::CMLeaf( QName* const element
|
---|
223 | , const unsigned int position
|
---|
224 | , MemoryManager* const manager) :
|
---|
225 | CMNode(ContentSpecNode::Leaf, manager)
|
---|
226 | , fElement(0)
|
---|
227 | , fPosition(position)
|
---|
228 | , fAdopt(false)
|
---|
229 | {
|
---|
230 | if (!element)
|
---|
231 | {
|
---|
232 | fElement = new (fMemoryManager) QName
|
---|
233 | (
|
---|
234 | XMLUni::fgZeroLenString
|
---|
235 | , XMLUni::fgZeroLenString
|
---|
236 | , XMLElementDecl::fgInvalidElemId
|
---|
237 | , fMemoryManager
|
---|
238 | );
|
---|
239 | // We have to be responsible for this QName - override default fAdopt
|
---|
240 | fAdopt = true;
|
---|
241 | }
|
---|
242 | else
|
---|
243 | {
|
---|
244 | fElement = element;
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | inline CMLeaf::CMLeaf( QName* const element
|
---|
249 | , const unsigned int position
|
---|
250 | , const bool adopt
|
---|
251 | , MemoryManager* const manager) :
|
---|
252 | CMNode(ContentSpecNode::Leaf, manager)
|
---|
253 | , fElement(0)
|
---|
254 | , fPosition(position)
|
---|
255 | , fAdopt(adopt)
|
---|
256 | {
|
---|
257 | if (!element)
|
---|
258 | {
|
---|
259 | fElement = new (fMemoryManager) QName
|
---|
260 | (
|
---|
261 | XMLUni::fgZeroLenString
|
---|
262 | , XMLUni::fgZeroLenString
|
---|
263 | , XMLElementDecl::fgInvalidElemId
|
---|
264 | , fMemoryManager
|
---|
265 | );
|
---|
266 | // We have to be responsible for this QName - override adopt parameter
|
---|
267 | fAdopt = true;
|
---|
268 | }
|
---|
269 | else
|
---|
270 | {
|
---|
271 | fElement = element;
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 | inline CMLeaf::~CMLeaf()
|
---|
276 | {
|
---|
277 | if (fAdopt)
|
---|
278 | delete fElement;
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | // ---------------------------------------------------------------------------
|
---|
283 | // Getter methods
|
---|
284 | // ---------------------------------------------------------------------------
|
---|
285 | inline QName* CMLeaf::getElement()
|
---|
286 | {
|
---|
287 | return fElement;
|
---|
288 | }
|
---|
289 |
|
---|
290 | inline const QName* CMLeaf::getElement() const
|
---|
291 | {
|
---|
292 | return fElement;
|
---|
293 | }
|
---|
294 |
|
---|
295 | inline unsigned int CMLeaf::getPosition() const
|
---|
296 | {
|
---|
297 | return fPosition;
|
---|
298 | }
|
---|
299 |
|
---|
300 |
|
---|
301 | // ---------------------------------------------------------------------------
|
---|
302 | // Setter methods
|
---|
303 | // ---------------------------------------------------------------------------
|
---|
304 | inline void CMLeaf::setPosition(const unsigned int newPosition)
|
---|
305 | {
|
---|
306 | fPosition = newPosition;
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 | // ---------------------------------------------------------------------------
|
---|
311 | // Implementation of public CMNode virtual interface
|
---|
312 | // ---------------------------------------------------------------------------
|
---|
313 | inline bool CMLeaf::isNullable() const
|
---|
314 | {
|
---|
315 | // Leaf nodes are never nullable unless its an epsilon node
|
---|
316 | return (fPosition == -1);
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | // ---------------------------------------------------------------------------
|
---|
321 | // Implementation of protected CMNode virtual interface
|
---|
322 | // ---------------------------------------------------------------------------
|
---|
323 | inline void CMLeaf::calcFirstPos(CMStateSet& toSet) const
|
---|
324 | {
|
---|
325 | // If we are an epsilon node, then the first pos is an empty set
|
---|
326 | if (fPosition == -1)
|
---|
327 | {
|
---|
328 | toSet.zeroBits();
|
---|
329 | return;
|
---|
330 | }
|
---|
331 |
|
---|
332 | // Otherwise, its just the one bit of our position
|
---|
333 | toSet.setBit(fPosition);
|
---|
334 | }
|
---|
335 |
|
---|
336 | inline void CMLeaf::calcLastPos(CMStateSet& toSet) const
|
---|
337 | {
|
---|
338 | // If we are an epsilon node, then the last pos is an empty set
|
---|
339 | if (fPosition == -1)
|
---|
340 | {
|
---|
341 | toSet.zeroBits();
|
---|
342 | return;
|
---|
343 | }
|
---|
344 |
|
---|
345 | // Otherwise, its just the one bit of our position
|
---|
346 | toSet.setBit(fPosition);
|
---|
347 | }
|
---|
348 |
|
---|
349 | XERCES_CPP_NAMESPACE_END
|
---|
350 |
|
---|
351 | #endif
|
---|