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

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

Initial check-in of icXML 0.8 source files

File size: 15.6 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 <xercesc/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                XMLSize_t           fReaderNum;
104
105                #ifndef STORE_CHILDREN_INFORMATION_IN_PARSER
106                // TODO: it may be possible to remove all this child code from the elem stack and instead
107                // store it within the XMLParser
108                XMLSize_t           fChildCapacity;
109                XMLSize_t           fChildCount;
110                QName**             fChildren;
111                #endif
112
113                bool                fValidationFlag;
114                bool                fCommentOrPISeen;
115                unsigned int        fCurrentScope;
116
117                Grammar*            fCurrentGrammar;
118                #ifndef PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER
119                const XMLCh *       fSchemaElemName;
120                #endif
121        };
122
123        enum MapModes
124        {
125                Mode_Attribute
126                , Mode_Element
127        };
128
129
130        // -----------------------------------------------------------------------
131        //  Constructors and Destructor
132        // -----------------------------------------------------------------------
133        ElemStack(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
134        ~ElemStack();
135
136
137        // -----------------------------------------------------------------------
138        //  Stack access
139        // -----------------------------------------------------------------------
140        XMLSize_t addLevel();
141        XMLSize_t addLevel(XMLElementDecl* const toSet, const XMLSize_t readerNum);
142        XMLSize_t getLevel() const;
143
144        const StackElem* popTop();
145
146
147        // -----------------------------------------------------------------------
148        //  Stack top access
149        // -----------------------------------------------------------------------
150        XMLSize_t addChild(QName* const child, const bool toParent);
151        const StackElem* topElement() const;
152        void setElement(XMLElementDecl* const toSet, const XMLSize_t readerNum);
153
154        void setValidationFlag(bool validationFlag);
155        bool getValidationFlag();
156
157        inline void setCommentOrPISeen();
158        inline bool getCommentOrPISeen() const;
159
160        inline void setReferenceEscaped();
161        inline bool getReferenceEscaped() const;
162
163        void setCurrentScope(int currentScope);
164        int getCurrentScope();
165
166        void setPrefixColonPos(int colonPos); // DEPRECATED BUT KEPT FOR DLL COMPATIBILITY
167        int getPrefixColonPos() const; // DEPRECATED BUT KEPT FOR DLL COMPATIBILITY
168
169        void setCurrentGrammar(Grammar* currentGrammar);
170        Grammar* getCurrentGrammar();
171
172        void setCurrentURI(unsigned int uri);
173        unsigned int getCurrentURI();
174
175        inline void setCurrentSchemaElemName(const XMLCh * const schemaElemName);
176        inline XMLCh *getCurrentSchemaElemName();
177
178        // -----------------------------------------------------------------------
179        //  Prefix map methods
180        // -----------------------------------------------------------------------
181        void addGlobalPrefix
182        (
183                const   XMLCh* const    prefixToAdd
184                , const unsigned int    uriId
185        );
186        void addPrefix
187        (
188                const   XMLCh* const    prefixToAdd
189                , const unsigned int    uriId
190        );
191
192        unsigned int mapPrefixToURI
193        (
194                const   XMLCh* const    prefixToMap
195                ,       bool&           unknown
196        )   const;
197
198        ValueVectorOf<PrefMapElem*>* getNamespaceMap() const;
199        unsigned int getPrefixId(const XMLCh* const prefix) const;
200        const XMLCh* getPrefixForId(unsigned int prefId) const;
201
202        // -----------------------------------------------------------------------
203        //  Miscellaneous methods
204        // -----------------------------------------------------------------------
205        bool isEmpty() const;
206        void reset
207        (
208                const   unsigned int    emptyId
209                , const unsigned int    unknownId
210                , const unsigned int    xmlId
211                , const unsigned int    xmlNSId
212        );
213
214        unsigned int getEmptyNamespaceId();
215
216private :
217        // -----------------------------------------------------------------------
218        //  Unimplemented constructors and operators
219        // -----------------------------------------------------------------------
220        ElemStack(const ElemStack&);
221        ElemStack& operator=(const ElemStack&);
222
223
224        // -----------------------------------------------------------------------
225        //  Private helper methods
226        // -----------------------------------------------------------------------
227        void expandMap(StackElem* const toExpand);
228        void expandStack();
229
230
231        // -----------------------------------------------------------------------
232        //  Data members
233        //
234        //  fStack
235        //  fStackCapacity
236        //  fStackTop
237        //      This the stack array. Its an array of pointers to StackElem
238        //      structures. The capacity is the current high water mark of the
239        //      stack. The top is the current top of stack (i.e. the part of it
240        //      being used.)
241        //
242        // -----------------------------------------------------------------------
243        StackElem**                  fStack;
244        XMLSize_t                    fStackCapacity;
245        XMLSize_t                    fStackTop;
246        MemoryManager*               fMemoryManager;
247};
248
249// ---------------------------------------------------------------------------
250//  ElemStack: Miscellaneous methods
251// ---------------------------------------------------------------------------
252inline bool ElemStack::isEmpty() const
253{
254        return (fStackTop == 0);
255}
256
257inline XMLSize_t ElemStack::getLevel() const
258{
259        return fStackTop - 1;
260}
261
262inline bool ElemStack::getValidationFlag()
263{
264        return fStack[fStackTop - 1]->fValidationFlag;
265}
266
267inline void ElemStack::setValidationFlag(bool validationFlag)
268{
269        fStack[fStackTop-1]->fValidationFlag = validationFlag;
270}
271
272inline bool ElemStack::getCommentOrPISeen() const
273{
274        return fStack[fStackTop-1]->fCommentOrPISeen;
275}
276
277inline void ElemStack::setCommentOrPISeen()
278{
279        fStack[fStackTop-1]->fCommentOrPISeen = true;
280}
281
282inline void ElemStack::setCurrentSchemaElemName(const XMLCh * const schemaElemName)
283{
284        #ifdef PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER
285        DEPRECATED_FEATURE_IN_ICXML;
286        #else
287        fStack[fStackTop - 1]->fSchemaElemName = schemaElemName;
288        #endif
289}
290
291inline XMLCh * ElemStack::getCurrentSchemaElemName()
292{
293        #ifdef PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER
294        DEPRECATED_FEATURE_IN_ICXML;
295        #else
296        return const_cast<XMLCh*>(fStack[fStackTop - 1]->fSchemaElemName);
297        #endif
298}
299
300inline int ElemStack::getCurrentScope()
301{
302        return fStack[fStackTop - 1]->fCurrentScope;
303}
304
305inline void ElemStack::setCurrentScope(int currentScope)
306{
307        fStack[fStackTop - 1]->fCurrentScope = currentScope;
308}
309
310inline Grammar * ElemStack::getCurrentGrammar()
311{
312        return fStack[fStackTop - 1]->fCurrentGrammar;
313}
314
315inline void ElemStack::setCurrentGrammar(Grammar* currentGrammar)
316{
317        fStack[fStackTop - 1]->fCurrentGrammar = currentGrammar;
318}
319
320// --------------------------------------------------------------------------
321// DEPRECATED BUT KEPT FOR DLL COMPATIBILITY
322// --------------------------------------------------------------------------
323
324inline unsigned int ElemStack::getCurrentURI()
325{
326        DEPRECATED_FEATURE_IN_ICXML;
327}
328
329inline void ElemStack::setCurrentURI(unsigned int)
330{
331        DEPRECATED_FEATURE_IN_ICXML;
332}
333
334inline unsigned int ElemStack::getPrefixId(const XMLCh* const) const
335{
336        DEPRECATED_FEATURE_IN_ICXML;
337}
338
339inline const XMLCh* ElemStack::getPrefixForId(unsigned int) const
340{
341        DEPRECATED_FEATURE_IN_ICXML;
342}
343
344inline unsigned int ElemStack::getEmptyNamespaceId()
345{
346        DEPRECATED_FEATURE_IN_ICXML;
347}
348
349inline bool ElemStack::getReferenceEscaped() const
350{
351        DEPRECATED_FEATURE_IN_ICXML;
352}
353
354inline void ElemStack::setReferenceEscaped()
355{
356        DEPRECATED_FEATURE_IN_ICXML;
357}
358
359inline void ElemStack::setPrefixColonPos(int)
360{
361        DEPRECATED_FEATURE_IN_ICXML;
362}
363
364inline int ElemStack::getPrefixColonPos() const
365{
366        DEPRECATED_FEATURE_IN_ICXML;
367}
368
369// --------------------------------------------------------------------------
370// THIS ENTIRE CLASS IS DEPRECATED
371// --------------------------------------------------------------------------
372
373class XMLPARSER_EXPORT WFElemStack : public XMemory
374{
375public :
376        // -----------------------------------------------------------------------
377        //  Class specific data types
378        //
379        //  These really should be private, but some of the compilers we have to
380        //  support are too dumb to deal with that.
381        //
382        //  PrefMapElem
383        //      fURIId is the id of the URI from the validator's URI map. The
384        //      fPrefId is the id of the prefix from our own prefix pool. The
385        //      namespace stack consists of these elements.
386        //
387        //  StackElem
388        //      fThisElement is the basic element decl for the current element.
389        //      The fRowCapacity is how large fChildIds has grown so far.
390        //      fChildCount is how many of them are valid right now.
391        //
392        //      The fMapCapacity is how large fMap has grown so far. fMapCount
393        //      is how many of them are valid right now.
394        //
395        //      Note that we store the reader number we were in when we found the
396        //      start tag. We'll use this at the end tag to test for unbalanced
397        //      markup in entities.
398        //
399        //  MapModes
400        //      When a prefix is mapped to a namespace id, it matters whether the
401        //      QName being mapped is an attribute or name. Attributes are not
402        //      affected by an sibling xmlns attributes, whereas elements are
403        //      affected by its own xmlns attributes.
404        // -----------------------------------------------------------------------
405        struct StackElem : public XMemory
406        {
407                int                 fTopPrefix;
408                unsigned int        fCurrentURI;
409                unsigned int        fReaderNum;
410                unsigned int        fElemMaxLength;
411                XMLCh*              fThisElement;
412        };
413
414        enum MapModes
415        {
416                Mode_Attribute
417                , Mode_Element
418        };
419
420
421        // -----------------------------------------------------------------------
422        //  Constructors and Destructor
423        // -----------------------------------------------------------------------
424        WFElemStack(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
425        ~WFElemStack();
426
427
428        // -----------------------------------------------------------------------
429        //  Stack access
430        // -----------------------------------------------------------------------
431        XMLSize_t addLevel();
432        XMLSize_t addLevel(const XMLCh* const toSet, const unsigned int toSetLen,
433                                                  const unsigned int readerNum);
434        const StackElem* popTop();
435
436
437        // -----------------------------------------------------------------------
438        //  Stack top access
439        // -----------------------------------------------------------------------
440        const StackElem* topElement() const;
441        void setElement(const XMLCh* const toSet, const unsigned int toSetLen,
442                                        const unsigned int readerNum);
443
444        void setCurrentURI(unsigned int uri);
445        unsigned int getCurrentURI();
446
447        // -----------------------------------------------------------------------
448        //  Prefix map methods
449        // -----------------------------------------------------------------------
450        void addPrefix
451        (
452                const   XMLCh* const    prefixToAdd
453                , const unsigned int    uriId
454        );
455        unsigned int mapPrefixToURI
456        (
457                const   XMLCh* const    prefixToMap
458                ,       bool&           unknown
459        )   const;
460
461
462        // -----------------------------------------------------------------------
463        //  Miscellaneous methods
464        // -----------------------------------------------------------------------
465        bool isEmpty() const;
466        void reset
467        (
468                const   unsigned int    emptyId
469                , const unsigned int    unknownId
470                , const unsigned int    xmlId
471                , const unsigned int    xmlNSId
472        );
473
474
475private :
476        // -----------------------------------------------------------------------
477        //  Unimplemented constructors and operators
478        // -----------------------------------------------------------------------
479        WFElemStack(const WFElemStack&);
480        WFElemStack& operator=(const WFElemStack&);
481
482
483        // -----------------------------------------------------------------------
484        //  Private helper methods
485        // -----------------------------------------------------------------------
486        void expandMap();
487        void expandStack();
488};
489
490// ---------------------------------------------------------------------------
491//  WFElemStack: Miscellaneous methods
492// ---------------------------------------------------------------------------
493inline bool WFElemStack::isEmpty() const
494{
495        DEPRECATED_FEATURE_IN_ICXML;
496}
497
498inline unsigned int WFElemStack::getCurrentURI()
499{
500        DEPRECATED_FEATURE_IN_ICXML;
501}
502
503inline void WFElemStack::setCurrentURI(unsigned int)
504{
505        DEPRECATED_FEATURE_IN_ICXML;
506}
507
508XERCES_CPP_NAMESPACE_END
509
510#endif
Note: See TracBrowser for help on using the repository browser.