Back to home page

EIC code displayed by LXR

 
 

    


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

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_SIMPLECONTENTMODEL_HPP)
0023 #define XERCESC_INCLUDE_GUARD_SIMPLECONTENTMODEL_HPP
0024 
0025 #include <xercesc/framework/XMLContentModel.hpp>
0026 #include <xercesc/validators/common/ContentSpecNode.hpp>
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 //
0031 //  SimpleContentModel is a derivative of the abstract content model base
0032 //  class that handles a small set of simple content models that are just
0033 //  way overkill to give the DFA treatment.
0034 //
0035 //  DESCRIPTION:
0036 //
0037 //  This guy handles the following scenarios:
0038 //
0039 //      a
0040 //      a?
0041 //      a*
0042 //      a+
0043 //      a,b
0044 //      a|b
0045 //
0046 //  These all involve a unary operation with one element type, or a binary
0047 //  operation with two elements. These are very simple and can be checked
0048 //  in a simple way without a DFA and without the overhead of setting up a
0049 //  DFA for such a simple check.
0050 //
0051 //  NOTE:   Pass the XMLElementDecl::fgPCDataElemId value to represent a
0052 //          PCData node. Pass XMLElementDecl::fgInvalidElemId for unused element
0053 //
0054 class SimpleContentModel : public XMLContentModel
0055 {
0056 public :
0057     // -----------------------------------------------------------------------
0058     //  Constructors and Destructor
0059     // -----------------------------------------------------------------------
0060     SimpleContentModel
0061     (
0062         const bool                        dtd
0063       , QName* const                      firstChild
0064       , QName* const                      secondChild
0065       , const ContentSpecNode::NodeTypes  cmOp
0066       , MemoryManager* const              manager = XMLPlatformUtils::fgMemoryManager
0067     );
0068 
0069     ~SimpleContentModel();
0070 
0071 
0072     // -----------------------------------------------------------------------
0073     //  Implementation of the ContentModel virtual interface
0074     // -----------------------------------------------------------------------
0075     virtual bool validateContent
0076     (
0077         QName** const         children
0078       , XMLSize_t             childCount
0079       , unsigned int          emptyNamespaceId
0080       , XMLSize_t*            indexFailingChild
0081       , MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
0082     ) const;
0083 
0084     virtual bool validateContentSpecial
0085     (
0086         QName** const           children
0087       , XMLSize_t               childCount
0088       , unsigned int            emptyNamespaceId
0089       , GrammarResolver*  const pGrammarResolver
0090       , XMLStringPool*    const pStringPool
0091       , XMLSize_t*              indexFailingChild
0092       , MemoryManager*    const manager = XMLPlatformUtils::fgMemoryManager
0093     ) const;
0094 
0095     virtual ContentLeafNameTypeVector *getContentLeafNameTypeVector() const;
0096 
0097     virtual unsigned int getNextState(unsigned int currentState,
0098                                       XMLSize_t    elementIndex) const;
0099 
0100     virtual bool handleRepetitions( const QName* const curElem,
0101                                     unsigned int curState,
0102                                     unsigned int currentLoop,
0103                                     unsigned int& nextState,
0104                                     unsigned int& nextLoop,
0105                                     XMLSize_t elementIndex,
0106                                     SubstitutionGroupComparator * comparator) const;
0107 
0108     virtual void checkUniqueParticleAttribution
0109     (
0110         SchemaGrammar*    const pGrammar
0111       , GrammarResolver*  const pGrammarResolver
0112       , XMLStringPool*    const pStringPool
0113       , XMLValidator*     const pValidator
0114       , unsigned int*     const pContentSpecOrgURI
0115       , const XMLCh*            pComplexTypeName = 0
0116     ) ;
0117 
0118  private :
0119     // -----------------------------------------------------------------------
0120     //  Unimplemented constructors and operators
0121     // -----------------------------------------------------------------------
0122     SimpleContentModel();
0123     SimpleContentModel(const SimpleContentModel&);
0124     SimpleContentModel& operator=(const SimpleContentModel&);
0125 
0126 
0127     // -----------------------------------------------------------------------
0128     //  Private data members
0129     //
0130     //  fFirstChild
0131     //  fSecondChild
0132     //      The first (and optional second) child node. The
0133     //      operation code tells us whether the second child is used or not.
0134     //
0135     //  fOp
0136     //      The operation that this object represents. Since this class only
0137     //      does simple contents, there is only ever a single operation
0138     //      involved (i.e. the children of the operation are always one or
0139     //      two leafs.)
0140     //
0141     //  fDTD
0142     //      Boolean to allow DTDs to validate even with namespace support. */
0143     //
0144     // -----------------------------------------------------------------------
0145     QName*                     fFirstChild;
0146     QName*                     fSecondChild;
0147     ContentSpecNode::NodeTypes fOp;
0148     bool                       fDTD;
0149     MemoryManager* const       fMemoryManager;
0150 };
0151 
0152 
0153 // ---------------------------------------------------------------------------
0154 //  SimpleContentModel: Constructors and Destructor
0155 // ---------------------------------------------------------------------------
0156 inline SimpleContentModel::SimpleContentModel
0157 (
0158       const bool                       dtd
0159     , QName* const                     firstChild
0160     , QName* const                     secondChild
0161     , const ContentSpecNode::NodeTypes cmOp
0162      , MemoryManager* const            manager
0163 )
0164     : fFirstChild(0)
0165     , fSecondChild(0)
0166     , fOp(cmOp)
0167     , fDTD(dtd)
0168     , fMemoryManager(manager)
0169 {
0170     if (firstChild)
0171         fFirstChild = new (manager) QName(*firstChild);
0172     else
0173         fFirstChild = new (manager) QName(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId, manager);
0174 
0175     if (secondChild)
0176         fSecondChild = new (manager) QName(*secondChild);
0177     else
0178         fSecondChild = new (manager) QName(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId, manager);
0179 }
0180 
0181 inline SimpleContentModel::~SimpleContentModel()
0182 {
0183     delete fFirstChild;
0184     delete fSecondChild;
0185 }
0186 
0187 
0188 // ---------------------------------------------------------------------------
0189 //  SimpleContentModel: Virtual methods
0190 // ---------------------------------------------------------------------------
0191 inline unsigned int
0192 SimpleContentModel::getNextState(unsigned int,
0193                                  XMLSize_t) const {
0194 
0195     return XMLContentModel::gInvalidTrans;
0196 }
0197 
0198 inline bool
0199 SimpleContentModel::handleRepetitions( const QName* const /*curElem*/,
0200                                        unsigned int /*curState*/,
0201                                        unsigned int /*currentLoop*/,
0202                                        unsigned int& /*nextState*/,
0203                                        unsigned int& /*nextLoop*/,
0204                                        XMLSize_t /*elementIndex*/,
0205                                        SubstitutionGroupComparator * /*comparator*/) const
0206 {
0207     return true;
0208 }
0209 
0210 XERCES_CPP_NAMESPACE_END
0211 
0212 #endif