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: CMAny.cpp 677396 2008-07-16 19:36:20Z amassari $
20 */
21
22 // ---------------------------------------------------------------------------
23 // Includes
24 // ---------------------------------------------------------------------------
25 #include <xercesc/util/XercesDefs.hpp>
26 #include <xercesc/util/RuntimeException.hpp>
27 #include <xercesc/validators/common/CMStateSet.hpp>
28 #include <xercesc/validators/common/CMAny.hpp>
29
30 XERCES_CPP_NAMESPACE_BEGIN
31
32 // ---------------------------------------------------------------------------
33 // CMUnaryOp: Constructors and Destructor
34 // ---------------------------------------------------------------------------
CMAny(ContentSpecNode::NodeTypes type,unsigned int URI,unsigned int position,unsigned int maxStates,MemoryManager * const manager)35 CMAny::CMAny( ContentSpecNode::NodeTypes type
36 , unsigned int URI
37 , unsigned int position
38 , unsigned int maxStates
39 , MemoryManager* const manager) :
40 CMNode(type, maxStates, manager)
41 , fURI(URI)
42 , fPosition(position)
43 {
44 if ((type & 0x0f) != ContentSpecNode::Any
45 && (type & 0x0f) != ContentSpecNode::Any_Other
46 && (type & 0x0f) != ContentSpecNode::Any_NS)
47 {
48 ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::CM_NotValidSpecTypeForNode,
49 "CMAny", manager);
50 }
51 // Leaf nodes are never nullable unless its an epsilon node
52 fIsNullable=(fPosition == epsilonNode);
53 }
54
~CMAny()55 CMAny::~CMAny()
56 {
57 }
58
59 // ---------------------------------------------------------------------------
60 // Getter methods
61 // ---------------------------------------------------------------------------
getURI() const62 unsigned int CMAny::getURI() const
63 {
64 return fURI;
65 }
66
getPosition() const67 unsigned int CMAny::getPosition() const
68 {
69 return fPosition;
70 }
71
72 // ---------------------------------------------------------------------------
73 // Setter methods
74 // ---------------------------------------------------------------------------
setPosition(const unsigned int newPosition)75 void CMAny::setPosition(const unsigned int newPosition)
76 {
77 fPosition = newPosition;
78 }
79
80 // ---------------------------------------------------------------------------
81 // Implementation of public CMNode virtual interface
82 // ---------------------------------------------------------------------------
orphanChild()83 void CMAny::orphanChild()
84 {
85 }
86
87 // ---------------------------------------------------------------------------
88 // Implementation of protected CMNode virtual interface
89 // ---------------------------------------------------------------------------
calcFirstPos(CMStateSet & toSet) const90 void CMAny::calcFirstPos(CMStateSet& toSet) const
91 {
92 // If we are an epsilon node, then the first pos is an empty set
93 if (isNullable())
94 toSet.zeroBits();
95 else
96 // Otherwise, its just the one bit of our position
97 toSet.setBit(fPosition);
98 }
99
calcLastPos(CMStateSet & toSet) const100 void CMAny::calcLastPos(CMStateSet& toSet) const
101 {
102 // If we are an epsilon node, then the last pos is an empty set
103 if (isNullable())
104 toSet.zeroBits();
105 // Otherwise, its just the one bit of our position
106 else
107 toSet.setBit(fPosition);
108 }
109
110 XERCES_CPP_NAMESPACE_END
111