source: icXML/icXML-devel/src/icxercesc/validators/common/CMLeaf.hpp @ 3153

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

New custom icxercesc files

File size: 7.4 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) :
121CMNode(ContentSpecNode::Leaf, maxStates, manager)
122, fElement(0)
123, fPosition(position)
124, fAdopt(true)
125{
126    fElement = new (fMemoryManager) QName
127    (
128        element->getPrefix()
129        , element->getLocalPart()
130        , element->getURI()
131        , fMemoryManager
132    );
133    // Leaf nodes are never nullable unless its an epsilon node
134    fIsNullable = (fPosition == epsilonNode);
135}
136
137inline CMLeaf::CMLeaf( QName* const         element
138                     , unsigned int         position
139                     , bool                 adopt
140                     , unsigned int         maxStates
141                     , MemoryManager* const manager)
142: CMNode(ContentSpecNode::Leaf, maxStates, manager)
143, fElement(0)
144, fPosition(position)
145, fAdopt(adopt)
146{
147    if (!element)
148    {
149        fElement = new (fMemoryManager) QName
150        (
151              XMLUni::fgZeroLenString
152            , XMLUni::fgZeroLenString
153            , XMLElementDecl::fgInvalidElemId
154            , fMemoryManager
155        );
156        // We have to be responsible for this QName - override adopt parameter
157        fAdopt = true;
158    }
159    else
160    {
161        fElement = element;
162    }
163    // Leaf nodes are never nullable unless its an epsilon node
164    fIsNullable=(fPosition == epsilonNode);
165}
166
167inline CMLeaf::~CMLeaf()
168{
169    if (fAdopt)
170        delete fElement;
171}
172
173
174// ---------------------------------------------------------------------------
175//  Getter methods
176// ---------------------------------------------------------------------------
177inline QName* CMLeaf::getElement()
178{
179    return fElement;
180}
181
182inline const QName* CMLeaf::getElement() const
183{
184    return fElement;
185}
186
187inline unsigned int CMLeaf::getPosition() const
188{
189    return fPosition;
190}
191
192inline bool CMLeaf::isRepeatableLeaf() const
193{
194    return false;
195}
196
197// ---------------------------------------------------------------------------
198//  Setter methods
199// ---------------------------------------------------------------------------
200inline void CMLeaf::setPosition(const unsigned int newPosition)
201{
202    fPosition = newPosition;
203}
204
205
206// ---------------------------------------------------------------------------
207//  Implementation of public CMNode virtual interface
208// ---------------------------------------------------------------------------
209inline void CMLeaf::orphanChild()
210{
211}
212
213// ---------------------------------------------------------------------------
214//  Implementation of protected CMNode virtual interface
215// ---------------------------------------------------------------------------
216inline void CMLeaf::calcFirstPos(CMStateSet& toSet) const
217{
218    // If we are an epsilon node, then the first pos is an empty set
219    if (isNullable())
220    {
221        toSet.zeroBits();
222        return;
223    }
224
225    // Otherwise, its just the one bit of our position
226    toSet.setBit(fPosition);
227}
228
229inline void CMLeaf::calcLastPos(CMStateSet& toSet) const
230{
231    // If we are an epsilon node, then the last pos is an empty set
232    if (isNullable())
233    {
234        toSet.zeroBits();
235        return;
236    }
237
238    // Otherwise, its just the one bit of our position
239    toSet.setBit(fPosition);
240}
241
242XERCES_CPP_NAMESPACE_END
243
244#endif
Note: See TracBrowser for help on using the repository browser.