dbertoni    2003/01/06 16:40:30

  Modified:    c/src/XPath XPath.cpp XPath.hpp XPathExpression.cpp
                        XPathExpression.hpp
  Log:
  New code to "inline" more XPath functions.
  
  Revision  Changes    Path
  1.87      +66 -0     xml-xalan/c/src/XPath/XPath.cpp
  
  Index: XPath.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- XPath.cpp 3 Jan 2003 21:46:30 -0000       1.86
  +++ XPath.cpp 7 Jan 2003 00:40:29 -0000       1.87
  @@ -473,6 +473,10 @@
                return 
executionContext.getXObjectFactory().createNumber(functionStringLength(context, 
opPos, executionContext));
                break;
   
  +     case XPathExpression::eOP_FUNCTION_SUM:
  +             return 
executionContext.getXObjectFactory().createNumber(functionSum(context, opPos, 
executionContext));
  +             break;
  +
        default:
                unknownOpCodeError(context, executionContext, opPos);
                break;
  @@ -656,6 +660,10 @@
                result = XObject::boolean(functionStringLength(context, opPos, 
executionContext));
                break;
   
  +     case XPathExpression::eOP_FUNCTION_SUM:
  +             result = XObject::boolean(functionSum(context, opPos, 
executionContext));
  +             break;
  +
        default:
                unknownOpCodeError(context, executionContext, opPos);
                break;
  @@ -837,6 +845,10 @@
                result = functionStringLength(context, opPos, executionContext);
                break;
   
  +     case XPathExpression::eOP_FUNCTION_SUM:
  +             result = functionSum(context, opPos, executionContext);
  +             break;
  +
        default:
                unknownOpCodeError(context, executionContext, opPos);
                break;
  @@ -1018,6 +1030,10 @@
                XObject::string(functionStringLength(context, opPos, 
executionContext), result);
                break;
   
  +     case XPathExpression::eOP_FUNCTION_SUM:
  +             XObject::string(functionSum(context, opPos, executionContext), 
result);
  +             break;
  +
        default:
                unknownOpCodeError(context, executionContext, opPos);
                break;
  @@ -1235,6 +1251,10 @@
                XObject::string(functionStringLength(context, opPos, 
executionContext), formatterListener, function);
                break;
   
  +     case XPathExpression::eOP_FUNCTION_SUM:
  +             XObject::string(functionSum(context, opPos, executionContext), 
formatterListener, function);
  +             break;
  +
        default:
                unknownOpCodeError(context, executionContext, opPos);
                break;
  @@ -1296,6 +1316,7 @@
        case XPathExpression::eOP_FUNCTION_STRINGLENGTH_1:
        case XPathExpression::eOP_FUNCTION_NAMESPACEURI_0:
        case XPathExpression::eOP_FUNCTION_NAMESPACEURI_1:
  +     case XPathExpression::eOP_FUNCTION_SUM:
                notNodeSetError(context, executionContext);
                break;
   
  @@ -2717,6 +2738,51 @@
        executeMore(context, opPos + 2, executionContext, theCounter, 
&FormatterListener::characters);
   
        return theCounter.getCount();
  +}
  +
  +
  +
  +double
  +XPath::functionSum(
  +                     XalanNode*                              context,
  +                     int                                             opPos,
  +                     XPathExecutionContext&  executionContext) const
  +{
  +     assert(context != 0);
  +
  +     double  sum = 0.0;
  +
  +     typedef XPathExecutionContext::BorrowReturnMutableNodeRefList   
BorrowReturnMutableNodeRefList;
  +
  +     BorrowReturnMutableNodeRefList  result(executionContext);
  +
  +     const XObjectPtr        nodesetResult(executeMore(context, opPos + 2, 
executionContext, *result));
  +
  +     const NodeRefListBase* const    theNodeList = nodesetResult.null() == 
false ?
  +                     &nodesetResult->nodeset() : &*result;
  +     assert(theNodeList != 0);
  +
  +     const NodeRefListBase::size_type        theLength = 
theNodeList->getLength();
  +
  +     if (theLength != 0)
  +     {
  +             assert(theNodeList->item(0) != 0);
  +
  +             XPathExecutionContext::GetAndReleaseCachedString        
theData(executionContext);
  +
  +             XalanDOMString&         theString = theData.get();
  +
  +             for (NodeRefListBase::size_type i = 0; i < theLength; i++)
  +             {
  +                     DOMServices::getNodeData(*theNodeList->item(i), 
theString);
  +
  +                     sum = DoubleSupport::add(sum, 
DoubleSupport::toDouble(theString));
  +
  +                     clear(theString);
  +             }
  +     }
  +
  +     return sum;
   }
   
   
  
  
  
  1.41      +14 -0     xml-xalan/c/src/XPath/XPath.hpp
  
  Index: XPath.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.hpp,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- XPath.hpp 3 Jan 2003 21:46:30 -0000       1.40
  +++ XPath.hpp 7 Jan 2003 00:40:30 -0000       1.41
  @@ -1961,6 +1961,20 @@
                        XPathExecutionContext&  executionContext) const;
   
        /**
  +      * Handle the built-in function "sum".
  +      *
  +      * @param context The current source tree context node.
  +      * @param opPos The current position in the m_opMap array.
  +      * @param executionContext current execution context
  +      * @return the result of the function.
  +      */
  +     double
  +     functionSum(
  +                     XalanNode*                              context,
  +                     int                                             opPos,
  +                     XPathExecutionContext&  executionContext) const;
  +
  +     /**
         * Get a numeric operand for an expression.
         * @param context The current source tree context node.
         * @param opPos The current position in the m_opMap array.
  
  
  
  1.44      +2 -0      xml-xalan/c/src/XPath/XPathExpression.cpp
  
  Index: XPathExpression.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.cpp,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- XPathExpression.cpp       3 Jan 2003 08:04:24 -0000       1.43
  +++ XPathExpression.cpp       7 Jan 2003 00:40:30 -0000       1.44
  @@ -191,6 +191,8 @@
        XPathExpression::s_opCodeMapLengthIndex + 1,
        XPathExpression::s_opCodeMapLengthIndex + 1,
        XPathExpression::s_opCodeMapLengthIndex + 1,
  +     XPathExpression::s_opCodeMapLengthIndex + 1,
  +     XPathExpression::s_opCodeMapLengthIndex + 1,
        XPathExpression::s_opCodeMapLengthIndex + 1
   };
   
  
  
  
  1.34      +2 -0      xml-xalan/c/src/XPath/XPathExpression.hpp
  
  Index: XPathExpression.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.hpp,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XPathExpression.hpp       3 Jan 2003 08:04:24 -0000       1.33
  +++ XPathExpression.hpp       7 Jan 2003 00:40:30 -0000       1.34
  @@ -603,6 +603,8 @@
                eOP_FUNCTION_STRINGLENGTH_1 = 75,
                eOP_FUNCTION_NAMESPACEURI_0 = 76,
                eOP_FUNCTION_NAMESPACEURI_1 = 77,
  +             eOP_FUNCTION_SUM = 78,
  +             eOP_FUNCTION_CONCAT = 79,
   
                // Always add _before_ this one and update
                // s_opCodeLengthArray.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to