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