source: icXML/icXML-devel/src/xercesc/validators/common/CMLeaf.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 7.7 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: CMLeaf.hpp 677396 2008-07-16 19:36:20Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_CMLEAF_HPP)
23#define XERCESC_INCLUDE_GUARD_CMLEAF_HPP
24
25#include <xercesc/validators/common/CMNode.hpp>
26
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30//
31//  This class represents a leaf in the content spec node tree of an
32//  element's content model. It just has an element qname and a position value,
33//  the latter of which is used during the building of a DFA.
34//
35class CMLeaf : public CMNode
36{
37public :
38    // -----------------------------------------------------------------------
39    //  Constructors
40    // -----------------------------------------------------------------------
41    CMLeaf
42    (
43          QName* const          element
44        , unsigned int          position
45        , unsigned int          maxStates
46        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
47    );
48    CMLeaf
49    (
50          QName* const          element
51        , unsigned int          position
52        , bool                  adopt
53        , unsigned int          maxStates
54        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
55    );
56    ~CMLeaf();
57
58
59    // -----------------------------------------------------------------------
60    //  Getter methods
61    // -----------------------------------------------------------------------
62    QName* getElement();
63    const QName* getElement() const;
64    unsigned int getPosition() const;
65
66    virtual bool isRepeatableLeaf() const;
67
68    // -----------------------------------------------------------------------
69    //  Setter methods
70    // -----------------------------------------------------------------------
71    void setPosition(const unsigned int newPosition);
72
73
74    // -----------------------------------------------------------------------
75    //  Implementation of public CMNode virtual interface
76    // -----------------------------------------------------------------------
77    virtual void orphanChild();
78
79protected :
80    // -----------------------------------------------------------------------
81    //  Implementation of protected CMNode virtual interface
82    // -----------------------------------------------------------------------
83    void calcFirstPos(CMStateSet& toSet) const;
84    void calcLastPos(CMStateSet& toSet) const;
85
86
87private :
88    // -----------------------------------------------------------------------
89    //  Private data members
90    //
91    //  fElement
92    //      This is the element that this leaf represents.
93    //
94    //  fPosition
95    //      Part of the algorithm to convert a regex directly to a DFA
96    //      numbers each leaf sequentially. If its -1, that means its an
97    //      epsilon node. All others are non-epsilon positions.
98    //
99    //  fAdopt
100    //      This node is responsible for the storage of the fElement QName.
101    // -----------------------------------------------------------------------
102    QName*          fElement;
103    unsigned int    fPosition;
104    bool            fAdopt;
105
106    // -----------------------------------------------------------------------
107    //  Unimplemented constructors and operators
108    // -----------------------------------------------------------------------
109    CMLeaf(const CMLeaf&);
110    CMLeaf& operator=(const CMLeaf&);
111};
112
113
114// -----------------------------------------------------------------------
115//  Constructors
116// -----------------------------------------------------------------------
117inline CMLeaf::CMLeaf( QName* const         element
118                     , unsigned int         position
119                     , unsigned int         maxStates
120                     , MemoryManager* const manager) :
121    CMNode(ContentSpecNode::Leaf, maxStates, manager)
122    , fElement(0)
123    , fPosition(position)
124    , fAdopt(false)
125{
126    if (!element)
127    {
128        fElement = new (fMemoryManager) QName
129        (
130              XMLUni::fgZeroLenString
131            , XMLUni::fgZeroLenString
132            , XMLElementDecl::fgInvalidElemId
133            , fMemoryManager
134        );
135        // We have to be responsible for this QName - override default fAdopt
136        fAdopt = true;
137    }
138    else
139    {
140        fElement = element;
141    }
142    // Leaf nodes are never nullable unless its an epsilon node
143    fIsNullable=(fPosition == epsilonNode);
144}
145
146inline CMLeaf::CMLeaf( QName* const         element
147                     , unsigned int         position
148                     , bool                 adopt
149                     , unsigned int         maxStates
150                     , MemoryManager* const manager) :
151    CMNode(ContentSpecNode::Leaf, maxStates, manager)
152    , fElement(0)
153    , fPosition(position)
154    , fAdopt(adopt)
155{
156    if (!element)
157    {
158        fElement = new (fMemoryManager) QName
159        (
160              XMLUni::fgZeroLenString
161            , XMLUni::fgZeroLenString
162            , XMLElementDecl::fgInvalidElemId
163            , fMemoryManager
164        );
165        // We have to be responsible for this QName - override adopt parameter
166        fAdopt = true;
167    }
168    else
169    {
170        fElement = element;
171    }
172    // Leaf nodes are never nullable unless its an epsilon node
173    fIsNullable=(fPosition == epsilonNode);
174}
175
176inline CMLeaf::~CMLeaf()
177{
178    if (fAdopt)
179        delete fElement;
180}
181
182
183// ---------------------------------------------------------------------------
184//  Getter methods
185// ---------------------------------------------------------------------------
186inline QName* CMLeaf::getElement()
187{
188    return fElement;
189}
190
191inline const QName* CMLeaf::getElement() const
192{
193    return fElement;
194}
195
196inline unsigned int CMLeaf::getPosition() const
197{
198    return fPosition;
199}
200
201inline bool CMLeaf::isRepeatableLeaf() const
202{
203    return false;
204}
205
206// ---------------------------------------------------------------------------
207//  Setter methods
208// ---------------------------------------------------------------------------
209inline void CMLeaf::setPosition(const unsigned int newPosition)
210{
211    fPosition = newPosition;
212}
213
214
215// ---------------------------------------------------------------------------
216//  Implementation of public CMNode virtual interface
217// ---------------------------------------------------------------------------
218inline void CMLeaf::orphanChild()
219{
220}
221
222// ---------------------------------------------------------------------------
223//  Implementation of protected CMNode virtual interface
224// ---------------------------------------------------------------------------
225inline void CMLeaf::calcFirstPos(CMStateSet& toSet) const
226{
227    // If we are an epsilon node, then the first pos is an empty set
228    if (isNullable())
229    {
230        toSet.zeroBits();
231        return;
232    }
233
234    // Otherwise, its just the one bit of our position
235    toSet.setBit(fPosition);
236}
237
238inline void CMLeaf::calcLastPos(CMStateSet& toSet) const
239{
240    // If we are an epsilon node, then the last pos is an empty set
241    if (isNullable())
242    {
243        toSet.zeroBits();
244        return;
245    }
246
247    // Otherwise, its just the one bit of our position
248    toSet.setBit(fPosition);
249}
250
251XERCES_CPP_NAMESPACE_END
252
253#endif
Note: See TracBrowser for help on using the repository browser.