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/12/21 05:45:28 UTC

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

dbertoni    00/12/20 20:45:28

  Modified:    c/src/XSLT ElemNumber.cpp ElemNumber.hpp
  Log:
  Fixed bug where counts were not cached.  Moved Counter and CountersTable to CountersTable.hpp/cpp.
  
  Revision  Changes    Path
  1.31      +6 -133    xml-xalan/c/src/XSLT/ElemNumber.cpp
  
  Index: ElemNumber.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemNumber.cpp,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ElemNumber.cpp	2000/11/21 21:09:57	1.30
  +++ ElemNumber.cpp	2000/12/21 04:45:27	1.31
  @@ -84,6 +84,7 @@
   
   #include "AVT.hpp"
   #include "Constants.hpp"
  +#include "CountersTable.hpp"
   #include "StylesheetConstructionContext.hpp"
   #include "StylesheetExecutionContext.hpp"
   
  @@ -394,7 +395,7 @@
   	}
   	else
   	{
  -		CountersTable	ctable;
  +		CountersTable&	ctable = executionContext.getCountersTable();
   
   		if(Constants::NUMBERLEVEL_ANY == m_level)
   		{
  @@ -428,10 +429,12 @@
   	return numberList.size() > 0 ? formatNumberList(executionContext, numberList, sourceNode) : XalanDOMString();
   }
   
  +
  +
   XalanNode*
   ElemNumber::getPreviousNode(
  -		StylesheetExecutionContext&		executionContext,
  -		XalanNode* pos) const
  +			StylesheetExecutionContext&		executionContext,
  +			XalanNode*						pos) const
   {
   	// Create an XPathGuard, since we may need to
   	// create a new XPath...
  @@ -1357,136 +1360,6 @@
   		count++;
   	}
   	return count;
  -}
  -
  -
  -
  -ElemNumber::CounterVectorType& ElemNumber::CountersTable::getCounters(const ElemNumber* numberElem)
  -{
  -	return m_counterMap[numberElem];
  -}
  -
  -
  -
  -void
  -ElemNumber::CountersTable::appendBtoFList(MutableNodeRefList& flist, MutableNodeRefList& blist)
  -{
  -	const int n = blist.getLength();
  -
  -	for(int i = n - 1; i >= 0; i--)
  -	{
  -		flist.addNode(blist.item(i));
  -	}
  -}
  -
  -
  -
  -int
  -ElemNumber::CountersTable::countNode(
  -			StylesheetExecutionContext&		support,
  -			const ElemNumber*				numberElem,
  -			XalanNode*						node)
  -{
  -	int		count = 0;
  -
  -	CounterVectorType&	counters = getCounters(numberElem);
  -
  -	const CounterVectorType::size_type	nCounters = counters.size();
  -
  -	XalanNode* 	target = numberElem->getTargetNode(support, node);
  -
  -	if(0 != target)
  -	{
  -		for(CounterVectorType::size_type i = 0; i < nCounters; i++)
  -		{    
  -			const Counter&	counter = counters[i];
  -
  -			count = counter.getPreviouslyCounted(support, target);
  -			if(count > 0)
  -				return count;
  -		}
  -
  -		// In the loop below, we collect the nodes in backwards doc order, so 
  -		// we don't have to do inserts, but then we store the nodes in forwards 
  -		// document order, so we don't have to insert nodes into that list, 
  -		// so that's what the appendBtoFList stuff is all about.  In cases 
  -		// of forward counting by one, this will mean a single node copy from 
  -		// the backwards list (m_newFound) to the forwards list
  -		// (counter.m_countNodes).
  -		count = 0;
  -		for(; 0 != target; target = numberElem->getPreviousNode(support, target))
  -		{   
  -			// First time in, we should not have to check for previous counts, 
  -			// since the original target node was already checked in the 
  -			// block above.
  -			if(0 != count)  
  -			{
  -				for(CounterVectorType::size_type i = 0; i < nCounters; i++)
  -				{
  -					Counter&	counter = counters[i];
  -
  -					const unsigned int	cacheLen = counter.m_countNodes.getLength();
  -
  -					if((cacheLen > 0) &&
  -							(counter.m_countNodes.item(cacheLen-1) == target))
  -					{
  -						count += cacheLen + counter.m_countNodesStartCount;
  -						if(cacheLen > 0)
  -							appendBtoFList(counter.m_countNodes, m_newFound);
  -						m_newFound.clear();
  -						return count;
  -					}
  -				}
  -			}
  -			m_newFound.addNode(target);
  -			count++;
  -		}
  -		// If we got to this point, then we didn't find a counter, so make 
  -		// one and add it to the list.
  -		ElemNumber::Counter counter(numberElem);
  -		m_countersMade++; // for diagnostics
  -		appendBtoFList(counter.m_countNodes, m_newFound);
  -		m_newFound.clear();
  -		counters.push_back(counter);
  -	}
  -
  -	return count;
  -}
  -
  -
  -
  -int
  -ElemNumber::Counter::getPreviouslyCounted(
  -		StylesheetExecutionContext&		support,
  -		const XalanNode*				node) const
  -{
  -	const int n = m_countNodes.getLength();
  -	int result = 0;
  -
  -	for(int i = n-1;i >= 0; i--)
  -	{
  -		const XalanNode* countedNode = m_countNodes.item(i);
  -		if(node == countedNode)
  -		{
  -			// Since the list is in backwards order, the count is 
  -			// how many are in the rest of the list.
  -			result = i + 1 + m_countNodesStartCount;
  -			break;
  -		}
  -
  -		// Try to see if the given node falls after the counted node...
  -		// if it does, don't keep searching backwards.
  -		if(support.isNodeAfter(*countedNode, *node))
  -			break;
  -	}
  -
  -	return result;
  -}
  -
  -XalanNode* ElemNumber::Counter::getLast()
  -{
  -	const int size = m_countNodes.getLength();
  -	return (size > 0) ? m_countNodes.item(size-1) : 0;
   }
   
   
  
  
  
  1.23      +15 -161   xml-xalan/c/src/XSLT/ElemNumber.hpp
  
  Index: ElemNumber.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemNumber.hpp,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ElemNumber.hpp	2000/11/30 20:34:08	1.22
  +++ ElemNumber.hpp	2000/12/21 04:45:27	1.23
  @@ -58,7 +58,7 @@
   #define XALAN_ELEMNUMBER_HEADER_GUARD 
   
   /**
  - * $Id: ElemNumber.hpp,v 1.22 2000/11/30 20:34:08 auriemma Exp $
  + * $Id: ElemNumber.hpp,v 1.23 2000/12/21 04:45:27 dbertoni Exp $
    * 
    * $State: Exp $
    * 
  @@ -103,19 +103,12 @@
   #if defined(XALAN_NO_NAMESPACES)
   	typedef vector<DecimalToRoman>					DecimalToRomanVectorType;
   	typedef vector<int>								IntArrayType;
  -	typedef vector<Counter>							CounterVectorType;
  -	typedef map<const ElemNumber*,
  -				CounterVectorType,
  -				less<const ElemNumber*> >			ElemToCounterVectorMapType;
   	typedef map<XalanDOMChar,
   				XalanNumberingResourceBundle,
   				less<XalanDOMChar> >				NumberingResourceBundleMapType;
   #else
   	typedef std::vector<DecimalToRoman>				DecimalToRomanVectorType;
   	typedef std::vector<int>						IntArrayType;
  -	typedef std::vector<Counter>					CounterVectorType;
  -	typedef std::map<const ElemNumber*,
  -					 CounterVectorType>				ElemToCounterVectorMapType;
   	typedef std::map<XalanDOMChar,
   					 XalanNumberingResourceBundle>	NumberingResourceBundleMapType;
   #endif
  @@ -162,6 +155,20 @@
   			XalanNode*						sourceNode,
   			const QName&					mode) const;
   
  +	/**
  +	 * Get the previous node to be counted.
  +	 */
  +	XalanNode* getPreviousNode(
  +			StylesheetExecutionContext&		executionContext,
  +			XalanNode*						pos) const;
  +
  +	/**
  +	 * Get the target node that will be counted..
  +	 */
  +	XalanNode* getTargetNode(
  +			StylesheetExecutionContext&		executionContext,
  +			XalanNode*						sourceNode) const;
  +
   protected:
   
   	/**
  @@ -217,20 +224,6 @@
   			XalanNode*						sourceNode) const;
   
   	/**
  -	 * Get the previous node to be counted.
  -	 */
  -	XalanNode* getPreviousNode(
  -			StylesheetExecutionContext&		executionContext,
  -			XalanNode*						pos) const;
  -
  -	/**
  -	 * Get the target node that will be counted..
  -	 */
  -	XalanNode* getTargetNode(
  -			StylesheetExecutionContext&		executionContext,
  -			XalanNode*						sourceNode) const;
  -
  -	/**
   	 * Get the ancestors, up to the root, that match the
   	 * pattern.
   	 * @param patterns if non-0, count only nodes
  @@ -493,145 +486,6 @@
   			int				m_maxPosition;
   			XalanDOMString	m_str;
   	}; // end NumberFormatStringTokenizer
  -
  -	/**
  -	 * <meta name="usage" content="internal"/>
  -	 * This is a table of counters, keyed by ElemNumber objects, each 
  -	 * of which has a list of Counter objects.  This really isn't a true 
  -	 * table, it is more like a list of lists (there must be a technical 
  -	 * term for that...).
  -	 */
  -	class CountersTable
  -	{
  -		public:
  -
  -			/**
  -			 * Construct a CountersTable.
  -			 */
  -			CountersTable() : 
  -				m_countersMade(0)
  -				{
  -				};
  -
  -
  -			/**
  -			 * Count forward until the given node is found, or until 
  -			 * we have looked to the given amount.
  -			 * @node The node to count.
  -			 * @return The node count, or 0 if not found.
  -			 */
  -			int
  -			countNode(
  -					StylesheetExecutionContext&		support,
  -					const ElemNumber*				numberElem,
  -					XalanNode*						node);
  -
  -		private:
  -
  -			/**
  -			 * Get the list of counters that corresponds to 
  -			 * the given ElemNumber object.
  -			 */
  -			CounterVectorType& getCounters(const ElemNumber*	numberElem);
  -
  -			/**
  -			 * Add a list of counted nodes that were built in backwards document 
  -			 * order, or a list of counted nodes that are in forwards document 
  -			 * order.
  -			 */
  -			void appendBtoFList(MutableNodeRefList& flist, MutableNodeRefList& blist);
  -
  -			/**
  -			 * Place to collect new counters.
  -			 */
  -			MutableNodeRefList m_newFound;
  -
  -			// For diagnostics
  -			int m_countersMade;
  -
  -			ElemToCounterVectorMapType	m_counterMap;
  -
  -	}; // end CountersTable
  -
  -	friend class CountersTable;
  -
  -	/**
  -	 * <meta name="usage" content="internal"/>
  -	 * A class that does incremental counting for support of xsl:number.
  -	 * This class stores a cache of counted nodes (m_countNodes). 
  -	 * It tries to cache the counted nodes in document order... 
  -	 * the node count is based on its position in the cache list 
  -	 */
  -	struct Counter
  -	{
  -		/**
  -		 * The start count from where m_countNodes counts 
  -		 * from.  In other words, the count of a given node 
  -		 * in the m_countNodes vector is node position + 
  -		 * m_countNodesStartCount.
  -		 */
  -		int							m_countNodesStartCount;
  -
  -		/**
  -		 * A vector of all nodes counted so far.
  -		 */
  -		MutableNodeRefList			m_countNodes;
  -
  -		/**
  -		 * The node from where the counting starts.  This is needed to 
  -		 * find a counter if the node being counted is not immediatly
  -		 * found in the m_countNodes vector.
  -		 */
  -		const XalanNode*			m_fromNode;
  -
  -		/**
  -		 * The owning xsl:number element.
  -		 */
  -		const ElemNumber*			m_numberElem;
  -
  -		/**
  -		 * Construct a counter object.
  -		 */
  -		Counter(
  -				const ElemNumber*		numberElem,
  -				MutableNodeRefList&		countNodes) :
  -			m_countNodesStartCount(0),
  -			m_countNodes(countNodes),
  -			m_fromNode(0),
  -			m_numberElem(numberElem)
  -		{
  -		}
  -
  -		/**
  -		 * Construct a counter object.
  -		 */
  -		Counter(const ElemNumber*	numberElem = 0) :
  -			m_countNodesStartCount(0),
  -			m_countNodes(),
  -			m_fromNode(0),
  -			m_numberElem(numberElem)
  -		{
  -		}
  -
  -		/**
  -		 * Try to find a node that was previously counted. If found, return a
  -		 * positive integer that corresponds to the count.
  -		 * @param node The node to be counted.
  -		 * @returns The count of the node, or -1 if not found.
  -		 */
  -		int
  -		getPreviouslyCounted(
  -				StylesheetExecutionContext&		support,
  -				const XalanNode*				node) const;
  -
  -		/**
  -		 * Get the last node in the list.
  -		 */
  -		XalanNode*
  -		getLast();
  -	}; // end Counter
  -
  -	friend struct Counter;
   
   }; // end ElemNumber