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