Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:19

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_NAMESPACESCOPE_HPP)
0023 #define XERCESC_INCLUDE_GUARD_NAMESPACESCOPE_HPP
0024 
0025 #include <xercesc/util/StringPool.hpp>
0026 
0027 XERCES_CPP_NAMESPACE_BEGIN
0028 
0029 // Define a pure interface to allow XercesXPath to work on both NamespaceScope and DOMXPathNSResolver
0030 class VALIDATORS_EXPORT XercesNamespaceResolver
0031 {
0032 public:
0033     virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefix) const = 0;
0034 };
0035 
0036 //
0037 // NamespaceScope provides a data structure for mapping namespace prefixes
0038 // to their URI's. The mapping accurately reflects the scoping of namespaces
0039 // at a particular instant in time.
0040 //
0041 
0042 class VALIDATORS_EXPORT NamespaceScope : public XMemory,
0043                                          public XercesNamespaceResolver
0044 {
0045 public :
0046     // -----------------------------------------------------------------------
0047     //  Class specific data types
0048     //
0049     //  These really should be private, but some of the compilers we have to
0050     //  support are too dumb to deal with that.
0051     //
0052     //  PrefMapElem
0053     //      fURIId is the id of the URI from the validator's URI map. The
0054     //      fPrefId is the id of the prefix from our own prefix pool. The
0055     //      namespace stack consists of these elements.
0056     //
0057     //  StackElem
0058     //      The fMapCapacity is how large fMap has grown so far. fMapCount
0059     //      is how many of them are valid right now.
0060     // -----------------------------------------------------------------------
0061     struct PrefMapElem : public XMemory
0062     {
0063         unsigned int        fPrefId;
0064         unsigned int        fURIId;
0065     };
0066 
0067     struct StackElem : public XMemory
0068     {
0069         PrefMapElem*        fMap;
0070         unsigned int        fMapCapacity;
0071         unsigned int        fMapCount;
0072     };
0073 
0074 
0075     // -----------------------------------------------------------------------
0076     //  Constructors and Destructor
0077     // -----------------------------------------------------------------------
0078     NamespaceScope(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0079     NamespaceScope(const NamespaceScope* const initialize, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0080     virtual ~NamespaceScope();
0081 
0082 
0083     // -----------------------------------------------------------------------
0084     //  Stack access
0085     // -----------------------------------------------------------------------
0086     unsigned int increaseDepth();
0087     unsigned int decreaseDepth();
0088 
0089     // -----------------------------------------------------------------------
0090     //  Prefix map methods
0091     // -----------------------------------------------------------------------
0092     void addPrefix(const XMLCh* const prefixToAdd,
0093                    const unsigned int uriId);
0094 
0095     virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefixToMap) const;
0096 
0097 
0098     // -----------------------------------------------------------------------
0099     //  Miscellaneous methods
0100     // -----------------------------------------------------------------------
0101     bool isEmpty() const;
0102     void reset(const unsigned int emptyId);
0103     unsigned int getEmptyNamespaceId() const;
0104 
0105 
0106 private :
0107     // -----------------------------------------------------------------------
0108     //  Unimplemented constructors and operators
0109     // -----------------------------------------------------------------------
0110     NamespaceScope(const NamespaceScope&);
0111     NamespaceScope& operator=(const NamespaceScope&);
0112 
0113 
0114     // -----------------------------------------------------------------------
0115     //  Private helper methods
0116     // -----------------------------------------------------------------------
0117     void expandMap(StackElem* const toExpand);
0118     void expandStack();
0119 
0120 
0121     // -----------------------------------------------------------------------
0122     //  Data members
0123     //
0124     //  fEmptyNamespaceId
0125     //      This is the special URI id for the "" namespace, which is magic
0126     //      because of the xmlns="" operation.
0127     //
0128     //  fPrefixPool
0129     //      This is the prefix pool where prefixes are hashed and given unique
0130     //      ids. These ids are used to track prefixes in the element stack.
0131     //
0132     //  fStack
0133     //  fStackCapacity
0134     //  fStackTop
0135     //      This the stack array. Its an array of pointers to StackElem
0136     //      structures. The capacity is the current high water mark of the
0137     //      stack. The top is the current top of stack (i.e. the part of it
0138     //      being used.)
0139     // -----------------------------------------------------------------------
0140     unsigned int  fEmptyNamespaceId;
0141     unsigned int  fStackCapacity;
0142     unsigned int  fStackTop;
0143     XMLStringPool fPrefixPool;
0144     StackElem**   fStack;
0145     MemoryManager* fMemoryManager;
0146 };
0147 
0148 // ---------------------------------------------------------------------------
0149 //  NamespaceScope: Miscellaneous methods
0150 // ---------------------------------------------------------------------------
0151 inline bool NamespaceScope::isEmpty() const
0152 {
0153     return (fStackTop == 0);
0154 }
0155 
0156 inline unsigned int NamespaceScope::getEmptyNamespaceId() const
0157 {
0158     return fEmptyNamespaceId;
0159 }
0160 
0161 
0162 XERCES_CPP_NAMESPACE_END
0163 
0164 #endif
0165 
0166 /**
0167   * End of file NameSpaceScope.hpp
0168   */
0169