source: NonGTP/Xerces/xerces/include/xercesc/validators/common/CMNode.hpp @ 358

Revision 358, 7.9 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Log: CMNode.hpp,v $
19 * Revision 1.6  2004/09/08 13:56:51  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.5  2003/05/16 21:43:20  knoaman
23 * Memory manager implementation: Modify constructors to pass in the memory manager.
24 *
25 * Revision 1.4  2003/05/15 18:48:27  knoaman
26 * Partial implementation of the configurable memory manager.
27 *
28 * Revision 1.3  2003/03/07 18:16:57  tng
29 * Return a reference instead of void for operator=
30 *
31 * Revision 1.2  2002/11/04 14:54:58  tng
32 * C++ Namespace Support.
33 *
34 * Revision 1.1.1.1  2002/02/01 22:22:38  peiyongz
35 * sane_include
36 *
37 * Revision 1.3  2001/05/11 13:27:17  tng
38 * Copyright update.
39 *
40 * Revision 1.2  2001/02/16 14:58:57  tng
41 * Schema: Update Makefile, configure files, project files, and include path in
42 * certain cpp files because of the move of the common Content Model files.  By Pei Yong Zhang.
43 *
44 * Revision 1.1  2001/02/16 14:17:29  tng
45 * Schema: Move the common Content Model files that are shared by DTD
46 * and schema from 'DTD' folder to 'common' folder.  By Pei Yong Zhang.
47 *
48 * Revision 1.5  2000/03/28 19:43:25  roddey
49 * Fixes for signed/unsigned warnings. New work for two way transcoding
50 * stuff.
51 *
52 * Revision 1.4  2000/03/02 19:55:37  roddey
53 * This checkin includes many changes done while waiting for the
54 * 1.1.0 code to be finished. I can't list them all here, but a list is
55 * available elsewhere.
56 *
57 * Revision 1.3  2000/02/24 20:16:48  abagchi
58 * Swat for removing Log from API docs
59 *
60 * Revision 1.2  2000/02/09 21:42:36  abagchi
61 * Copyright swat
62 *
63 * Revision 1.1.1.1  1999/11/09 01:03:05  twl
64 * Initial checkin
65 *
66 * Revision 1.2  1999/11/08 20:45:36  rahul
67 * Swat for adding in Product name and CVS comment log variable.
68 *
69 */
70
71#if !defined(CMNODE_HPP)
72#define CMNODE_HPP
73
74#include <xercesc/validators/common/ContentSpecNode.hpp>
75#include <xercesc/validators/common/CMStateSet.hpp>
76
77XERCES_CPP_NAMESPACE_BEGIN
78
79class CMNode : public XMemory
80{
81public :
82    // -----------------------------------------------------------------------
83    //  Constructors and Destructors
84    // -----------------------------------------------------------------------
85    CMNode
86    (
87        const ContentSpecNode::NodeTypes type
88        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
89    );
90    virtual ~CMNode();
91
92
93    // -----------------------------------------------------------------------
94    //  Virtual methods to be provided derived node classes
95    // -----------------------------------------------------------------------
96    virtual bool isNullable() const = 0;
97
98
99    // -----------------------------------------------------------------------
100    //  Getter methods
101    // -----------------------------------------------------------------------
102    ContentSpecNode::NodeTypes getType() const;
103    const CMStateSet& getFirstPos() const;
104    const CMStateSet& getLastPos() const;
105
106
107    // -----------------------------------------------------------------------
108    //  Setter methods
109    // -----------------------------------------------------------------------
110    void setMaxStates(const unsigned int maxStates);
111
112
113protected :
114    // -----------------------------------------------------------------------
115    //  Protected, abstract methods
116    // -----------------------------------------------------------------------
117    virtual void calcFirstPos(CMStateSet& toUpdate) const = 0;
118    virtual void calcLastPos(CMStateSet& toUpdate) const = 0;
119
120    // -----------------------------------------------------------------------
121    //  Protected data members
122    //
123    //  fMemoryManager
124    //      Pluggable memory manager for dynamic allocation/deallocation.
125    // -----------------------------------------------------------------------
126    MemoryManager*             fMemoryManager;
127
128
129private :
130    // -----------------------------------------------------------------------
131    //  Unimplemented constructors and operators
132    // -----------------------------------------------------------------------
133    CMNode();
134    CMNode(const CMNode&);
135    CMNode& operator=(const CMNode&);
136
137
138    // -----------------------------------------------------------------------
139    //  Private data members
140    //
141    //  fType
142    //      The type of node. This indicates whether its a leaf or an
143    //      operation.
144    //
145    //  fFirstPos
146    //      The set of NFA states that represent the entry states of this
147    //      node in the DFA.
148    //
149    //  fLastPos
150    //      The set of NFA states that represent the final states of this
151    //      node in the DFA.
152    //
153    //  fMaxStates
154    //      The maximum number of states that the NFA has, which means the
155    //      max number of NFA states that have to be traced in the state
156    //      sets during the building of the DFA. Its unfortunate that it
157    //      has to be stored redundantly, but we need to fault in the
158    //      state set members and they have to be sized to this size.
159    // -----------------------------------------------------------------------
160    ContentSpecNode::NodeTypes fType;
161    CMStateSet*                fFirstPos;
162    CMStateSet*                fLastPos;
163    unsigned int               fMaxStates;
164};
165
166
167
168// ---------------------------------------------------------------------------
169//  CMNode: Constructors and Destructors
170// ---------------------------------------------------------------------------
171inline CMNode::CMNode(const ContentSpecNode::NodeTypes type,
172                      MemoryManager* const manager) :
173
174    fMemoryManager(manager)
175    , fType(type)
176    , fFirstPos(0)
177    , fLastPos(0)
178    , fMaxStates(~0)
179{
180}
181
182inline CMNode::~CMNode()
183{
184    // Clean up any position sets that got created
185    delete fFirstPos;
186    delete fLastPos;
187}
188
189
190// ---------------------------------------------------------------------------
191//  CMNode: Getter methods
192// ---------------------------------------------------------------------------
193inline ContentSpecNode::NodeTypes CMNode::getType() const
194{
195    return fType;
196}
197
198inline const CMStateSet& CMNode::getFirstPos() const
199{
200    //
201    //  Fault in the state set if needed. Since we can't use mutable members
202    //  cast off the const'ness.
203    //
204    if (!fFirstPos)
205    {
206        CMNode* unconstThis = (CMNode*)this;
207        unconstThis->fFirstPos = new (fMemoryManager) CMStateSet(fMaxStates, fMemoryManager);
208        unconstThis->calcFirstPos(*fFirstPos);
209    }
210    return *fFirstPos;
211}
212
213inline const CMStateSet& CMNode::getLastPos() const
214{
215    //
216    //  Fault in the state set if needed. Since we can't use mutable members
217    //  cast off the const'ness.
218    //
219    if (!fLastPos)
220    {
221        CMNode* unconstThis = (CMNode*)this;
222        unconstThis->fLastPos = new (fMemoryManager) CMStateSet(fMaxStates, fMemoryManager);
223        unconstThis->calcLastPos(*fLastPos);
224    }
225    return *fLastPos;
226}
227
228
229// ---------------------------------------------------------------------------
230//  CMNode: Setter methods
231// ---------------------------------------------------------------------------
232inline void CMNode::setMaxStates(const unsigned int maxStates)
233{
234    fMaxStates = maxStates;
235}
236
237XERCES_CPP_NAMESPACE_END
238
239#endif
Note: See TracBrowser for help on using the repository browser.