Xalan-C++ API Reference  1.12.0
XalanNamespacesStack.hpp
Go to the documentation of this file.
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_XALANNAMESPACESSTACK_HEADER_GUARD)
19 #define XALAN_XALANNAMESPACESSTACK_HEADER_GUARD
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
30 
31 
32 
35 
36 
37 
38 namespace XALAN_CPP_NAMESPACE {
39 
40 
41 class XalanDOMString;
42 
43 
44 
46 {
47 public:
48 
50  {
51  public:
52 
53  /**
54  * Construct a PrefixResolver from a XalanNamespaceStack
55  * instance.
56  *
57  * @param theStack The stack to use for prefix resolution
58  * @param theURI The namespace URI of the resolver, if any. Only a reference is kept, so this cannot be a temporary
59  * @return pointer to the string value if found, otherwise 0.
60  */
62  const XalanNamespacesStack& theStack,
63  const XalanDOMString& theURI);
64 
65  virtual
67 
68  virtual const XalanDOMString*
69  getNamespaceForPrefix(const XalanDOMString& prefix) const;
70 
71  virtual const XalanDOMString&
72  getURI() const;
73 
74  private:
75 
76  const XalanNamespacesStack& m_stack;
77 
78  const XalanDOMString& m_uri;
79  };
80 
82  {
83  public:
84 
86 
88 
89  typedef const XalanDOMString& (value_type::*MemberFunctionType)() const;
90 
95 
96  XalanNamespacesStackEntry(MemoryManager& theManager);
97 
99  MemoryManager& theManager);
100 
102 
104  set(const XalanNamespacesStackEntry& theRHS,
105  MemoryManager& theManager);
106 
107  void
108  addDeclaration(
109  const XalanDOMString& thePrefix,
110  const XalanDOMChar* theNamespaceURI,
111  XalanDOMString::size_type theLength);
112 
113  /**
114  * Get the namespace for a prefix.
115  *
116  * @param thePrefix The prefix to find
117  * @return pointer to the string value if found, otherwise 0.
118  */
119  const XalanDOMString*
120  getNamespaceForPrefix(const XalanDOMString& thePrefix) const
121  {
122  return findEntry(thePrefix, &XalanNamespace::getPrefix, &XalanNamespace::getURI);
123  }
124 
125  /**
126  * Get the prefix for a namespace.
127  *
128  * @param theURI The namespace URI to find
129  * @return pointer to the string value if found, otherwise 0.
130  */
131  const XalanDOMString*
133  {
134  return findEntry(theURI, &XalanNamespace::getURI, &XalanNamespace::getPrefix);
135  }
136 
137  bool
138  isPrefixPresent(const XalanDOMString& thePrefix) const
139  {
140  return getNamespaceForPrefix(thePrefix) == 0 ? false : true;
141  }
142 
143  iterator
145  {
146  return m_namespaces.begin();
147  }
148 
150  begin() const
151  {
152  return m_namespaces.begin();
153  }
154 
155  iterator
156  end()
157  {
158  return m_position;
159  }
160 
162  end() const
163  {
164  return const_iterator(m_position);
165  }
166 
169  {
170  return reverse_iterator(end());
171  }
172 
174  rbegin() const
175  {
176  return const_reverse_iterator(end());
177  }
178 
181  {
182  return reverse_iterator(begin());
183  }
184 
186  rend() const
187  {
188  return const_reverse_iterator(begin());
189  }
190 
191  void
192  clear();
193 
194  void
196  {
197  m_position = m_namespaces.begin();
198  }
199 
200  void
201  swap(XalanNamespacesStackEntry& theOther);
202 
203  private:
204  //Not implemented
207 
208  const XalanDOMString*
209  findEntry(
210  const XalanDOMString& theKey,
211  MemberFunctionType theKeyFunction,
212  MemberFunctionType theValueFunction) const;
213 
214  NamespaceCollectionType m_namespaces;
215 
216  iterator m_position;
217  };
218 
219 
221 
224 
229 
231 
232  typedef const XalanDOMString* (value_type::*MemberFunctionType)(const XalanDOMString&) const;
233 
234 
235  explicit
236  XalanNamespacesStack(MemoryManager& theManager);
237 
239 
240  void
242  const XalanDOMString& thePrefix,
243  const XalanDOMString& theURI)
244  {
245  addDeclaration(
246  thePrefix,
247  theURI.c_str(),
248  theURI.length());
249  }
250 
251  void
253  const XalanDOMString& thePrefix,
254  const XalanDOMChar* theURI)
255  {
256  addDeclaration(
257  thePrefix,
258  theURI,
259  length(theURI));
260  }
261 
262  void
263  addDeclaration(
264  const XalanDOMString& thePrefix,
265  const XalanDOMChar* theURI,
266  XalanDOMString::size_type theLength);
267 
268  void
269  pushContext();
270 
271  void
272  popContext();
273 
274  const XalanDOMString*
275  getNamespaceForPrefix(const XalanDOMString& thePrefix) const;
276 
277  const XalanDOMString*
279  {
280  return findEntry(theURI, &value_type::getPrefixForNamespace);
281  }
282 
283  /**
284  * See if the prefix has been mapped to a namespace in the current
285  * context, without looking down the stack of namespaces.
286  */
287  bool
288  prefixIsPresentLocal(const XalanDOMString& thePrefix);
289 
290  void
291  clear();
292 
293  iterator
295  {
296  return m_stackBegin + 1;
297  }
298 
299  const_iterator
300  begin() const
301  {
302  return const_iterator(m_stackBegin + 1);
303  }
304 
305  iterator
306  end()
307  {
308  return m_stackPosition + 1;
309  }
310 
311  const_iterator
312  end() const
313  {
314  return const_iterator(m_stackPosition + 1);
315  }
316 
317  reverse_iterator
319  {
320  return reverse_iterator(end());
321  }
322 
323  const_reverse_iterator
324  rbegin() const
325  {
326  return const_reverse_iterator(end());
327  }
328 
329  reverse_iterator
331  {
332  return reverse_iterator(begin());
333  }
334 
335  const_reverse_iterator
336  rend() const
337  {
338  return const_reverse_iterator(begin());
339  }
340 
341  size_type
342  size() const
343  {
344  return m_resultNamespaces.size() - 1;
345  }
346 
347  bool
348  empty() const
349  {
350  return NamespacesStackType::const_iterator(m_stackPosition) == m_resultNamespaces.begin() ? true : false;
351  }
352 
353 private:
354 
355  // not implemented
358  XalanNamespacesStackEntry&
359  operator=(const XalanNamespacesStackEntry& theRHS);
360 
361  bool
362  operator==(const XalanNamespacesStack&) const;
363 
365  operator=(const XalanNamespacesStack&);
366 
367  enum { eDefaultCreateNewContextStackSize = 25 };
368 
369  const XalanDOMString*
370  findEntry(
371  const XalanDOMString& theKey,
372  MemberFunctionType theFunction) const;
373 
374  /**
375  * A stack to keep track of the result tree namespaces.
376  */
377  NamespacesStackType m_resultNamespaces;
378 
379  NamespacesStackType::iterator m_stackBegin;
380 
381  NamespacesStackType::iterator m_stackPosition;
382 
383  BoolVectorType m_createNewContextStack;
384 };
385 
386 
387 
388 }
389 
390 
391 
392 #endif // XALAN_XALANNAMESPACESSTACK_HEADER_GUARD
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::MemberFunctionType
const typedef XalanDOMString &(value_type::* MemberFunctionType)() const
Definition: XalanNamespacesStack.hpp:89
xalanc::XalanNamespacesStack::end
const_iterator end() const
Definition: XalanNamespacesStack.hpp:312
xalanc::XalanNamespacesStack::rbegin
const_reverse_iterator rbegin() const
Definition: XalanNamespacesStack.hpp:324
xalanc::XalanNamespacesStack::begin
iterator begin()
Definition: XalanNamespacesStack.hpp:294
XALAN_DOMSUPPORT_EXPORT
#define XALAN_DOMSUPPORT_EXPORT
Definition: DOMSupportDefinitions.hpp:35
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::begin
iterator begin()
Definition: XalanNamespacesStack.hpp:144
xalanc::XalanNamespacesStack::PrefixResolverProxy
Definition: XalanNamespacesStack.hpp:49
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::isPrefixPresent
bool isPrefixPresent(const XalanDOMString &thePrefix) const
Definition: XalanNamespacesStack.hpp:138
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanDequeIterator
Definition: XalanDeque.hpp:57
xalanc::clear
void clear(XalanDOMString &theString)
Remove all elements from target string.
Definition: DOMStringHelper.hpp:2475
PrefixResolver.hpp
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry
Definition: XalanNamespacesStack.hpp:81
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::rend
const_reverse_iterator rend() const
Definition: XalanNamespacesStack.hpp:186
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::end
iterator end()
Definition: XalanNamespacesStack.hpp:156
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::rbegin
const_reverse_iterator rbegin() const
Definition: XalanNamespacesStack.hpp:174
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::rbegin
reverse_iterator rbegin()
Definition: XalanNamespacesStack.hpp:168
xalanc::XalanVector< bool >
xalanc::XalanNamespacesStack::begin
const_iterator begin() const
Definition: XalanNamespacesStack.hpp:300
xalanc::XalanNamespacesStack::rbegin
reverse_iterator rbegin()
Definition: XalanNamespacesStack.hpp:318
xalanc::XalanNamespacesStack::end
iterator end()
Definition: XalanNamespacesStack.hpp:306
xalanc::swap
void swap(XalanVector< Type > &theLHS, XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1107
XalanDeque.hpp
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::getNamespaceForPrefix
const XalanDOMString * getNamespaceForPrefix(const XalanDOMString &thePrefix) const
Get the namespace for a prefix.
Definition: XalanNamespacesStack.hpp:120
xalanc::XalanDeque< value_type >::const_reverse_iterator
const_reverse_iterator_ const_reverse_iterator
Definition: XalanDeque.hpp:222
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::iterator
NamespaceCollectionType::iterator iterator
Definition: XalanNamespacesStack.hpp:91
xalanc::XalanNamespacesStack::BoolVectorType
XalanVector< bool > BoolVectorType
Definition: XalanNamespacesStack.hpp:223
xalanc::XalanNamespacesStack::getPrefixForNamespace
const XalanDOMString * getPrefixForNamespace(const XalanDOMString &theURI) const
Definition: XalanNamespacesStack.hpp:278
XalanVector.hpp
xalanc::XalanDeque< value_type >::reverse_iterator
reverse_iterator_ reverse_iterator
Definition: XalanDeque.hpp:221
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::end
const_iterator end() const
Definition: XalanNamespacesStack.hpp:162
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::reset
void reset()
Definition: XalanNamespacesStack.hpp:195
xalanc::XalanNamespacesStack::addDeclaration
void addDeclaration(const XalanDOMString &thePrefix, const XalanDOMChar *theURI)
Definition: XalanNamespacesStack.hpp:252
xalanc::XalanDeque< value_type >
xalanc::XalanNamespacesStack::value_type
XalanNamespacesStackEntry value_type
Definition: XalanNamespacesStack.hpp:220
xalanc::XalanNamespacesStack::rend
reverse_iterator rend()
Definition: XalanNamespacesStack.hpp:330
xalanc::XalanDOMString::length
size_type length() const
Definition: XalanDOMString.hpp:209
xalanc::XalanNamespacesStack::size
size_type size() const
Definition: XalanNamespacesStack.hpp:342
xalanc::XalanNamespacesStack::reverse_iterator
NamespacesStackType::reverse_iterator reverse_iterator
Definition: XalanNamespacesStack.hpp:226
xalanc::XalanNamespacesStack::rend
const_reverse_iterator rend() const
Definition: XalanNamespacesStack.hpp:336
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::const_iterator
NamespaceCollectionType::const_iterator const_iterator
Definition: XalanNamespacesStack.hpp:93
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
xalanc::XalanNamespacesStack::empty
bool empty() const
Definition: XalanNamespacesStack.hpp:348
xalanc::PrefixResolver
This class defines an interface for classes that resolve namespace prefixes to their URIs.
Definition: PrefixResolver.hpp:39
xalanc::XalanNamespacesStack
Definition: XalanNamespacesStack.hpp:45
xalanc::XalanNamespace
Definition: XalanNamespace.hpp:36
xalanc::XalanNamespacesStack::const_iterator
NamespacesStackType::const_iterator const_iterator
Definition: XalanNamespacesStack.hpp:227
xalanc::XalanDeque::size_type
size_t size_type
Definition: XalanDeque.hpp:204
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::NamespaceCollectionType
XalanDeque< value_type > NamespaceCollectionType
Definition: XalanNamespacesStack.hpp:87
xalanc::XalanNamespacesStack::size_type
NamespacesStackType::size_type size_type
Definition: XalanNamespacesStack.hpp:230
xalanc::XalanNamespacesStack::addDeclaration
void addDeclaration(const XalanDOMString &thePrefix, const XalanDOMString &theURI)
Definition: XalanNamespacesStack.hpp:241
xalanc::XalanNamespacesStack::MemberFunctionType
const typedef XalanDOMString *(value_type::* MemberFunctionType)(const XalanDOMString &) const
Definition: XalanNamespacesStack.hpp:232
xalanc::XalanDOMString::c_str
const XalanDOMChar * c_str() const
Definition: XalanDOMString.hpp:344
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::reverse_iterator
NamespaceCollectionType::reverse_iterator reverse_iterator
Definition: XalanNamespacesStack.hpp:92
DOMSupportDefinitions.hpp
xalanc::XalanDOMString::size_type
XalanSize_t size_type
Definition: XalanDOMString.hpp:57
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::const_reverse_iterator
NamespaceCollectionType::const_reverse_iterator const_reverse_iterator
Definition: XalanNamespacesStack.hpp:94
XalanNamespace.hpp
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanNamespacesStack::const_reverse_iterator
NamespacesStackType::const_reverse_iterator const_reverse_iterator
Definition: XalanNamespacesStack.hpp:228
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::getPrefixForNamespace
const XalanDOMString * getPrefixForNamespace(const XalanDOMString &theURI) const
Get the prefix for a namespace.
Definition: XalanNamespacesStack.hpp:132
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::value_type
XalanNamespace value_type
Definition: XalanNamespacesStack.hpp:85
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::rend
reverse_iterator rend()
Definition: XalanNamespacesStack.hpp:180
xalanc::XalanNamespacesStack::NamespacesStackType
XalanDeque< value_type, ConstructWithMemoryManagerTraits< value_type > > NamespacesStackType
Definition: XalanNamespacesStack.hpp:222
xalanc::XalanNamespacesStack::iterator
NamespacesStackType::iterator iterator
Definition: XalanNamespacesStack.hpp:225
xalanc::XalanNamespacesStack::XalanNamespacesStackEntry::begin
const_iterator begin() const
Definition: XalanNamespacesStack.hpp:150