[2674] | 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: CMNode.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #if !defined(CMNODE_HPP) |
---|
| 23 | #define CMNODE_HPP |
---|
| 24 | |
---|
| 25 | #include <xercesc/validators/common/ContentSpecNode.hpp> |
---|
| 26 | #include <xercesc/validators/common/CMStateSet.hpp> |
---|
| 27 | |
---|
| 28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 29 | |
---|
| 30 | class CMNode : public XMemory |
---|
| 31 | { |
---|
| 32 | public : |
---|
| 33 | // ----------------------------------------------------------------------- |
---|
| 34 | // Constructors and Destructors |
---|
| 35 | // ----------------------------------------------------------------------- |
---|
| 36 | CMNode |
---|
| 37 | ( |
---|
| 38 | const ContentSpecNode::NodeTypes type |
---|
| 39 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 40 | ); |
---|
| 41 | virtual ~CMNode(); |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | // ----------------------------------------------------------------------- |
---|
| 45 | // Virtual methods to be provided derived node classes |
---|
| 46 | // ----------------------------------------------------------------------- |
---|
| 47 | virtual bool isNullable() const = 0; |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | // ----------------------------------------------------------------------- |
---|
| 51 | // Getter methods |
---|
| 52 | // ----------------------------------------------------------------------- |
---|
| 53 | ContentSpecNode::NodeTypes getType() const; |
---|
| 54 | const CMStateSet& getFirstPos() const; |
---|
| 55 | const CMStateSet& getLastPos() const; |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | // ----------------------------------------------------------------------- |
---|
| 59 | // Setter methods |
---|
| 60 | // ----------------------------------------------------------------------- |
---|
| 61 | void setMaxStates(const unsigned int maxStates); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | protected : |
---|
| 65 | // ----------------------------------------------------------------------- |
---|
| 66 | // Protected, abstract methods |
---|
| 67 | // ----------------------------------------------------------------------- |
---|
| 68 | virtual void calcFirstPos(CMStateSet& toUpdate) const = 0; |
---|
| 69 | virtual void calcLastPos(CMStateSet& toUpdate) const = 0; |
---|
| 70 | |
---|
| 71 | // ----------------------------------------------------------------------- |
---|
| 72 | // Protected data members |
---|
| 73 | // |
---|
| 74 | // fMemoryManager |
---|
| 75 | // Pluggable memory manager for dynamic allocation/deallocation. |
---|
| 76 | // ----------------------------------------------------------------------- |
---|
| 77 | MemoryManager* fMemoryManager; |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | private : |
---|
| 81 | // ----------------------------------------------------------------------- |
---|
| 82 | // Unimplemented constructors and operators |
---|
| 83 | // ----------------------------------------------------------------------- |
---|
| 84 | CMNode(); |
---|
| 85 | CMNode(const CMNode&); |
---|
| 86 | CMNode& operator=(const CMNode&); |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | // ----------------------------------------------------------------------- |
---|
| 90 | // Private data members |
---|
| 91 | // |
---|
| 92 | // fType |
---|
| 93 | // The type of node. This indicates whether its a leaf or an |
---|
| 94 | // operation. |
---|
| 95 | // |
---|
| 96 | // fFirstPos |
---|
| 97 | // The set of NFA states that represent the entry states of this |
---|
| 98 | // node in the DFA. |
---|
| 99 | // |
---|
| 100 | // fLastPos |
---|
| 101 | // The set of NFA states that represent the final states of this |
---|
| 102 | // node in the DFA. |
---|
| 103 | // |
---|
| 104 | // fMaxStates |
---|
| 105 | // The maximum number of states that the NFA has, which means the |
---|
| 106 | // max number of NFA states that have to be traced in the state |
---|
| 107 | // sets during the building of the DFA. Its unfortunate that it |
---|
| 108 | // has to be stored redundantly, but we need to fault in the |
---|
| 109 | // state set members and they have to be sized to this size. |
---|
| 110 | // ----------------------------------------------------------------------- |
---|
| 111 | ContentSpecNode::NodeTypes fType; |
---|
| 112 | CMStateSet* fFirstPos; |
---|
| 113 | CMStateSet* fLastPos; |
---|
| 114 | unsigned int fMaxStates; |
---|
| 115 | }; |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | // --------------------------------------------------------------------------- |
---|
| 120 | // CMNode: Constructors and Destructors |
---|
| 121 | // --------------------------------------------------------------------------- |
---|
| 122 | inline CMNode::CMNode(const ContentSpecNode::NodeTypes type, |
---|
| 123 | MemoryManager* const manager) : |
---|
| 124 | |
---|
| 125 | fMemoryManager(manager) |
---|
| 126 | , fType(type) |
---|
| 127 | , fFirstPos(0) |
---|
| 128 | , fLastPos(0) |
---|
| 129 | , fMaxStates(~0) |
---|
| 130 | { |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | inline CMNode::~CMNode() |
---|
| 134 | { |
---|
| 135 | // Clean up any position sets that got created |
---|
| 136 | delete fFirstPos; |
---|
| 137 | delete fLastPos; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | // --------------------------------------------------------------------------- |
---|
| 142 | // CMNode: Getter methods |
---|
| 143 | // --------------------------------------------------------------------------- |
---|
| 144 | inline ContentSpecNode::NodeTypes CMNode::getType() const |
---|
| 145 | { |
---|
| 146 | return fType; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | inline const CMStateSet& CMNode::getFirstPos() const |
---|
| 150 | { |
---|
| 151 | // |
---|
| 152 | // Fault in the state set if needed. Since we can't use mutable members |
---|
| 153 | // cast off the const'ness. |
---|
| 154 | // |
---|
| 155 | if (!fFirstPos) |
---|
| 156 | { |
---|
| 157 | CMNode* unconstThis = (CMNode*)this; |
---|
| 158 | unconstThis->fFirstPos = new (fMemoryManager) CMStateSet(fMaxStates, fMemoryManager); |
---|
| 159 | unconstThis->calcFirstPos(*fFirstPos); |
---|
| 160 | } |
---|
| 161 | return *fFirstPos; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | inline const CMStateSet& CMNode::getLastPos() const |
---|
| 165 | { |
---|
| 166 | // |
---|
| 167 | // Fault in the state set if needed. Since we can't use mutable members |
---|
| 168 | // cast off the const'ness. |
---|
| 169 | // |
---|
| 170 | if (!fLastPos) |
---|
| 171 | { |
---|
| 172 | CMNode* unconstThis = (CMNode*)this; |
---|
| 173 | unconstThis->fLastPos = new (fMemoryManager) CMStateSet(fMaxStates, fMemoryManager); |
---|
| 174 | unconstThis->calcLastPos(*fLastPos); |
---|
| 175 | } |
---|
| 176 | return *fLastPos; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | // --------------------------------------------------------------------------- |
---|
| 181 | // CMNode: Setter methods |
---|
| 182 | // --------------------------------------------------------------------------- |
---|
| 183 | inline void CMNode::setMaxStates(const unsigned int maxStates) |
---|
| 184 | { |
---|
| 185 | fMaxStates = maxStates; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | XERCES_CPP_NAMESPACE_END |
---|
| 189 | |
---|
| 190 | #endif |
---|