source: icXML/icXML-devel/src/xercesc/validators/common/CMNode.hpp @ 2722

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

Original Xerces files with import mods for icxercesc

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