1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD)
19 #define XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD
20 
21 
22 
23 // Base include file.  Must be first.
24 #include <xalanc/XSLT/XSLTDefinitions.hpp>
25 
26 
27 
28 #include <xalanc/Include/XalanVector.hpp>
29 
30 
31 
32 #include <xalanc/XalanDOM/XalanDOMString.hpp>
33 
34 
35 
36 #include <xalanc/XPath/XalanQName.hpp>
37 
38 
39 
40 namespace XALAN_CPP_NAMESPACE {
41 
42 
43 
44 class XALAN_XSLT_EXPORT ResultNamespacesStack
45 {
46 public:
47 
48 
49 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
50     typedef std::deque<bool>    BoolVectorType;
51 #else
52     typedef XalanVector<bool>       BoolVectorType;
53 #endif
54 
55     typedef XalanQName::NamespaceVectorType     NamespaceVectorType;
56     typedef XalanQName::NamespacesStackType     NamespacesStackType;
57 
58     typedef NamespacesStackType::size_type      size_type;
59 
60 
61     explicit
62     ResultNamespacesStack(MemoryManager& theManager);
63 
64     ~ResultNamespacesStack();
65 
66     void
addDeclaration(const XalanDOMString & thePrefix,const XalanDOMString & theNamespaceURI)67     addDeclaration(
68             const XalanDOMString&   thePrefix,
69             const XalanDOMString&   theNamespaceURI)
70     {
71         addDeclaration(
72             thePrefix,
73             theNamespaceURI.c_str(),
74             theNamespaceURI.length());
75     }
76 
77     void
addDeclaration(const XalanDOMString & thePrefix,const XalanDOMChar * theNamespaceURI)78     addDeclaration(
79             const XalanDOMString&   thePrefix,
80             const XalanDOMChar*     theNamespaceURI)
81     {
82         addDeclaration(
83             thePrefix,
84             theNamespaceURI,
85             length(theNamespaceURI));
86     }
87 
88     void
89     addDeclaration(
90             const XalanDOMString&       thePrefix,
91             const XalanDOMChar*         theNamespaceURI,
92             XalanDOMString::size_type   theLength);
93 
94     void
95     pushContext();
96 
97     void
98     popContext();
99 
100     const XalanDOMString*
101     getNamespaceForPrefix(const XalanDOMString&     thePrefix) const;
102 
103     const XalanDOMString*
104     getPrefixForNamespace(const XalanDOMString&     theNamespaceURI) const;
105 
106     /**
107      * See if the prefix has been mapped to a namespace in the current
108      * context, without looking down the stack of namespaces.
109      */
110     bool
111     prefixIsPresentLocal(const XalanDOMString&  thePrefix);
112 
113     void
114     clear();
115 
116     size_type
size() const117     size() const
118     {
119         return m_resultNamespaces.size() - 1;
120     }
121 
122     bool
empty() const123     empty() const
124     {
125         return NamespacesStackType::const_iterator(m_stackPosition) == m_resultNamespaces.begin() ? true : false;
126     }
127 
128 private:
129 
130     // not implemented
131     ResultNamespacesStack(const ResultNamespacesStack&);
132 
133     bool
134     operator==(const ResultNamespacesStack&) const;
135 
136     ResultNamespacesStack&
137     operator=(const ResultNamespacesStack&);
138 
139     enum { eDefaultCreateNewContextStackSize = 25 };
140 
141     /**
142      * A stack to keep track of the result tree namespaces.
143      */
144     NamespacesStackType             m_resultNamespaces;
145 
146     NamespacesStackType::iterator   m_stackBegin;
147 
148     NamespacesStackType::iterator   m_stackPosition;
149 
150     BoolVectorType                  m_createNewContextStack;
151 };
152 
153 
154 
155 }
156 
157 
158 
159 #endif  // XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD
160