source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/validators/common/ContentSpecNode.hpp @ 2674

Revision 2674, 12.5 KB checked in by mattausch, 16 years ago (diff)
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: ContentSpecNode.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#if !defined(CONTENTSPECNODE_HPP)
24#define CONTENTSPECNODE_HPP
25
26#include <xercesc/framework/XMLElementDecl.hpp>
27#include <xercesc/framework/MemoryManager.hpp>
28
29#include <xercesc/internal/XSerializable.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33class XMLBuffer;
34class Grammar;
35
36
37class XMLUTIL_EXPORT ContentSpecNode : public XSerializable, public XMemory
38{
39public :
40    // -----------------------------------------------------------------------
41    //  Class specific types
42    // -----------------------------------------------------------------------
43    enum NodeTypes
44    {
45        Leaf = 0
46        , ZeroOrOne
47        , ZeroOrMore
48        , OneOrMore
49        , Choice
50        , Sequence
51        , Any
52        , Any_Other
53        , Any_NS = 8
54        , All = 9
55        , Any_NS_Choice = 20
56        , ModelGroupSequence = 21
57        , Any_Lax = 22
58        , Any_Other_Lax = 23
59        , Any_NS_Lax = 24
60        , ModelGroupChoice = 36
61        , Any_Skip = 38
62        , Any_Other_Skip = 39
63        , Any_NS_Skip = 40
64
65        , UnknownType = -1
66    };
67
68
69    // -----------------------------------------------------------------------
70    //  Constructors and Destructor
71    // -----------------------------------------------------------------------
72    ContentSpecNode(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
73    ContentSpecNode
74    (
75        QName* const toAdopt
76        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
77    );
78    ContentSpecNode
79    (
80        XMLElementDecl* const elemDecl
81        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
82    );
83    ContentSpecNode
84    (
85        QName* const toAdopt
86        , const bool copyQName
87        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
88    );
89    ContentSpecNode
90    (
91        const   NodeTypes               type
92        ,       ContentSpecNode* const  firstToAdopt
93        ,       ContentSpecNode* const  secondToAdopt
94        , const bool                    adoptFirst = true
95        , const bool                    adoptSecond = true
96        ,       MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
97    );
98    ContentSpecNode(const ContentSpecNode&);
99        ~ContentSpecNode();
100
101    // -----------------------------------------------------------------------
102    //  Getter methods
103    // -----------------------------------------------------------------------
104    QName* getElement();
105    const QName* getElement() const;
106    XMLElementDecl* getElementDecl();
107    const XMLElementDecl* getElementDecl() const;
108    ContentSpecNode* getFirst();
109    const ContentSpecNode* getFirst() const;
110    ContentSpecNode* getSecond();
111    const ContentSpecNode* getSecond() const;
112    NodeTypes getType() const;
113    ContentSpecNode* orphanFirst();
114    ContentSpecNode* orphanSecond();
115    int getMinOccurs() const;
116    int getMaxOccurs() const;
117    bool isFirstAdopted() const;
118    bool isSecondAdopted() const;
119
120
121    // -----------------------------------------------------------------------
122    //  Setter methods
123    // -----------------------------------------------------------------------
124    void setElement(QName* const toAdopt);
125    void setFirst(ContentSpecNode* const toAdopt);
126    void setSecond(ContentSpecNode* const toAdopt);
127    void setType(const NodeTypes type);
128    void setMinOccurs(int min);
129    void setMaxOccurs(int max);
130    void setAdoptFirst(bool adoptFirst);
131    void setAdoptSecond(bool adoptSecond);
132
133
134    // -----------------------------------------------------------------------
135    //  Miscellaneous
136    // -----------------------------------------------------------------------
137    void formatSpec (XMLBuffer&      bufToFill)   const;
138    bool hasAllContent();
139    int  getMinTotalRange() const;
140    int  getMaxTotalRange() const;
141
142    /***
143     * Support for Serialization/De-serialization
144     ***/
145    DECL_XSERIALIZABLE(ContentSpecNode)
146
147private :
148    // -----------------------------------------------------------------------
149    //  Unimplemented constructors and operators
150    // -----------------------------------------------------------------------
151    ContentSpecNode& operator=(const ContentSpecNode&);
152
153
154    // -----------------------------------------------------------------------
155    //  Private Data Members
156    //
157    //  fElement
158    //      If the type is Leaf/Any*, then this is the qName of the element. If the URI
159    //      is fgPCDataElemId, then its a PCData node.  Else, it is zero.
160    //
161    //  fFirst
162    //  fSecond
163    //      The optional first and second nodes. The fType field indicates
164    //      which of these are valid. The validaty constraints are:
165    //
166    //          Leaf = Neither valid
167    //          ZeroOrOne, ZeroOrMore = First
168    //          Choice, Sequence, All = First and Second
169    //          Any* = Neither valid
170    //
171    //  fType
172    //      The type of node. This controls how many of the child node fields
173    //      are used.
174    //
175    //  fAdoptFirst
176    //      Indicate if this ContentSpecNode adopts the fFirst, and is responsible
177    //      for deleting it.
178    //
179    //  fAdoptSecond
180    //      Indicate if this ContentSpecNode adopts the fSecond, and is responsible
181    //      for deleting it.
182    //
183    //  fMinOccurs
184    //      Indicate the minimum times that this node can occur
185    //
186    //  fMaxOccurs
187    //      Indicate the maximum times that this node can occur
188    //      -1 (Unbounded), default (1)
189    // -----------------------------------------------------------------------
190    MemoryManager*      fMemoryManager;
191    QName*              fElement;
192    XMLElementDecl*     fElementDecl;
193    ContentSpecNode*    fFirst;
194    ContentSpecNode*    fSecond;
195    NodeTypes           fType;
196    bool                fAdoptFirst;
197    bool                fAdoptSecond;
198    int                 fMinOccurs;
199    int                 fMaxOccurs;
200};
201
202// ---------------------------------------------------------------------------
203//  ContentSpecNode: Constructors and Destructor
204// ---------------------------------------------------------------------------
205inline ContentSpecNode::ContentSpecNode(MemoryManager* const manager) :
206
207    fMemoryManager(manager)
208    , fElement(0)
209    , fElementDecl(0)
210    , fFirst(0)
211    , fSecond(0)
212    , fType(ContentSpecNode::Leaf)
213    , fAdoptFirst(true)
214    , fAdoptSecond(true)
215    , fMinOccurs(1)
216    , fMaxOccurs(1)
217{
218}
219
220inline
221ContentSpecNode::ContentSpecNode(QName* const element,
222                                 MemoryManager* const manager) :
223
224    fMemoryManager(manager)
225    , fElement(0)
226    , fElementDecl(0)
227    , fFirst(0)
228    , fSecond(0)
229    , fType(ContentSpecNode::Leaf)
230    , fAdoptFirst(true)
231    , fAdoptSecond(true)
232    , fMinOccurs(1)
233    , fMaxOccurs(1)
234{
235    if (element)
236        fElement = new (fMemoryManager) QName(*element);
237}
238
239inline
240ContentSpecNode::ContentSpecNode(XMLElementDecl* const elemDecl,
241                                 MemoryManager* const manager) :
242
243    fMemoryManager(manager)
244    , fElement(0)
245    , fElementDecl(elemDecl)
246    , fFirst(0)
247    , fSecond(0)
248    , fType(ContentSpecNode::Leaf)
249    , fAdoptFirst(true)
250    , fAdoptSecond(true)
251    , fMinOccurs(1)
252    , fMaxOccurs(1)
253{
254    if (elemDecl)
255        fElement = new (manager) QName(*(elemDecl->getElementName()));
256}
257
258inline
259ContentSpecNode::ContentSpecNode( QName* const element
260                                , const bool copyQName
261                                , MemoryManager* const manager) :
262
263    fMemoryManager(manager)
264    , fElement(0)
265    , fElementDecl(0)
266    , fFirst(0)
267    , fSecond(0)
268    , fType(ContentSpecNode::Leaf)
269    , fAdoptFirst(true)
270    , fAdoptSecond(true)
271    , fMinOccurs(1)
272    , fMaxOccurs(1)
273{
274    if (copyQName)
275    {
276        if (element)
277            fElement = new (fMemoryManager) QName(*element);
278    }
279    else
280    {
281        fElement = element;
282    }
283}
284
285inline
286ContentSpecNode::ContentSpecNode(const  NodeTypes              type
287                                ,       ContentSpecNode* const firstAdopt
288                                ,       ContentSpecNode* const secondAdopt
289                                , const bool                   adoptFirst
290                                , const bool                   adoptSecond
291                                ,       MemoryManager* const   manager) :
292
293    fMemoryManager(manager)
294    , fElement(0)
295    , fElementDecl(0)
296    , fFirst(firstAdopt)
297    , fSecond(secondAdopt)
298    , fType(type)
299    , fAdoptFirst(adoptFirst)
300    , fAdoptSecond(adoptSecond)
301    , fMinOccurs(1)
302    , fMaxOccurs(1)
303{
304}
305
306inline ContentSpecNode::~ContentSpecNode()
307{
308    // Delete our children, which cause recursive cleanup
309    if (fAdoptFirst) {
310                delete fFirst;
311    }
312
313    if (fAdoptSecond) {
314                delete fSecond;
315    }
316
317    delete fElement;
318}
319
320// ---------------------------------------------------------------------------
321//  ContentSpecNode: Getter methods
322// ---------------------------------------------------------------------------
323inline QName* ContentSpecNode::getElement()
324{
325    return fElement;
326}
327
328inline const QName* ContentSpecNode::getElement() const
329{
330    return fElement;
331}
332
333inline XMLElementDecl* ContentSpecNode::getElementDecl()
334{
335    return fElementDecl;
336}
337
338inline const XMLElementDecl* ContentSpecNode::getElementDecl() const
339{
340    return fElementDecl;
341}
342
343inline ContentSpecNode* ContentSpecNode::getFirst()
344{
345    return fFirst;
346}
347
348inline const ContentSpecNode* ContentSpecNode::getFirst() const
349{
350    return fFirst;
351}
352
353inline ContentSpecNode* ContentSpecNode::getSecond()
354{
355    return fSecond;
356}
357
358inline const ContentSpecNode* ContentSpecNode::getSecond() const
359{
360    return fSecond;
361}
362
363inline ContentSpecNode::NodeTypes ContentSpecNode::getType() const
364{
365    return fType;
366}
367
368inline ContentSpecNode* ContentSpecNode::orphanFirst()
369{
370    ContentSpecNode* retNode = fFirst;
371    fFirst = 0;
372    return retNode;
373}
374
375inline ContentSpecNode* ContentSpecNode::orphanSecond()
376{
377    ContentSpecNode* retNode = fSecond;
378    fSecond = 0;
379    return retNode;
380}
381
382inline int ContentSpecNode::getMinOccurs() const
383{
384    return fMinOccurs;
385}
386
387inline int ContentSpecNode::getMaxOccurs() const
388{
389    return fMaxOccurs;
390}
391
392inline bool ContentSpecNode::isFirstAdopted() const
393{
394    return fAdoptFirst;
395}
396
397inline bool ContentSpecNode::isSecondAdopted() const
398{
399    return fAdoptSecond;
400}
401
402
403// ---------------------------------------------------------------------------
404//  ContentSpecType: Setter methods
405// ---------------------------------------------------------------------------
406inline void ContentSpecNode::setElement(QName* const element)
407{
408    delete fElement;
409    fElement = 0;
410    if (element)
411        fElement = new (fMemoryManager) QName(*element);
412}
413
414inline void ContentSpecNode::setFirst(ContentSpecNode* const toAdopt)
415{
416    if (fAdoptFirst)
417        delete fFirst;
418    fFirst = toAdopt;
419}
420
421inline void ContentSpecNode::setSecond(ContentSpecNode* const toAdopt)
422{
423    if (fAdoptSecond)
424        delete fSecond;
425    fSecond = toAdopt;
426}
427
428inline void ContentSpecNode::setType(const NodeTypes type)
429{
430    fType = type;
431}
432
433inline void ContentSpecNode::setMinOccurs(int min)
434{
435    fMinOccurs = min;
436}
437
438inline void ContentSpecNode::setMaxOccurs(int max)
439{
440    fMaxOccurs = max;
441}
442
443inline void ContentSpecNode::setAdoptFirst(bool newState)
444{
445    fAdoptFirst = newState;
446}
447
448inline void ContentSpecNode::setAdoptSecond(bool newState)
449{
450    fAdoptSecond = newState;
451}
452
453// ---------------------------------------------------------------------------
454//  ContentSpecNode: Miscellaneous
455// ---------------------------------------------------------------------------
456inline bool ContentSpecNode::hasAllContent() {
457
458    if (fType == ContentSpecNode::ZeroOrOne) {
459        return (fFirst->getType() == ContentSpecNode::All);
460    }
461
462    return (fType == ContentSpecNode::All);
463}
464
465XERCES_CPP_NAMESPACE_END
466
467#endif
Note: See TracBrowser for help on using the repository browser.