#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 Plus::name[]={ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_p, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_l, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_u, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_s, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; Plus::Plus(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : DataItemOperator(name, args, memMgr) { // Nothing to do } Sequence Plus::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("Plus::collapseTreeInternal"), X("The operator add ('+') 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)->add((const Numeric*)atom2, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An attempt to add a non numeric type to 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)->addYearMonthDuration(duration, context), memMgr); } else if(duration->isDayTimeDuration()) { return Sequence( ((const ATDateOrDerived*)atom1)->addDayTimeDuration(duration, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:date type has occurred")); } } default: { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:date type has occurred")); } }// switch } case AnyAtomicType::TIME : { switch(atom2->getPrimitiveTypeIndex()) { case AnyAtomicType::DURATION : { // assume xdt:dayTimeDuration, otherwise function will throw return Sequence( ((const ATTimeOrDerived*)atom1)->addDayTimeDuration( (const ATDurationOrDerived*)atom2, context ), memMgr ); } default: { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to 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)->addYearMonthDuration(duration, context), memMgr); } else if(duration->isDayTimeDuration()) { return Sequence( ((const ATDateTimeOrDerived*)atom1)->addDayTimeDuration(duration, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:dateTime type has occurred")); } } default: { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:dateTime type has occurred")); } }// switch } case AnyAtomicType::DURATION : { const ATDurationOrDerived* duration = (const ATDurationOrDerived*)atom1; switch(atom2->getPrimitiveTypeIndex()) { case AnyAtomicType::DURATION : { // this call will throw an error if the duration is of the wrong type return Sequence( duration->add((const ATDurationOrDerived*)atom2, context), memMgr); } case AnyAtomicType::DATE: { if(duration->isYearMonthDuration()) { return Sequence( ((const ATDateOrDerived*)atom2)->addYearMonthDuration(duration, context), memMgr); } else if (duration->isDayTimeDuration()) { return Sequence( ((const ATDateOrDerived*)atom2)->addDayTimeDuration(duration, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:duration type has occurred")); } } case AnyAtomicType::DATE_TIME: { if(duration->isYearMonthDuration()) { return Sequence( ((const ATDateTimeOrDerived*)atom2)->addYearMonthDuration(duration, context), memMgr); } else if (duration->isDayTimeDuration()) { return Sequence( ((const ATDateTimeOrDerived*)atom2)->addDayTimeDuration(duration, context), memMgr); } else { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:duration type has occurred")); } } case AnyAtomicType::TIME: { // assume xdt:dayTimeDuration, otherwise will throw return Sequence( ((const ATTimeOrDerived*)atom2)->addDayTimeDuration(duration, context), memMgr); } default: { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("An invalid attempt to add to xs:duration type has occurred")); } }// switch } default: { DSLthrow(XPath2ErrorException,X("Plus::collapseTreeInternal"), X("The operator add ('+') has been called on invalid operand types")); } }// switch }