#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 #include /*static*/ const XMLCh Minus::name[]={ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_m, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_i, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_n, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_u, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_s, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; Minus::Minus(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : DataItemOperator(name, args, memMgr) { } Sequence Minus::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("Minus::collapseTreeInternal"), X("The operator subtract ('-') 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)->subtract((const Numeric*)atom2, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An attempt to subtract a non numeric type from a numeric type has occurred")); } } switch(atom1->getPrimitiveTypeIndex()) { case AnyAtomicType::DATE : { switch(atom2->getPrimitiveTypeIndex()) { case AnyAtomicType::DURATION : { const ATDurationOrDerived* duration = (const ATDurationOrDerived*)atom2; if(duration->isYearMonthDuration()) { return Sequence( ((const ATDateOrDerived*)atom1)->subtractYearMonthDuration(duration, context), memMgr); } else if(duration->isDayTimeDuration()) { return Sequence( ((const ATDateOrDerived*)atom1)->subtractDayTimeDuration(duration, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An invalid attempt to subtract from xs:date type has occurred")); } } case AnyAtomicType::DATE : { return Sequence( ((const ATDateOrDerived*)atom1)->subtractDate((const ATDateOrDerived*)atom2, context), memMgr); } default: { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An invalid attempt to subtract from xs:date type has occurred")); } }// switch } case AnyAtomicType::TIME : { switch(atom2->getPrimitiveTypeIndex()) { case AnyAtomicType::DURATION : { // assume dayTimeDuration, otherwise function will throw return Sequence( ((const ATTimeOrDerived*)atom1)->subtractDayTimeDuration( (const ATDurationOrDerived*)atom2, context ), memMgr ); } case AnyAtomicType::TIME : { return Sequence( ((const ATTimeOrDerived*)atom1)->subtractTime((const ATTimeOrDerived*)atom2, context), memMgr); } default: { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An invalid attempt to subtract from xs:time type has occurred")); } }// switch } case AnyAtomicType::DATE_TIME : { switch(atom2->getPrimitiveTypeIndex()) { case AnyAtomicType::DURATION : { const ATDurationOrDerived* duration = (const ATDurationOrDerived*)atom2; if(duration->isYearMonthDuration()) { return Sequence( ((const ATDateTimeOrDerived*)atom1)->subtractYearMonthDuration(duration, context), memMgr); } else if(duration->isDayTimeDuration()) { return Sequence( ((const ATDateTimeOrDerived*)atom1)->subtractDayTimeDuration(duration, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An invalid attempt to subtract from xs:dateTime type has occurred")); } } case AnyAtomicType::DATE_TIME : { return Sequence( ((const ATDateTimeOrDerived*)atom1)->subtractDateTimeAsDayTimeDuration((const ATDateTimeOrDerived*)atom2, context), memMgr); } default: { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An invalid attempt to subtract from xs:dateTime type has occurred")); } }// switch } case AnyAtomicType::DURATION : { switch(atom2->getPrimitiveTypeIndex()) { case AnyAtomicType::DURATION : { // this call will throw an error if the duration is of the wrong type return Sequence( ((const ATDurationOrDerived*)atom1)->subtract((const ATDurationOrDerived*)atom2, context), memMgr); } default: { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("An invalid attempt to subtract from xs:duration type has occurred")); } }// switch } default: { DSLthrow(XPath2ErrorException,X("Minus::collapseTreeInternal"), X("The operator subtract ('-') has been called on invalid operand types")); } }// switch }