#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 Divide::name[]={ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_d, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_i, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_v, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; Divide::Divide(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : DataItemOperator(name, args, memMgr) { // Nothing to do } Sequence Divide::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("Divide::collapseTreeInternal"), X("The operator div has been called on invalid operand types")); } const AnyAtomicType* atom1 = (const AnyAtomicType*)newArgs.first(); const AnyAtomicType* atom2 = (const AnyAtomicType*)newArgs.second(); if(atom1->isNumericValue()) { if(atom2->isNumericValue()) { return Sequence(((const Numeric*)atom1)->divide((const Numeric*)atom2, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Divide::collapseTreeInternal"), X("An attempt to divide a non numeric type to a numeric type has occurred")); } } if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::DURATION) { if(atom2->getPrimitiveTypeIndex() == AnyAtomicType::DECIMAL) { const ATDurationOrDerived* duration = (const ATDurationOrDerived*)atom1; const ATDecimalOrDerived* num = (const ATDecimalOrDerived*)atom2; if(duration->isDayTimeDuration() || duration->isYearMonthDuration()) { return Sequence (duration->divide(num, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Divide::collapseTreeInternal"), X("An invalid attempt to divide an xs:duration by a decimal type has occurred")); } } else { DSLthrow(XPath2ErrorException,X("Divide::collapseTreeInternal"), X("An invalid attempt to divide an xs:duration by a non-decimal type has occured")); } } else { DSLthrow(XPath2ErrorException,X("Divide::collapseTreeInternal"), X("The operator div has been called on invalid operand types")); } }