You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/11/20 21:00:08 UTC

cvs commit: xml-xalan/c/src/XSLT OutputContextStack.cpp OutputContextStack.hpp ResultNamespacesStack.cpp ResultNamespacesStack.hpp

dbertoni    00/11/20 12:00:07

  Added:       c/src/XSLT OutputContextStack.cpp OutputContextStack.hpp
                        ResultNamespacesStack.cpp ResultNamespacesStack.hpp
  Log:
  Initial revision.
  
  Revision  Changes    Path
  1.1                  xml-xalan/c/src/XSLT/OutputContextStack.cpp
  
  Index: OutputContextStack.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  // Class header file...
  #include "OutputContextStack.hpp"
  
  
  
  #include <PlatformSupport/DOMStringHelper.hpp>
  
  
  
  OutputContextStack::OutputContextStack() :
  	m_stack(1),
  	m_stackPosition(m_stack.begin())
  {
  	// m_stack is initialized to a size of 1, so that
  	// we always have a dummy entry at the beginning
  	// of the deque.  This makes the implementation
  	// much simpler.
  }
  
  
  
  OutputContextStack::~OutputContextStack()
  {
  }
  
  
  
  void
  OutputContextStack::pushContext(FormatterListener*	theListener)
  {
  	++m_stackPosition;
  
  	if (m_stackPosition == m_stack.end())
  	{
  		m_stack.resize(m_stack.size() + 1);
  
  		m_stackPosition = m_stack.end() - 1;
  	}
  
  	if (theListener != 0)
  	{
  		(*m_stackPosition).m_flistener  = theListener;
  	}
  }
  
  
  
  void
  OutputContextStack::popContext()
  {
  	assert(m_stackPosition != m_stack.begin());
  
  	OutputContext&	theCurrentContext = *m_stackPosition;
  
  	theCurrentContext.reset();
  
  	--m_stackPosition;
  }
  
  
  
  void
  OutputContextStack::clear()
  {
  	// Since we always keep one dummy entry at the beginning,
  	// swap with an OutputContextStackType instance of size 1.
  	OutputContextStackType(1).swap(m_stack);
  
  	m_stackPosition = m_stack.begin();
  }
  
  
  
  void
  OutputContextStack::reset()
  {
  	while(m_stackPosition != m_stack.begin())
  	{
  		popContext();
  	}
  }
  
  
  
  1.1                  xml-xalan/c/src/XSLT/OutputContextStack.hpp
  
  Index: OutputContextStack.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALAN_OUTPUTCONTEXTSTACK_HEADER_GUARD)
  #define XALAN_OUTPUTCONTEXTSTACK_HEADER_GUARD
  
  
  
  // Base include file.  Must be first.
  #include <XSLT/XSLTDefinitions.hpp>
  
  
  
  #include <deque>
  
  
  
  #include <XalanDOM/XalanDOMString.hpp>
  
  
  
  #include <PlatformSupport/AttributeListImpl.hpp>
  
  
  
  class FormatterListener;
  
  
  
  class XALAN_XSLT_EXPORT OutputContextStack
  {
  public:
  
  	struct OutputContext
  	{
  		OutputContext(FormatterListener*	theListener = 0) :
  			m_flistener(theListener),
  			m_pendingAttributes(),
  			m_pendingElementName(),
  			m_hasPendingStartDocument(false),
  			m_mustFlushPendingStartDocument(false)
  		{
  		}
  
  		~OutputContext()
  		{
  		}
  
  		void
  		reset()
  		{
  			m_flistener = 0;
  
  			m_pendingAttributes.clear();
  
  			::clear(m_pendingElementName);
  
  			m_hasPendingStartDocument = false;
  
  			m_mustFlushPendingStartDocument = false;
  		}
  
  		FormatterListener*	m_flistener;
  
  		AttributeListImpl	m_pendingAttributes;
  
  		XalanDOMString		m_pendingElementName;
  
  		bool				m_hasPendingStartDocument;
  
  		bool				m_mustFlushPendingStartDocument;
  	};
  
  #if defined(XALAN_NO_NAMESPACES)
  	typedef deque<OutputContext>			OutputContextStackType;
  #else
  	typedef std::deque<OutputContext>		OutputContextStackType;
  #endif
  
  	typedef OutputContextStackType::size_type	size_type;
  
  	explicit
  	OutputContextStack();
  
  	~OutputContextStack();
  
  	void
  	pushContext(FormatterListener*	theListener = 0);
  
  	void
  	popContext();
  
  	FormatterListener*
  	getFormatterListener() const
  	{
  		return (*m_stackPosition).m_flistener;
  	}
  
  	FormatterListener*&
  	getFormatterListener()
  	{
  		return (*m_stackPosition).m_flistener;
  	}
  
  	const AttributeListImpl&
  	getPendingAttributes() const
  	{
  		return (*m_stackPosition).m_pendingAttributes;
  	}
  
  	AttributeListImpl&
  	getPendingAttributes()
  	{
  		return (*m_stackPosition).m_pendingAttributes;
  	}
  
  	const XalanDOMString&
  	getPendingElementName() const
  	{
  		return (*m_stackPosition).m_pendingElementName;
  	}
  
  	XalanDOMString&
  	getPendingElementName()
  	{
  		return (*m_stackPosition).m_pendingElementName;
  	}
  
  	const bool&
  	getHasPendingStartDocument() const
  	{
  		return (*m_stackPosition).m_hasPendingStartDocument;
  	}
  
  	bool&
  	getHasPendingStartDocument()
  	{
  		return (*m_stackPosition).m_hasPendingStartDocument;
  	}
  
  	const bool&
  	getMustFlushPendingStartDocument() const
  	{
  		return (*m_stackPosition).m_mustFlushPendingStartDocument;
  	}
  
  	bool&
  	getMustFlushPendingStartDocument()
  	{
  		return (*m_stackPosition).m_mustFlushPendingStartDocument;
  	}
  
  	size_type
  	size() const
  	{
  		// Since we always keep one dummy entry at the beginning,
  		// subtract one from the size
  		return m_stack.size() - 1;
  	}
  
  	bool
  	empty() const
  	{
  		return size() == 0 ? true : false;
  	}
  
  	void
  	clear();
  
  	void
  	reset();
  
  private:
  
  	// not implemented
  	OutputContextStack(const OutputContextStack&);
  
  	bool
  	operator==(const OutputContextStack&) const;
  
  	OutputContextStack&
  	operator=(const OutputContextStack&);
  
  	/**
  	 * A stack to hold the output contexts...
  	 */
  	OutputContextStackType				m_stack;
  
  	OutputContextStackType::iterator	m_stackPosition;
  };
  
  
  
  #endif	// XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD
  
  
  
  1.1                  xml-xalan/c/src/XSLT/ResultNamespacesStack.cpp
  
  Index: ResultNamespacesStack.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  // Class header file...
  #include "ResultNamespacesStack.hpp"
  
  
  
  ResultNamespacesStack::ResultNamespacesStack() :
  	m_resultNamespaces(),
  	m_createNewContextStack()
  {
  }
  
  
  
  ResultNamespacesStack::~ResultNamespacesStack()
  {
  }
  
  
  
  void
  ResultNamespacesStack::addDeclaration(
  			const XalanDOMString&	thePrefix,
  			const XalanDOMString&	theNamespaceURI)
  {
  	assert(m_createNewContextStack.size() != 0);
  
  	// Check to see if we need to create a new context and do so if necessary...
  	if (m_createNewContextStack.back() == true)
  	{
  		m_resultNamespaces.resize(m_resultNamespaces.size() + 1);
  
  		m_resultNamespaces.back().resize(1);
  
  		m_createNewContextStack.back() = false;
  	}
  
  	NamespaceVectorType&	theCurrentNamespaces = m_resultNamespaces.back();
  
  	NameSpace&				theCurrentNamespace = theCurrentNamespaces.front();
  
  	// If the last vector contains only an empty namespace, replace it with a
  	// new vector containing only this namespace
  	if(isEmpty(theCurrentNamespace.getURI()))
  	{
  		theCurrentNamespace.setPrefix(thePrefix);
  
  		theCurrentNamespace.setURI(theNamespaceURI);
  	}
  	else
  	{
  		// Otherwise, add the namespace at the end of the current namespaces.
  		theCurrentNamespaces.push_back(NameSpace(thePrefix, theNamespaceURI));
  	}
  }
  
  
  
  void
  ResultNamespacesStack::pushContext()
  {
  	if (m_createNewContextStack.size() == 0)
  	{
  		m_createNewContextStack.reserve(eDefaultCreateNewContextStackSize);
  	}
  
  	m_createNewContextStack.push_back(true);
  }
  
  
  
  void
  ResultNamespacesStack::popContext()
  {
  	assert(m_createNewContextStack.size() != 0);
  
  	if (m_createNewContextStack.back() == false)
  	{
  		assert(m_resultNamespaces.size() != 0);
  
  		m_resultNamespaces.pop_back();
  	}
  
  	m_createNewContextStack.pop_back();
  }
  
  
  
  const XalanDOMString&
  ResultNamespacesStack::getNamespaceForPrefix(const XalanDOMString&	thePrefix) const
  {
  	// Search vector from first element back
  	return QName::getNamespaceForPrefix(m_resultNamespaces, thePrefix, false);
  }
  
  
  
  const XalanDOMString&
  ResultNamespacesStack::getPrefixForNamespace(const XalanDOMString&	theNamespaceURI) const
  {
  	// Search vector from first element back
  	return QName::getPrefixForNamespace(m_resultNamespaces, theNamespaceURI, false);
  }
  
  
  
  void
  ResultNamespacesStack::clear()
  {
  	m_resultNamespaces.clear();
  
  	m_createNewContextStack.clear();
  }
  
  
  
  1.1                  xml-xalan/c/src/XSLT/ResultNamespacesStack.hpp
  
  Index: ResultNamespacesStack.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD)
  #define XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD
  
  
  
  // Base include file.  Must be first.
  #include <XSLT/XSLTDefinitions.hpp>
  
  
  
  #include <vector>
  
  
  
  #include <XalanDOM/XalanDOMString.hpp>
  
  
  
  #include <XPath/QName.hpp>
  
  
  
  class XALAN_XSLT_EXPORT ResultNamespacesStack
  {
  public:
  
  #if defined(XALAN_NO_NAMESPACES)
  	typedef vector<bool>					BoolVectorType;
  #else
  	typedef std::vector<bool>				BoolVectorType;
  #endif
  
  	typedef QName::NamespaceVectorType		NamespaceVectorType;
  	typedef QName::NamespacesStackType		NamespacesStackType;
  
  	explicit
  	ResultNamespacesStack();
  
  	~ResultNamespacesStack();
  
  	void
  	addDeclaration(
  			const XalanDOMString&	thePrefix,
  	        const XalanDOMString&	theNamespaceURI);
  
  	void
  	pushContext();
  
  	void
  	popContext();
  
  	const XalanDOMString&
  	getNamespaceForPrefix(const XalanDOMString&		thePrefix) const;
  
  	const XalanDOMString&
  	getPrefixForNamespace(const XalanDOMString&		theNamespaceURI) const;
  
  	void
  	clear();
  
  private:
  
  	// not implemented
  	ResultNamespacesStack(const ResultNamespacesStack&);
  
  	bool
  	operator==(const ResultNamespacesStack&) const;
  
  	ResultNamespacesStack&
  	operator=(const ResultNamespacesStack&);
  
  	enum { eDefaultCreateNewContextStackSize = 100 };
  
  	/**
  	 * A stack to keep track of the result tree namespaces.
  	 */
  	NamespacesStackType		m_resultNamespaces;
  
  	BoolVectorType			m_createNewContextStack;
  };
  
  
  
  #endif	// XALAN_RESULTNAMESPACESSTACK_HEADER_GUARD