source: NonGTP/Xerces/xerces/include/xercesc/validators/common/CMLeaf.hpp @ 358

Revision 358, 10.2 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2001,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: CMLeaf.hpp,v $
19 * Revision 1.8  2004/09/08 13:56:51  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.7  2004/01/29 11:51:21  cargilld
23 * Code cleanup changes to get rid of various compiler diagnostic messages.
24 *
25 * Revision 1.6  2003/05/30 16:11:45  gareth
26 * Fixes so we compile under VC7.1. Patch by Alberto Massari.
27 *
28 * Revision 1.5  2003/05/18 14:02:06  knoaman
29 * Memory manager implementation: pass per instance manager.
30 *
31 * Revision 1.4  2003/05/16 21:43:20  knoaman
32 * Memory manager implementation: Modify constructors to pass in the memory manager.
33 *
34 * Revision 1.3  2003/05/15 18:48:27  knoaman
35 * Partial implementation of the configurable memory manager.
36 *
37 * Revision 1.2  2002/11/04 14:54:58  tng
38 * C++ Namespace Support.
39 *
40 * Revision 1.1.1.1  2002/02/01 22:22:37  peiyongz
41 * sane_include
42 *
43 * Revision 1.6  2001/12/06 17:52:17  tng
44 * Performance Enhancement.  The QName that was passed to the CMLeaf
45 * constructor was always being copied, even though the CMLeaf objects
46 * only existed during construction of a DFA.  In most cases the original
47 * QName that was passed into the CMLeaf constructor continued to exist long
48 * after the CMLeaf was destroyed; in some cases the QName was constructed
49 * 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.
50 * By Henry Zongaro.
51 *
52 * Revision 1.5  2001/10/03 15:08:45  tng
53 * typo fix: remove the extra space which may confuse some compilers while constructing the qname.
54 *
55 * Revision 1.4  2001/05/11 13:27:16  tng
56 * Copyright update.
57 *
58 * Revision 1.3  2001/04/19 18:17:27  tng
59 * Schema: SchemaValidator update, and use QName in Content Model
60 *
61 * Revision 1.2  2001/02/16 14:58:57  tng
62 * Schema: Update Makefile, configure files, project files, and include path in
63 * certain cpp files because of the move of the common Content Model files.  By Pei Yong Zhang.
64 *
65 * Revision 1.1  2001/02/16 14:17:29  tng
66 * Schema: Move the common Content Model files that are shared by DTD
67 * and schema from 'DTD' folder to 'common' folder.  By Pei Yong Zhang.
68 *
69 * Revision 1.5  2000/03/28 19:43:25  roddey
70 * Fixes for signed/unsigned warnings. New work for two way transcoding
71 * stuff.
72 *
73 * Revision 1.4  2000/03/02 19:55:37  roddey
74 * This checkin includes many changes done while waiting for the
75 * 1.1.0 code to be finished. I can't list them all here, but a list is
76 * available elsewhere.
77 *
78 * Revision 1.3  2000/02/24 20:16:47  abagchi
79 * Swat for removing Log from API docs
80 *
81 * Revision 1.2  2000/02/09 21:42:36  abagchi
82 * Copyright swat
83 *
84 * Revision 1.1.1.1  1999/11/09 01:03:04  twl
85 * Initial checkin
86 *
87 * Revision 1.2  1999/11/08 20:45:36  rahul
88 * Swat for adding in Product name and CVS comment log variable.
89 *
90 */
91
92#if !defined(CMLEAF_HPP)
93#define CMLEAF_HPP
94
95#include <xercesc/validators/common/CMNode.hpp>
96
97
98XERCES_CPP_NAMESPACE_BEGIN
99
100//
101//  This class represents a leaf in the content spec node tree of an
102//  element's content model. It just has an element qname and a position value,
103//  the latter of which is used during the building of a DFA.
104//
105class CMLeaf : public CMNode
106{
107public :
108    // -----------------------------------------------------------------------
109    //  Constructors
110    // -----------------------------------------------------------------------
111    CMLeaf
112    (
113          QName* const         element
114        , const unsigned int   position = (~0)
115        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
116    );
117    CMLeaf
118    (
119          QName* const         element
120        , const unsigned int   position
121        , const bool           adopt
122        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
123    );
124    ~CMLeaf();
125
126
127    // -----------------------------------------------------------------------
128    //  Getter methods
129    // -----------------------------------------------------------------------
130    QName* getElement();
131    const QName* getElement() const;
132    unsigned int getPosition() const;
133
134
135    // -----------------------------------------------------------------------
136    //  Setter methods
137    // -----------------------------------------------------------------------
138    void setPosition(const unsigned int newPosition);
139
140
141    // -----------------------------------------------------------------------
142    //  Implementation of public CMNode virtual interface
143    // -----------------------------------------------------------------------
144    bool isNullable() const;
145
146
147protected :
148    // -----------------------------------------------------------------------
149    //  Implementation of protected CMNode virtual interface
150    // -----------------------------------------------------------------------
151    void calcFirstPos(CMStateSet& toSet) const;
152    void calcLastPos(CMStateSet& toSet) const;
153
154
155private :
156    // -----------------------------------------------------------------------
157    //  Private data members
158    //
159    //  fElement
160    //      This is the element that this leaf represents.
161    //
162    //  fPosition
163    //      Part of the algorithm to convert a regex directly to a DFA
164    //      numbers each leaf sequentially. If its -1, that means its an
165    //      epsilon node. All others are non-epsilon positions.
166    //
167    //  fAdopt
168    //      This node is responsible for the storage of the fElement QName.
169    // -----------------------------------------------------------------------
170    QName*          fElement;
171    unsigned int    fPosition;
172    bool            fAdopt;
173
174    // -----------------------------------------------------------------------
175    //  Unimplemented constructors and operators
176    // -----------------------------------------------------------------------
177    CMLeaf(const CMLeaf&);
178    CMLeaf& operator=(const CMLeaf&);
179};
180
181
182// -----------------------------------------------------------------------
183//  Constructors
184// -----------------------------------------------------------------------
185inline CMLeaf::CMLeaf(       QName* const         element
186                     , const unsigned int         position
187                     ,       MemoryManager* const manager) :
188    CMNode(ContentSpecNode::Leaf, manager)
189    , fElement(0)
190    , fPosition(position)
191    , fAdopt(false)
192{
193    if (!element)
194    {
195        fElement = new (fMemoryManager) QName
196        (
197              XMLUni::fgZeroLenString
198            , XMLUni::fgZeroLenString
199            , XMLElementDecl::fgInvalidElemId
200            , fMemoryManager
201        );
202        // We have to be responsible for this QName - override default fAdopt
203        fAdopt = true;
204    }
205    else
206    {
207        fElement = element;
208    }
209}
210
211inline CMLeaf::CMLeaf(       QName* const         element
212                     , const unsigned int         position
213                     , const bool                 adopt
214                     ,       MemoryManager* const manager) :
215    CMNode(ContentSpecNode::Leaf, manager)
216    , fElement(0)
217    , fPosition(position)
218    , fAdopt(adopt)
219{
220    if (!element)
221    {
222        fElement = new (fMemoryManager) QName
223        (
224              XMLUni::fgZeroLenString
225            , XMLUni::fgZeroLenString
226            , XMLElementDecl::fgInvalidElemId
227            , fMemoryManager
228        );
229        // We have to be responsible for this QName - override adopt parameter
230        fAdopt = true;
231    }
232    else
233    {
234        fElement = element;
235    }
236}
237
238inline CMLeaf::~CMLeaf()
239{
240    if (fAdopt)
241        delete fElement;
242}
243
244
245// ---------------------------------------------------------------------------
246//  Getter methods
247// ---------------------------------------------------------------------------
248inline QName* CMLeaf::getElement()
249{
250    return fElement;
251}
252
253inline const QName* CMLeaf::getElement() const
254{
255    return fElement;
256}
257
258inline unsigned int CMLeaf::getPosition() const
259{
260    return fPosition;
261}
262
263
264// ---------------------------------------------------------------------------
265//  Setter methods
266// ---------------------------------------------------------------------------
267inline void CMLeaf::setPosition(const unsigned int newPosition)
268{
269    fPosition = newPosition;
270}
271
272
273// ---------------------------------------------------------------------------
274//  Implementation of public CMNode virtual interface
275// ---------------------------------------------------------------------------
276inline bool CMLeaf::isNullable() const
277{
278    // Leaf nodes are never nullable unless its an epsilon node
279    return (fPosition == -1);
280}
281
282
283// ---------------------------------------------------------------------------
284//  Implementation of protected CMNode virtual interface
285// ---------------------------------------------------------------------------
286inline void CMLeaf::calcFirstPos(CMStateSet& toSet) const
287{
288    // If we are an epsilon node, then the first pos is an empty set
289    if (fPosition == -1)
290    {
291        toSet.zeroBits();
292        return;
293    }
294
295    // Otherwise, its just the one bit of our position
296    toSet.setBit(fPosition);
297}
298
299inline void CMLeaf::calcLastPos(CMStateSet& toSet) const
300{
301    // If we are an epsilon node, then the last pos is an empty set
302    if (fPosition == -1)
303    {
304        toSet.zeroBits();
305        return;
306    }
307
308    // Otherwise, its just the one bit of our position
309    toSet.setBit(fPosition);
310}
311
312XERCES_CPP_NAMESPACE_END
313
314#endif
Note: See TracBrowser for help on using the repository browser.