source: icXML/icXML-devel/src/xercesc/validators/schema/NamespaceScope.hpp @ 2734

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

Original Xerces files with import mods for icxercesc

File size: 5.9 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: NamespaceScope.hpp 729944 2008-12-29 17:03:32Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_NAMESPACESCOPE_HPP)
23#define XERCESC_INCLUDE_GUARD_NAMESPACESCOPE_HPP
24
25#include <xercesc/util/StringPool.hpp>
26
27XERCES_CPP_NAMESPACE_BEGIN
28
29// Define a pure interface to allow XercesXPath to work on both NamespaceScope and DOMXPathNSResolver
30class VALIDATORS_EXPORT XercesNamespaceResolver
31{
32public:
33    virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefix) const = 0;
34};
35
36//
37// NamespaceScope provides a data structure for mapping namespace prefixes
38// to their URI's. The mapping accurately reflects the scoping of namespaces
39// at a particular instant in time.
40//
41
42class VALIDATORS_EXPORT NamespaceScope : public XMemory,
43                                         public XercesNamespaceResolver
44{
45public :
46    // -----------------------------------------------------------------------
47    //  Class specific data types
48    //
49    //  These really should be private, but some of the compilers we have to
50    //  support are too dumb to deal with that.
51    //
52    //  PrefMapElem
53    //      fURIId is the id of the URI from the validator's URI map. The
54    //      fPrefId is the id of the prefix from our own prefix pool. The
55    //      namespace stack consists of these elements.
56    //
57    //  StackElem
58    //      The fMapCapacity is how large fMap has grown so far. fMapCount
59    //      is how many of them are valid right now.
60    // -----------------------------------------------------------------------
61    struct PrefMapElem : public XMemory
62    {
63        unsigned int        fPrefId;
64        unsigned int        fURIId;
65    };
66
67    struct StackElem : public XMemory
68    {
69        PrefMapElem*        fMap;
70        unsigned int        fMapCapacity;
71        unsigned int        fMapCount;
72    };
73
74
75    // -----------------------------------------------------------------------
76    //  Constructors and Destructor
77    // -----------------------------------------------------------------------
78    NamespaceScope(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
79    NamespaceScope(const NamespaceScope* const initialize, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
80    ~NamespaceScope();
81
82
83    // -----------------------------------------------------------------------
84    //  Stack access
85    // -----------------------------------------------------------------------
86    unsigned int increaseDepth();
87    unsigned int decreaseDepth();
88
89    // -----------------------------------------------------------------------
90    //  Prefix map methods
91    // -----------------------------------------------------------------------
92    void addPrefix(const XMLCh* const prefixToAdd,
93                   const unsigned int uriId);
94
95    virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefixToMap) const;
96
97
98    // -----------------------------------------------------------------------
99    //  Miscellaneous methods
100    // -----------------------------------------------------------------------
101    bool isEmpty() const;
102    void reset(const unsigned int emptyId);
103    unsigned int getEmptyNamespaceId() const;
104
105
106private :
107    // -----------------------------------------------------------------------
108    //  Unimplemented constructors and operators
109    // -----------------------------------------------------------------------
110    NamespaceScope(const NamespaceScope&);
111    NamespaceScope& operator=(const NamespaceScope&);
112
113
114    // -----------------------------------------------------------------------
115    //  Private helper methods
116    // -----------------------------------------------------------------------
117    void expandMap(StackElem* const toExpand);
118    void expandStack();
119
120
121    // -----------------------------------------------------------------------
122    //  Data members
123    //
124    //  fEmptyNamespaceId
125    //      This is the special URI id for the "" namespace, which is magic
126    //      because of the xmlns="" operation.
127    //
128    //  fPrefixPool
129    //      This is the prefix pool where prefixes are hashed and given unique
130    //      ids. These ids are used to track prefixes in the element stack.
131    //
132    //  fStack
133    //  fStackCapacity
134    //  fStackTop
135    //      This the stack array. Its an array of pointers to StackElem
136    //      structures. The capacity is the current high water mark of the
137    //      stack. The top is the current top of stack (i.e. the part of it
138    //      being used.)
139    // -----------------------------------------------------------------------
140    unsigned int  fEmptyNamespaceId;
141    unsigned int  fStackCapacity;
142    unsigned int  fStackTop;
143    XMLStringPool fPrefixPool;
144    StackElem**   fStack;
145    MemoryManager* fMemoryManager;
146};
147
148// ---------------------------------------------------------------------------
149//  NamespaceScope: Miscellaneous methods
150// ---------------------------------------------------------------------------
151inline bool NamespaceScope::isEmpty() const
152{
153    return (fStackTop == 0);
154}
155
156inline unsigned int NamespaceScope::getEmptyNamespaceId() const
157{
158    return fEmptyNamespaceId;
159}
160
161
162XERCES_CPP_NAMESPACE_END
163
164#endif
165
166/**
167  * End of file NameSpaceScope.hpp
168  */
169
Note: See TracBrowser for help on using the repository browser.