#include "../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include #include #include #include #include #include #include #include /*static*/ const XMLCh Multiply::name[]={ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_m, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_u, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_l, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; Multiply::Multiply(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : DataItemOperator(name, args, memMgr) { // Nothing to do } Sequence Multiply::collapseTreeInternal(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence newArgs = getArithmeticOperatorArguments(context); if(newArgs.getLength() < 2) return Sequence(memMgr); if(!newArgs.first()->isAtomicValue() || !newArgs.second()->isAtomicValue()) { DSLthrow(XPath2ErrorException,X("Multiply::collapseTreeInternal"), X("The operator multiply ('*') has been called on invalid operand types")); } const AnyAtomicType* atom1 = (const AnyAtomicType*)newArgs.first(); const AnyAtomicType* atom2 = (const AnyAtomicType*)newArgs.second(); // xs:decimal * xs:duration (only xdt:dayTimeDuration and xdt:yearMonthDuration) if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::DECIMAL && atom2->getPrimitiveTypeIndex() == AnyAtomicType::DURATION) { return Sequence( ((const ATDurationOrDerived*)atom2)->multiply((const ATDecimalOrDerived*)atom1, context), memMgr); } // xs:duration * xs:decimal (only xdt:dayTimeDuration and xdt:yearMonthDuration) if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::DURATION && atom2->getPrimitiveTypeIndex() == AnyAtomicType::DECIMAL ) { return Sequence( ((const ATDurationOrDerived*)atom1)->multiply((const ATDecimalOrDerived*)atom2, context), memMgr); } // numeric * numeric if(atom1->isNumericValue()) { if(atom2->isNumericValue()) { return Sequence(((const Numeric*)atom1)->multiply((const Numeric*)atom2, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Multiply::collapseTreeInternal"), X("An attempt to multiply a non numeric type to a numeric type has occurred")); } } DSLthrow(XPath2ErrorException,X("Multiply::collapseTreeInternal"), X("The operator * has been called on invalid operand types")); }