source: icXML/icXML-devel/src/icxercesc/internal/ElemStack.hpp

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

Initial imports for icXML v0.9

File size: 15.1 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: ElemStack.hpp 830538 2009-10-28 13:41:11Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_ELEMSTACK_HPP)
23#define XERCESC_INCLUDE_GUARD_ELEMSTACK_HPP
24
25#include <xercesc/util/StringPool.hpp>
26#include <icxercesc/util/QName.hpp>
27#include <xercesc/util/ValueVectorOf.hpp>
28#include <icxmlc/XMLConfig.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32class XMLElementDecl;
33class Grammar;
34
35struct PrefMapElem : public XMemory
36{
37        unsigned int        fPrefId;
38        unsigned int        fURIId;
39};
40
41//
42//  During the scan of content, we have to keep up with the nesting of
43//  elements (for validation and wellformedness purposes) and we have to
44//  have places to remember namespace (prefix to URI) mappings.
45//
46//  We only have to keep a stack of the current path down through the tree
47//  that we are currently scanning, and keep track of any children of any
48//  elements along that path.
49//
50//  So, this data structure is a stack, which represents the current path
51//  through the tree that we've worked our way down to. For each node in
52//  the stack, there is an array of element ids that represent the ids of
53//  the child elements scanned so far. Upon exit from that element, its
54//  array of child elements is validated.
55//
56//  Since we have the actual XMLElementDecl in the stack nodes, when its time
57//  to validate, we just extract the content model from that element decl
58//  and validate. All the required data falls easily to hand. Note that we
59//  actually have some derivative of XMLElementDecl, which is specific to
60//  the validator used, but the abstract API is sufficient for the needs of
61//  the scanner.
62//
63//  Since the namespace support also requires the storage of information on
64//  a nested element basis, this structure also holds the namespace info. For
65//  each level, the prefixes defined at that level (and the namespaces that
66//  they map to) are stored.
67//
68class XMLPARSER_EXPORT ElemStack : public XMemory
69{
70public :
71        // -----------------------------------------------------------------------
72        //  Class specific data types
73        //
74        //  These really should be private, but some of the compilers we have to
75        //  support are too dumb to deal with that.
76        //
77        //  PrefMapElem
78        //      fURIId is the id of the URI from the validator's URI map. The
79        //      fPrefId is the id of the prefix from our own prefix pool. The
80        //      namespace stack consists of these elements.
81        //
82        //  StackElem
83        //      fThisElement is the basic element decl for the current element.
84        //      The fRowCapacity is how large fChildIds has grown so far.
85        //      fChildCount is how many of them are valid right now.
86        //
87        //      The fMapCapacity is how large fMap has grown so far. fMapCount
88        //      is how many of them are valid right now.
89        //
90        //      Note that we store the reader number we were in when we found the
91        //      start tag. We'll use this at the end tag to test for unbalanced
92        //      markup in entities.
93        //
94        //  MapModes
95        //      When a prefix is mapped to a namespace id, it matters whether the
96        //      QName being mapped is an attribute or name. Attributes are not
97        //      affected by an sibling xmlns attributes, whereas elements are
98        //      affected by its own xmlns attributes.
99        // -----------------------------------------------------------------------
100        struct StackElem : public XMemory
101        {
102                XMLElementDecl*     fThisElement;
103                bool                fValidationFlag;
104                unsigned int        fCurrentScope;
105                Grammar*            fCurrentGrammar;
106        };
107
108        enum MapModes
109        {
110                Mode_Attribute
111                , Mode_Element
112        };
113
114
115        // -----------------------------------------------------------------------
116        //  Constructors and Destructor
117        // -----------------------------------------------------------------------
118        ElemStack(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
119        ~ElemStack();
120
121
122        // -----------------------------------------------------------------------
123        //  Stack access
124        // -----------------------------------------------------------------------
125        XMLSize_t addLevel();
126        XMLSize_t addLevel(XMLElementDecl* const toSet, const XMLSize_t readerNum);
127        XMLSize_t getLevel() const;
128
129        const StackElem* popTop();
130
131
132        // -----------------------------------------------------------------------
133        //  Stack top access
134        // -----------------------------------------------------------------------
135        XMLSize_t addChild(QName* const child, const bool toParent);
136        const StackElem* topElement() const;
137        void setElement(XMLElementDecl* const toSet, const XMLSize_t readerNum);
138
139        void setValidationFlag(bool validationFlag);
140        bool getValidationFlag();
141
142        inline void setCommentOrPISeen();
143        inline bool getCommentOrPISeen() const;
144
145        inline void setReferenceEscaped();
146        inline bool getReferenceEscaped() const;
147
148        void setCurrentScope(int currentScope);
149        int getCurrentScope();
150
151        void setPrefixColonPos(int colonPos); // DEPRECATED BUT KEPT FOR DLL COMPATIBILITY
152        int getPrefixColonPos() const; // DEPRECATED BUT KEPT FOR DLL COMPATIBILITY
153
154        void setCurrentGrammar(Grammar* currentGrammar);
155        Grammar* getCurrentGrammar();
156
157        void setCurrentURI(unsigned int uri);
158        unsigned int getCurrentURI();
159
160        inline void setCurrentSchemaElemName(const XMLCh * const schemaElemName);
161        inline XMLCh *getCurrentSchemaElemName();
162
163        // -----------------------------------------------------------------------
164        //  Prefix map methods
165        // -----------------------------------------------------------------------
166        void addGlobalPrefix
167        (
168                const   XMLCh* const    prefixToAdd
169                , const unsigned int    uriId
170        );
171        void addPrefix
172        (
173                const   XMLCh* const    prefixToAdd
174                , const unsigned int    uriId
175        );
176
177        unsigned int mapPrefixToURI
178        (
179                const   XMLCh* const    prefixToMap
180                ,       bool&           unknown
181        )   const;
182
183        ValueVectorOf<PrefMapElem*>* getNamespaceMap() const;
184        unsigned int getPrefixId(const XMLCh* const prefix) const;
185        const XMLCh* getPrefixForId(unsigned int prefId) const;
186
187        // -----------------------------------------------------------------------
188        //  Miscellaneous methods
189        // -----------------------------------------------------------------------
190        bool isEmpty() const;
191        void reset
192        (
193                const   unsigned int    emptyId
194                , const unsigned int    unknownId
195                , const unsigned int    xmlId
196                , const unsigned int    xmlNSId
197        );
198
199        unsigned int getEmptyNamespaceId();
200
201private :
202        // -----------------------------------------------------------------------
203        //  Unimplemented constructors and operators
204        // -----------------------------------------------------------------------
205        ElemStack(const ElemStack&);
206        ElemStack& operator=(const ElemStack&);
207
208
209        // -----------------------------------------------------------------------
210        //  Private helper methods
211        // -----------------------------------------------------------------------
212        void expandMap(StackElem* const toExpand);
213        void expandStack();
214
215
216        // -----------------------------------------------------------------------
217        //  Data members
218        //
219        //  fStack
220        //  fStackCapacity
221        //  fStackTop
222        //      This the stack array. Its an array of pointers to StackElem
223        //      structures. The capacity is the current high water mark of the
224        //      stack. The top is the current top of stack (i.e. the part of it
225        //      being used.)
226        //
227        // -----------------------------------------------------------------------
228        StackElem**                  fStack;
229        XMLSize_t                    fStackCapacity;
230        XMLSize_t                    fStackTop;
231        MemoryManager*               fMemoryManager;
232};
233
234// ---------------------------------------------------------------------------
235//  ElemStack: Miscellaneous methods
236// ---------------------------------------------------------------------------
237inline bool ElemStack::isEmpty() const
238{
239        return (fStackTop == 0);
240}
241
242inline XMLSize_t ElemStack::getLevel() const
243{
244        return fStackTop - 1;
245}
246
247inline bool ElemStack::getValidationFlag()
248{
249        return fStack[fStackTop - 1]->fValidationFlag;
250}
251
252inline void ElemStack::setValidationFlag(bool validationFlag)
253{
254        fStack[fStackTop-1]->fValidationFlag = validationFlag;
255}
256
257inline void ElemStack::setCurrentSchemaElemName(const XMLCh * const schemaElemName)
258{
259        #ifdef PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER
260        DEPRECATED_FEATURE_IN_ICXML;
261        #else
262        fStack[fStackTop - 1]->fSchemaElemName = schemaElemName;
263        #endif
264}
265
266inline XMLCh * ElemStack::getCurrentSchemaElemName()
267{
268        #ifdef PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER
269        DEPRECATED_FEATURE_IN_ICXML;
270        #else
271        return const_cast<XMLCh*>(fStack[fStackTop - 1]->fSchemaElemName);
272        #endif
273}
274
275inline int ElemStack::getCurrentScope()
276{
277        return fStack[fStackTop - 1]->fCurrentScope;
278}
279
280inline void ElemStack::setCurrentScope(int currentScope)
281{
282        fStack[fStackTop - 1]->fCurrentScope = currentScope;
283}
284
285inline Grammar * ElemStack::getCurrentGrammar()
286{
287        return fStack[fStackTop - 1]->fCurrentGrammar;
288}
289
290inline void ElemStack::setCurrentGrammar(Grammar* currentGrammar)
291{
292        fStack[fStackTop - 1]->fCurrentGrammar = currentGrammar;
293}
294
295// --------------------------------------------------------------------------
296// DEPRECATED BUT KEPT FOR DLL COMPATIBILITY
297// --------------------------------------------------------------------------
298
299inline unsigned int ElemStack::getCurrentURI()
300{
301        DEPRECATED_FEATURE_IN_ICXML;
302}
303
304inline void ElemStack::setCurrentURI(unsigned int)
305{
306        DEPRECATED_FEATURE_IN_ICXML;
307}
308
309inline unsigned int ElemStack::getPrefixId(const XMLCh* const) const
310{
311        DEPRECATED_FEATURE_IN_ICXML;
312}
313
314inline const XMLCh* ElemStack::getPrefixForId(unsigned int) const
315{
316        DEPRECATED_FEATURE_IN_ICXML;
317}
318
319inline unsigned int ElemStack::getEmptyNamespaceId()
320{
321        DEPRECATED_FEATURE_IN_ICXML;
322}
323
324inline bool ElemStack::getReferenceEscaped() const
325{
326        DEPRECATED_FEATURE_IN_ICXML;
327}
328
329inline void ElemStack::setReferenceEscaped()
330{
331        DEPRECATED_FEATURE_IN_ICXML;
332}
333
334inline void ElemStack::setPrefixColonPos(int)
335{
336        DEPRECATED_FEATURE_IN_ICXML;
337}
338
339inline int ElemStack::getPrefixColonPos() const
340{
341        DEPRECATED_FEATURE_IN_ICXML;
342}
343
344
345inline bool ElemStack::getCommentOrPISeen() const
346{
347    DEPRECATED_FEATURE_IN_ICXML;
348}
349
350inline void ElemStack::setCommentOrPISeen()
351{
352    DEPRECATED_FEATURE_IN_ICXML;
353}
354
355// --------------------------------------------------------------------------
356// THIS ENTIRE CLASS IS DEPRECATED
357// --------------------------------------------------------------------------
358
359class XMLPARSER_EXPORT WFElemStack : public XMemory
360{
361public :
362        // -----------------------------------------------------------------------
363        //  Class specific data types
364        //
365        //  These really should be private, but some of the compilers we have to
366        //  support are too dumb to deal with that.
367        //
368        //  PrefMapElem
369        //      fURIId is the id of the URI from the validator's URI map. The
370        //      fPrefId is the id of the prefix from our own prefix pool. The
371        //      namespace stack consists of these elements.
372        //
373        //  StackElem
374        //      fThisElement is the basic element decl for the current element.
375        //      The fRowCapacity is how large fChildIds has grown so far.
376        //      fChildCount is how many of them are valid right now.
377        //
378        //      The fMapCapacity is how large fMap has grown so far. fMapCount
379        //      is how many of them are valid right now.
380        //
381        //      Note that we store the reader number we were in when we found the
382        //      start tag. We'll use this at the end tag to test for unbalanced
383        //      markup in entities.
384        //
385        //  MapModes
386        //      When a prefix is mapped to a namespace id, it matters whether the
387        //      QName being mapped is an attribute or name. Attributes are not
388        //      affected by an sibling xmlns attributes, whereas elements are
389        //      affected by its own xmlns attributes.
390        // -----------------------------------------------------------------------
391        struct StackElem : public XMemory
392        {
393                int                 fTopPrefix;
394                unsigned int        fCurrentURI;
395                unsigned int        fElemMaxLength;
396                XMLCh*              fThisElement;
397        };
398
399        enum MapModes
400        {
401                Mode_Attribute
402                , Mode_Element
403        };
404
405
406        // -----------------------------------------------------------------------
407        //  Constructors and Destructor
408        // -----------------------------------------------------------------------
409        WFElemStack(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
410        ~WFElemStack();
411
412
413        // -----------------------------------------------------------------------
414        //  Stack access
415        // -----------------------------------------------------------------------
416        XMLSize_t addLevel();
417        XMLSize_t addLevel(const XMLCh* const toSet, const unsigned int toSetLen,
418                                                  const unsigned int readerNum);
419        const StackElem* popTop();
420
421
422        // -----------------------------------------------------------------------
423        //  Stack top access
424        // -----------------------------------------------------------------------
425        const StackElem* topElement() const;
426        void setElement(const XMLCh* const toSet, const unsigned int toSetLen,
427                                        const unsigned int readerNum);
428
429        void setCurrentURI(unsigned int uri);
430        unsigned int getCurrentURI();
431
432        // -----------------------------------------------------------------------
433        //  Prefix map methods
434        // -----------------------------------------------------------------------
435        void addPrefix
436        (
437                const   XMLCh* const    prefixToAdd
438                , const unsigned int    uriId
439        );
440        unsigned int mapPrefixToURI
441        (
442                const   XMLCh* const    prefixToMap
443                ,       bool&           unknown
444        )   const;
445
446
447        // -----------------------------------------------------------------------
448        //  Miscellaneous methods
449        // -----------------------------------------------------------------------
450        bool isEmpty() const;
451        void reset
452        (
453                const   unsigned int    emptyId
454                , const unsigned int    unknownId
455                , const unsigned int    xmlId
456                , const unsigned int    xmlNSId
457        );
458
459
460private :
461        // -----------------------------------------------------------------------
462        //  Unimplemented constructors and operators
463        // -----------------------------------------------------------------------
464        WFElemStack(const WFElemStack&);
465        WFElemStack& operator=(const WFElemStack&);
466
467
468        // -----------------------------------------------------------------------
469        //  Private helper methods
470        // -----------------------------------------------------------------------
471        void expandMap();
472        void expandStack();
473};
474
475// ---------------------------------------------------------------------------
476//  WFElemStack: Miscellaneous methods
477// ---------------------------------------------------------------------------
478inline bool WFElemStack::isEmpty() const
479{
480        DEPRECATED_FEATURE_IN_ICXML;
481}
482
483inline unsigned int WFElemStack::getCurrentURI()
484{
485        DEPRECATED_FEATURE_IN_ICXML;
486}
487
488inline void WFElemStack::setCurrentURI(unsigned int)
489{
490        DEPRECATED_FEATURE_IN_ICXML;
491}
492
493XERCES_CPP_NAMESPACE_END
494
495#endif
Note: See TracBrowser for help on using the repository browser.