Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:34:30

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_CMLEAF_HPP)
0023 #define XERCESC_INCLUDE_GUARD_CMLEAF_HPP
0024 
0025 #include <xercesc/validators/common/CMNode.hpp>
0026 
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 //
0031 //  This class represents a leaf in the content spec node tree of an
0032 //  element's content model. It just has an element qname and a position value,
0033 //  the latter of which is used during the building of a DFA.
0034 //
0035 class CMLeaf : public CMNode
0036 {
0037 public :
0038     // -----------------------------------------------------------------------
0039     //  Constructors
0040     // -----------------------------------------------------------------------
0041     CMLeaf
0042     (
0043           QName* const          element
0044         , unsigned int          position
0045         , unsigned int          maxStates
0046         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0047     );
0048     CMLeaf
0049     (
0050           QName* const          element
0051         , unsigned int          position
0052         , bool                  adopt
0053         , unsigned int          maxStates
0054         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0055     );
0056     ~CMLeaf();
0057 
0058 
0059     // -----------------------------------------------------------------------
0060     //  Getter methods
0061     // -----------------------------------------------------------------------
0062     QName* getElement();
0063     const QName* getElement() const;
0064     unsigned int getPosition() const;
0065 
0066     virtual bool isRepeatableLeaf() const;
0067 
0068     // -----------------------------------------------------------------------
0069     //  Setter methods
0070     // -----------------------------------------------------------------------
0071     void setPosition(const unsigned int newPosition);
0072 
0073 
0074     // -----------------------------------------------------------------------
0075     //  Implementation of public CMNode virtual interface
0076     // -----------------------------------------------------------------------
0077     virtual void orphanChild();
0078 
0079 protected :
0080     // -----------------------------------------------------------------------
0081     //  Implementation of protected CMNode virtual interface
0082     // -----------------------------------------------------------------------
0083     void calcFirstPos(CMStateSet& toSet) const;
0084     void calcLastPos(CMStateSet& toSet) const;
0085 
0086 
0087 private :
0088     // -----------------------------------------------------------------------
0089     //  Private data members
0090     //
0091     //  fElement
0092     //      This is the element that this leaf represents.
0093     //
0094     //  fPosition
0095     //      Part of the algorithm to convert a regex directly to a DFA
0096     //      numbers each leaf sequentially. If its -1, that means its an
0097     //      epsilon node. All others are non-epsilon positions.
0098     //
0099     //  fAdopt
0100     //      This node is responsible for the storage of the fElement QName.
0101     // -----------------------------------------------------------------------
0102     QName*          fElement;
0103     unsigned int    fPosition;
0104     bool            fAdopt;
0105 
0106     // -----------------------------------------------------------------------
0107     //  Unimplemented constructors and operators
0108     // -----------------------------------------------------------------------
0109     CMLeaf(const CMLeaf&);
0110     CMLeaf& operator=(const CMLeaf&);
0111 };
0112 
0113 
0114 // -----------------------------------------------------------------------
0115 //  Constructors
0116 // -----------------------------------------------------------------------
0117 inline CMLeaf::CMLeaf( QName* const         element
0118                      , unsigned int         position
0119                      , unsigned int         maxStates
0120                      , MemoryManager* const manager) :
0121     CMNode(ContentSpecNode::Leaf, maxStates, manager)
0122     , fElement(0)
0123     , fPosition(position)
0124     , fAdopt(false)
0125 {
0126     if (!element)
0127     {
0128         fElement = new (fMemoryManager) QName
0129         (
0130               XMLUni::fgZeroLenString
0131             , XMLUni::fgZeroLenString
0132             , XMLElementDecl::fgInvalidElemId
0133             , fMemoryManager
0134         );
0135         // We have to be responsible for this QName - override default fAdopt
0136         fAdopt = true;
0137     }
0138     else
0139     {
0140         fElement = element;
0141     }
0142     // Leaf nodes are never nullable unless its an epsilon node
0143     fIsNullable=(fPosition == epsilonNode);
0144 }
0145 
0146 inline CMLeaf::CMLeaf( QName* const         element
0147                      , unsigned int         position
0148                      , bool                 adopt
0149                      , unsigned int         maxStates
0150                      , MemoryManager* const manager) :
0151     CMNode(ContentSpecNode::Leaf, maxStates, manager)
0152     , fElement(0)
0153     , fPosition(position)
0154     , fAdopt(adopt)
0155 {
0156     if (!element)
0157     {
0158         fElement = new (fMemoryManager) QName
0159         (
0160               XMLUni::fgZeroLenString
0161             , XMLUni::fgZeroLenString
0162             , XMLElementDecl::fgInvalidElemId
0163             , fMemoryManager
0164         );
0165         // We have to be responsible for this QName - override adopt parameter
0166         fAdopt = true;
0167     }
0168     else
0169     {
0170         fElement = element;
0171     }
0172     // Leaf nodes are never nullable unless its an epsilon node
0173     fIsNullable=(fPosition == epsilonNode);
0174 }
0175 
0176 inline CMLeaf::~CMLeaf()
0177 {
0178     if (fAdopt)
0179         delete fElement;
0180 }
0181 
0182 
0183 // ---------------------------------------------------------------------------
0184 //  Getter methods
0185 // ---------------------------------------------------------------------------
0186 inline QName* CMLeaf::getElement()
0187 {
0188     return fElement;
0189 }
0190 
0191 inline const QName* CMLeaf::getElement() const
0192 {
0193     return fElement;
0194 }
0195 
0196 inline unsigned int CMLeaf::getPosition() const
0197 {
0198     return fPosition;
0199 }
0200 
0201 inline bool CMLeaf::isRepeatableLeaf() const
0202 {
0203     return false;
0204 }
0205 
0206 // ---------------------------------------------------------------------------
0207 //  Setter methods
0208 // ---------------------------------------------------------------------------
0209 inline void CMLeaf::setPosition(const unsigned int newPosition)
0210 {
0211     fPosition = newPosition;
0212 }
0213 
0214 
0215 // ---------------------------------------------------------------------------
0216 //  Implementation of public CMNode virtual interface
0217 // ---------------------------------------------------------------------------
0218 inline void CMLeaf::orphanChild()
0219 {
0220 }
0221 
0222 // ---------------------------------------------------------------------------
0223 //  Implementation of protected CMNode virtual interface
0224 // ---------------------------------------------------------------------------
0225 inline void CMLeaf::calcFirstPos(CMStateSet& toSet) const
0226 {
0227     // If we are an epsilon node, then the first pos is an empty set
0228     if (isNullable())
0229     {
0230         toSet.zeroBits();
0231         return;
0232     }
0233 
0234     // Otherwise, its just the one bit of our position
0235     toSet.setBit(fPosition);
0236 }
0237 
0238 inline void CMLeaf::calcLastPos(CMStateSet& toSet) const
0239 {
0240     // If we are an epsilon node, then the last pos is an empty set
0241     if (isNullable())
0242     {
0243         toSet.zeroBits();
0244         return;
0245     }
0246 
0247     // Otherwise, its just the one bit of our position
0248     toSet.setBit(fPosition);
0249 }
0250 
0251 XERCES_CPP_NAMESPACE_END
0252 
0253 #endif