bool operator()(const AnyAtomicType::Ptr &a, const AnyAtomicType::Ptr &b) const { AnyAtomicType::AtomicObjectType atype = getSortType(a); AnyAtomicType::AtomicObjectType btype = getSortType(b); if(atype != btype) return atype < btype; // Items are comparable switch(atype) { case AnyAtomicType::STRING: return collation_->compare(a->asString(context_), b->asString(context_)) < 0; case AnyAtomicType::DOUBLE: return ((const Numeric *)a.get())->compare((const Numeric *)b.get(), context_) < 0; case AnyAtomicType::DURATION: return ((const ATDurationOrDerived *)a.get())->compare((const ATDurationOrDerived *)b.get(), context_) < 0; case AnyAtomicType::BASE_64_BINARY: return ((const ATBase64BinaryOrDerived *)a.get())->compare((const ATBase64BinaryOrDerived *)b.get(), context_) < 0; case AnyAtomicType::BOOLEAN: return ((const ATBooleanOrDerived *)a.get())->compare((const ATBooleanOrDerived *)b.get(), context_) < 0; case AnyAtomicType::DATE: return ((const ATDateOrDerived *)a.get())->compare((const ATDateOrDerived *)b.get(), context_) < 0; case AnyAtomicType::DATE_TIME: return ((const ATDateTimeOrDerived *)a.get())->compare((const ATDateTimeOrDerived *)b.get(), context_) < 0; case AnyAtomicType::G_DAY: return ((const ATGDayOrDerived *)a.get())->compare((const ATGDayOrDerived *)b.get(), context_) < 0; case AnyAtomicType::G_MONTH: return ((const ATGMonthOrDerived *)a.get())->compare((const ATGMonthOrDerived *)b.get(), context_) < 0; case AnyAtomicType::G_MONTH_DAY: return ((const ATGMonthDayOrDerived *)a.get())->compare((const ATGMonthDayOrDerived *)b.get(), context_) < 0; case AnyAtomicType::G_YEAR: return ((const ATGYearOrDerived *)a.get())->compare((const ATGYearOrDerived *)b.get(), context_) < 0; case AnyAtomicType::G_YEAR_MONTH: return ((const ATGYearMonthOrDerived *)a.get())->compare((const ATGYearMonthOrDerived *)b.get(), context_) < 0; case AnyAtomicType::HEX_BINARY: return ((const ATHexBinaryOrDerived *)a.get())->compare((const ATHexBinaryOrDerived *)b.get(), context_) < 0; case AnyAtomicType::NOTATION: return ((const ATNotationOrDerived *)a.get())->compare((const ATNotationOrDerived *)b.get(), context_) < 0; case AnyAtomicType::QNAME: return ((const ATQNameOrDerived *)a.get())->compare((const ATQNameOrDerived *)b.get(), context_) < 0; case AnyAtomicType::TIME: return ((const ATTimeOrDerived *)a.get())->compare((const ATTimeOrDerived *)b.get(), context_) < 0; default: break; } assert(false); return false; }
/*static*/ bool Equals::equals(const AnyAtomicType::Ptr &atom1, const AnyAtomicType::Ptr &atom2, Collation* collation, DynamicContext* context, const LocationInfo *info) { try { // take care of the special case first if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::STRING) { if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::STRING && atom2->getPrimitiveTypeIndex() != AnyAtomicType::ANY_URI) { XQThrow3(XPath2ErrorException,X("Equals::equals"), X("An attempt to compare a string type to a non string type has occurred [err:XPTY0004]"), info); } // if the function returns 0, then they are equal return (collation->compare(atom1->asString(context),atom2->asString(context))==0); } return atom1->equals(atom2, context); } catch(XQException &e) { if(e.getXQueryLine() == 0) e.setXQueryPosition(info); throw; } }
/* returns true if the two objects' URI are equal (string comparison) * false otherwise */ bool ATUntypedAtomicImpl::equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const { if(this->getPrimitiveTypeIndex() != target->getPrimitiveTypeIndex()) { XQThrow2(IllegalArgumentException,X("ATUntypedAtomicImpl::equals"), X("Equality operator for given types not supported [err:XPTY0004]")); } return XPath2Utils::equals(target->asString(context), _value); }
/*static*/ bool GreaterThan::greater_than(const AnyAtomicType::Ptr &atom1, const AnyAtomicType::Ptr &atom2, Collation* collation, DynamicContext* context, const LocationInfo *info) { try { // take care of Numeric types first if(atom1->isNumericValue()) { if(atom2->isNumericValue()) { return ((Numeric*)(const AnyAtomicType*)atom1)->greaterThan((const Numeric::Ptr )atom2, context); } else { XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a numeric type to a non numeric type has occurred [err:XPTY0004]")); } } switch(atom1->getPrimitiveTypeIndex()) { case AnyAtomicType::BOOLEAN: { // op:boolean-greater-than(A, B) if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::BOOLEAN) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a boolean type to a non boolean type has occurred [err:XPTY0004]")); return ((const ATBooleanOrDerived*)atom1.get())->compare((const ATBooleanOrDerived*)atom2.get(), context) > 0; } case AnyAtomicType::STRING: case AnyAtomicType::ANY_URI: { // use function compare if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::STRING && atom2->getPrimitiveTypeIndex() != AnyAtomicType::ANY_URI) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a string type to a non string type has occurred [err:XPTY0004]")); // if the function returns 1, then atom1 is greater return collation->compare(atom1->asString(context),atom2->asString(context))>0; } case AnyAtomicType::DATE: { // op:date-greater-than(A, B) if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::DATE) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a date type to a non date type has occurred [err:XPTY0004]")); return ((ATDateOrDerived*)atom1.get())->compare((const ATDateOrDerived::Ptr )atom2, context) > 0; } case AnyAtomicType::TIME: { // op:time-greater-than(A, B) if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::TIME) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a time type to a non time type has occurred [err:XPTY0004]")); return ((ATTimeOrDerived*)atom1.get())->compare((const ATTimeOrDerived::Ptr )atom2, context) > 0; } case AnyAtomicType::DATE_TIME: { // op:datetime-greater-than(A, B) if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::DATE_TIME) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a dateTime type to a non dateTime type has occurred [err:XPTY0004]")); return ((ATDateTimeOrDerived*)atom1.get())->compare((const ATDateTimeOrDerived::Ptr)atom2, context) > 0; } case AnyAtomicType::DAY_TIME_DURATION: { if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::DAY_TIME_DURATION) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a duration type to a non duration type has occurred [err:XPTY0004]")); return ((const ATDurationOrDerived*)atom1.get())->compare((const ATDurationOrDerived*)atom2.get(), context) > 0; } case AnyAtomicType::YEAR_MONTH_DURATION: { if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::YEAR_MONTH_DURATION) XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("An attempt to compare a duration type to a non duration type has occurred [err:XPTY0004]")); return ((const ATDurationOrDerived*)atom1.get())->compare((const ATDurationOrDerived*)atom2.get(), context) > 0; } default: XQThrow2(XPath2ErrorException,X("GreaterThan::greater_than"), X("Unexpected data type in operator 'gt' [err:XPTY0004]")); } XQThrow2(FunctionException,X("GreaterThan::greater_than"), X("An equality operator is not defined for the provided arguments [err:XPTY0004]")); } catch(XQException &e) { if(e.getXQueryLine() == 0) e.setXQueryPosition(info); throw; } }
Result XQNameExpression::createResult(DynamicContext* context, int flags) const { AnyAtomicType::Ptr itemName = getExpression()->createResult(context)->next(context); switch(itemName->getPrimitiveTypeIndex()) { case AnyAtomicType::QNAME: return (Item::Ptr)itemName; case AnyAtomicType::STRING: case AnyAtomicType::UNTYPED_ATOMIC: try { return (Item::Ptr)context->getItemFactory()->createDerivedFromAtomicType(AnyAtomicType::QNAME, itemName->asString(context), context); } catch(XQException &) { XQThrow(ASTException,X("XQNameExpression::NameExpressionResult::createResult"), X("The name expression cannot be converted to a xs:QName [err:XQDY0074]")); } default: break; } XMLBuffer buf; buf.set(X("The name expression must be a single xs:QName, xs:string or xs:untypedAtomic")); buf.append(X(" - found item of type ")); itemName->typeToBuffer(context, buf); buf.append(X(" [err:XPTY0004]")); XQThrow(XPath2TypeMatchException, X("XQNameExpression::NameExpressionResult::createResult"), buf.getRawBuffer()); }