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()); }
EventGenerator::Ptr XQAttributeConstructor::generateEvents(EventHandler *events, DynamicContext *context, bool preserveNS, bool preserveType) const { AnyAtomicType::Ptr itemName = m_name->createResult(context)->next(context); const ATQNameOrDerived* pQName = (const ATQNameOrDerived*)itemName.get(); const XMLCh *prefix = pQName->getPrefix(); const XMLCh *uri = pQName->getURI(); const XMLCh *name = pQName->getName(); if((uri==NULL && XPath2Utils::equals(name, XMLUni::fgXMLNSString)) || XPath2Utils::equals(uri, XMLUni::fgXMLNSURIName)) XQThrow(ASTException,X("DOM Constructor"),X("A computed attribute constructor cannot create a namespace declaration [err:XQDY0044]")); XMLBuffer value; getStringValue(m_children, value, context); const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; const XMLCh *typeName = ATUntypedAtomic::fgDT_UNTYPEDATOMIC; // check if it's xml:id static const XMLCh id[] = { 'i', 'd', 0 }; if(XPath2Utils::equals(name, id) && XPath2Utils::equals(uri, XMLUni::fgXMLURIName)) { // If the attribute name is xml:id, the string value and typed value of the attribute are further normalized by // discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters // by a single space (#x20) character. XMLString::collapseWS(value.getRawBuffer(), context->getMemoryManager()); typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; typeName = XMLUni::fgIDString; } events->attributeEvent(emptyToNull(prefix), emptyToNull(uri), name, value.getRawBuffer(), typeURI, typeName); return 0; }
Item::Ptr DistinctValueResult::next(DynamicContext *context) { if(toDo_) { toDo_ = false; parent_ = fdv_->getParamNumber(1, context); Collation *collation; if(fdv_->getNumArgs() > 1) { const XMLCh* collName = fdv_->getParamNumber(2, context)->next(context)->asString(context); try { context->getItemFactory()->createAnyURI(collName, context); } catch(XPath2ErrorException &e) { XQThrow(FunctionException, X("FunctionDistinctValues::DistinctValueResult::next"), X("Invalid collationURI")); } collation = context->getCollation(collName, this); } else collation = context->getDefaultCollation(this); alreadySeen_ = new DistinctSet(dvCompare(collation, context)); } AnyAtomicType::Ptr item; while(true) { item = (const AnyAtomicType *)parent_->next(context).get(); if(item.isNull()) break; if(alreadySeen_->insert(item).second) return item; } parent_ = 0; return 0; }
/* returns true if the two objects * false otherwise */ bool ATGYearOrDerivedImpl::equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const { if(this->getPrimitiveTypeIndex() != target->getPrimitiveTypeIndex()) { XQThrow2(::IllegalArgumentException,X("ATGYearOrDerivedImpl::equals"), X("Equality operator for given types not supported [err:XPTY0004]")); } return compare((const ATGYearOrDerived *)target.get(), context) == 0; }
EventGenerator::Ptr XQCopy::generateEventsImpl(const Item::Ptr &toBeCopied, EventHandler *events, DynamicContext *context, bool preserveNS, bool preserveType) const { if(!toBeCopied->isNode()) { toBeCopied->generateEvents(events, context, preserveNS, preserveType); return 0; } Node *node = (Node*)toBeCopied.get(); if(node->dmNodeKind() == Node::element_string) { NoInheritFilter niFilter(events, context->getMemoryManager()); if(!inheritNamespaces_) events = &niFilter; AnyAtomicType::Ptr itemName = node->dmNodeName(context); const ATQNameOrDerived *pQName = (const ATQNameOrDerived*)itemName.get(); const XMLCh *prefix = emptyToNull(pQName->getPrefix()); const XMLCh *uri = emptyToNull(pQName->getURI()); const XMLCh *localname = pQName->getName(); events->startElementEvent(prefix, uri, localname); ElemConstructFilter elemFilter(events, this, context->getMemoryManager()); if(copyNamespaces_) { Result nsnodes = node->dmNamespaceNodes(context, this); Item::Ptr ns; while((ns = nsnodes->next(context)).notNull()) { ns->generateEvents(&elemFilter, context, preserveNS, preserveType); } } for(VectorOfASTNodes::const_iterator itCont = children_.begin(); itCont != children_.end (); ++itCont) { (*itCont)->generateAndTailCall(&elemFilter, context, preserveNS, preserveType); } // TBD validation and type - jpcs const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; const XMLCh *typeName = DocumentCache::g_szUntyped; events->endElementEvent(prefix, uri, localname, typeURI, typeName); } else if(node->dmNodeKind() == Node::document_string) { events->startDocumentEvent(0, 0); DocConstructFilter filter(events, this); for(VectorOfASTNodes::const_iterator itCont = children_.begin(); itCont != children_.end (); ++itCont) { (*itCont)->generateAndTailCall(&filter, context, preserveNS, preserveType); } events->endDocumentEvent(); } else { node->generateEvents(events, context, preserveNS, preserveType); } return 0; }
ASTNode* XQCastAs::staticResolution(StaticContext *context) { XPath2MemoryManager *mm = context->getMemoryManager(); _exprType->staticResolution(context); const SequenceType::ItemType *itemType = _exprType->getItemType(); if(itemType != NULL) { if((XPath2Utils::equals(itemType->getTypeURI(), XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgURI_SCHEMAFORSCHEMA) && XPath2Utils::equals(itemType->getType()->getName(), szNOTATION)) || (XPath2Utils::equals(itemType->getTypeURI(), FunctionConstructor::XMLChXPath2DatatypesURI) && XPath2Utils::equals(itemType->getType()->getName(), AnyAtomicType::fgDT_ANYATOMICTYPE))) XQThrow(TypeErrorException,X("XQCastAs::CastAsResult::getSingleResult"), X("The target type of a cast expression must be an atomic type that is in the in-scope schema types and is not xs:NOTATION or xdt:anyAtomicType [err:XPST0080]")); } if(_exprType->getItemTestType() != SequenceType::ItemType::TEST_ATOMIC_TYPE) XQThrow(TypeErrorException,X("XQCastAs::staticResolution"),X("Cannot cast to a non atomic type")); _typeIndex = context->getItemFactory()-> getPrimitiveTypeIndex(_exprType->getTypeURI(), _exprType->getConstrainingType()->getName(), _isPrimitive); // If this is a cast to xs:QName or xs:NOTATION and the argument is a string literal // evaluate immediately, since they aren't allowed otherwise if((_typeIndex == AnyAtomicType::QNAME || _typeIndex == AnyAtomicType::NOTATION) && _expr->getType() == LITERAL && ((XQLiteral*)_expr)->getPrimitiveType() == AnyAtomicType::STRING) { AutoDelete<DynamicContext> dContext(context->createDynamicContext()); dContext->setMemoryManager(mm); AnyAtomicType::Ptr item = (AnyAtomicType*)_expr->createResult(dContext)->next(dContext).get(); try { if(_isPrimitive) { item = item->castAsNoCheck(_typeIndex, 0, 0, dContext); } else { item = item->castAsNoCheck(_typeIndex, _exprType->getTypeURI(), _exprType->getConstrainingType()->getName(), dContext); } } catch(XQException &e) { if(e.getXQueryLine() == 0) e.setXQueryPosition(this); throw; } return XQLiteral::create(item, dContext, mm, this)->staticResolution(context); } _expr = new (mm) XQAtomize(_expr, mm); _expr->setLocationInfo(this); _expr = _expr->staticResolution(context); return this; }
Item::Ptr Divide::execute(const AnyAtomicType::Ptr &atom1, const AnyAtomicType::Ptr &atom2, DynamicContext *context) const { if(atom1 == NULLRCP || atom2 == NULLRCP) return 0; if(atom1->isNumericValue()) { if(atom2->isNumericValue()) { return (const Item::Ptr)((Numeric*)(const AnyAtomicType*)atom1)->divide((const Numeric::Ptr )atom2, context); } else { XQThrow(XPath2ErrorException,X("Divide::createSequence"), X("An attempt to divide a numeric type by a non-numeric type has occurred [err:XPTY0004]")); } } if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::DAY_TIME_DURATION || atom1->getPrimitiveTypeIndex() == AnyAtomicType::YEAR_MONTH_DURATION) { const ATDurationOrDerived* duration = (const ATDurationOrDerived*)atom1.get(); if(atom2->isNumericValue()) { return (const Item::Ptr)duration->divide((const Numeric *)atom2.get(), context); } else if(atom2->getPrimitiveTypeIndex() == AnyAtomicType::DAY_TIME_DURATION || atom2->getPrimitiveTypeIndex() == AnyAtomicType::YEAR_MONTH_DURATION) { return (const Item::Ptr)duration->divide((const ATDurationOrDerived*)atom2.get(), context); } else { XQThrow(XPath2ErrorException,X("Divide::createSequence"), X("An attempt to divide an xs:duration by an invalid type has occured [err:XPTY0004]")); } } else { XQThrow(XPath2ErrorException,X("Divide::createSequence"), X("The operator div has been called on invalid operand types [err:XPTY0004]")); } return 0; }
static inline AnyAtomicType::AtomicObjectType getSortType(const AnyAtomicType::Ptr &a) { switch(a->getPrimitiveTypeIndex()) { case AnyAtomicType::ANY_URI: case AnyAtomicType::UNTYPED_ATOMIC: case AnyAtomicType::STRING: return AnyAtomicType::STRING; case AnyAtomicType::DECIMAL: case AnyAtomicType::FLOAT: case AnyAtomicType::DOUBLE: return AnyAtomicType::DOUBLE; case AnyAtomicType::DAY_TIME_DURATION: case AnyAtomicType::YEAR_MONTH_DURATION: case AnyAtomicType::DURATION: return AnyAtomicType::DURATION; case AnyAtomicType::BASE_64_BINARY: return AnyAtomicType::BASE_64_BINARY; case AnyAtomicType::BOOLEAN: return AnyAtomicType::BOOLEAN; case AnyAtomicType::DATE: return AnyAtomicType::DATE; case AnyAtomicType::DATE_TIME: return AnyAtomicType::DATE_TIME; case AnyAtomicType::G_DAY: return AnyAtomicType::G_DAY; case AnyAtomicType::G_MONTH: return AnyAtomicType::G_MONTH; case AnyAtomicType::G_MONTH_DAY: return AnyAtomicType::G_MONTH_DAY; case AnyAtomicType::G_YEAR: return AnyAtomicType::G_YEAR; case AnyAtomicType::G_YEAR_MONTH: return AnyAtomicType::G_YEAR_MONTH; case AnyAtomicType::HEX_BINARY: return AnyAtomicType::HEX_BINARY; case AnyAtomicType::NOTATION: return AnyAtomicType::NOTATION; case AnyAtomicType::QNAME: return AnyAtomicType::QNAME; case AnyAtomicType::TIME: return AnyAtomicType::TIME; default: break; } assert(false); // Not supported return AnyAtomicType::STRING; }
AnyAtomicType::Ptr XQCastAs::cast(const AnyAtomicType::Ptr &in, DynamicContext *context) const { try { if(_isPrimitive) { return in->castAs(_typeIndex, 0, 0, context); } else { return in->castAs(_typeIndex, _exprType->getTypeURI(), _exprType->getConstrainingType()->getName(), context); } } catch(XQException &e) { if(e.getXQueryLine() == 0) e.setXQueryPosition(this); throw; } }
/*static*/ bool GreaterThanEqual::greater_than_equal(const AnyAtomicType::Ptr &arg1, const AnyAtomicType::Ptr &arg2, Collation* collation, DynamicContext* context, const LocationInfo *info) { // A ge B numeric numeric op:numeric-greater-than(A, B) or op:numeric-equal(A, B) // A ge B xs:boolean xs:boolean fn:not(op:boolean-less-than(A, B)) // A ge B xs:string xs:string op:numeric-greater-than(fn:compare(A, B), -1) // A ge B xs:date xs:date fn:not(op:date-less-than(A, B)) // A ge B xs:time xs:time fn:not(op:time-less-than(A, B)) // A ge B xs:dateTime xs:dateTime fn:not(op:datetime-less-than(A, B)) // A ge B xdt:yearMonthDuration xdt:yearMonthDuration fn:not(op:yearMonthDuration-less-than(A, B)) // A ge B xdt:dayTimeDuration xdt:dayTimeDuration fn:not(op:dayTimeDuration-less-than(A, B)) // numeric values need a special comparison, for the others we can just rely on LessThan if(arg1->isNumericValue() && arg2->isNumericValue()) { if(((Numeric*)arg1.get())->getState() == Numeric::NaN || ((Numeric*)arg2.get())->getState() == Numeric::NaN) return false; } return !LessThan::less_than(arg1,arg2,collation,context, info); }
/*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; } }
/*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; } }
Item::Ptr Multiply::execute(const AnyAtomicType::Ptr &atom1, const AnyAtomicType::Ptr &atom2, DynamicContext *context) const { if(atom1.isNull() || atom2.isNull()) return 0; // xs:double * xs:duration (only xdt:dayTimeDuration and xdt:yearMonthDuration) if(atom1->isNumericValue() && (atom2->getPrimitiveTypeIndex() == AnyAtomicType::DAY_TIME_DURATION || atom2->getPrimitiveTypeIndex() == AnyAtomicType::YEAR_MONTH_DURATION)) { return ((const ATDurationOrDerived*)atom2.get())->multiply((const Numeric*)atom1.get(), context); } // xs:duration * xs:double (only xdt:dayTimeDuration and xdt:yearMonthDuration) if(atom2->isNumericValue() && (atom1->getPrimitiveTypeIndex() == AnyAtomicType::DAY_TIME_DURATION || atom1->getPrimitiveTypeIndex() == AnyAtomicType::YEAR_MONTH_DURATION)) { return ((const ATDurationOrDerived*)atom1.get())->multiply((const Numeric*)atom2.get(), context); } // numeric * numeric if(atom1->isNumericValue()) { if(atom2->isNumericValue()) { return ((const Numeric*)atom1.get())->multiply((const Numeric*)atom2.get(), context); } else { XQThrow(XPath2ErrorException,X("Multiply::createSequence"), X("An attempt to multiply a non numeric type to a numeric type has occurred [err:XPTY0004]")); } } XQThrow(XPath2ErrorException,X("Multiply::createSequence"), X("The operator * has been called on invalid operand types [err:XPTY0004]")); }
bool GeneralComp::compare(GeneralComp::ComparisonOperation operation, AnyAtomicType::Ptr first, AnyAtomicType::Ptr second, Collation* collation, DynamicContext *context, bool xpath1compat, const LocationInfo *info) { // The magnitude relationship between two atomic values is determined as follows: // 1) If either atomic value has the dynamic type xdt:untypedAtomic, that value is cast to a required type, // which is determined as follows: // - If the dynamic type of the other atomic value is a numeric type, the required type is xs:double. // - If the dynamic type of the other atomic value is xdt:untypedAtomic, the required type is xs:string. // - Otherwise, the required type is the dynamic type of the other atomic value. // If the cast to the required type fails, a dynamic error is raised. // 2) If XPath 1.0 compatibility mode is true, and at least one of the atomic values has a numeric type, // then both atomic values are cast to to the type xs:double. // 3) After any necessary casting, the atomic values are compared using one of the value comparison operators // eq, ne, lt, le, gt, or ge, depending on whether the general comparison operator was // =, !=, <, <=, >, or >=. The values have the required magnitude relationship if the result of this // value comparison is true. if(first->getPrimitiveTypeIndex() == AnyAtomicType::UNTYPED_ATOMIC) { if (second->isNumericValue()) { first = first->castAs(AnyAtomicType::DOUBLE, context); } else if(second->getPrimitiveTypeIndex() == AnyAtomicType::UNTYPED_ATOMIC) { first = first->castAs(AnyAtomicType::STRING, context); } else { first = first->castAs(second->getPrimitiveTypeIndex(), second->getTypeURI(), second->getTypeName(), context); } } if(second->getPrimitiveTypeIndex() == AnyAtomicType::UNTYPED_ATOMIC) { if(first->isNumericValue()) { second = second->castAs(AnyAtomicType::DOUBLE, context); } else if(first->getPrimitiveTypeIndex() == AnyAtomicType::UNTYPED_ATOMIC) { second = second->castAs(AnyAtomicType::STRING, context); } else { second = second->castAs(first->getPrimitiveTypeIndex(), first->getTypeURI(), first->getTypeName(), context); } } if(xpath1compat && (first->isNumericValue() || second->isNumericValue())) { first = first->castAs(AnyAtomicType::DOUBLE, context); second = second->castAs(AnyAtomicType::DOUBLE, context); } bool result = false; switch(operation) { case GeneralComp::EQUAL: result = Equals::equals(first,second,collation,context,info); break; case GeneralComp::NOT_EQUAL: result = NotEquals::not_equals(first,second,collation,context,info); break; case GeneralComp::LESS_THAN: result = LessThan::less_than(first,second,collation,context,info); break; case GeneralComp::LESS_THAN_EQUAL: result = LessThanEqual::less_than_equal(first,second,collation,context,info); break; case GeneralComp::GREATER_THAN: result = GreaterThan::greater_than(first,second,collation,context,info); break; case GeneralComp::GREATER_THAN_EQUAL: result = GreaterThanEqual::greater_than_equal(first,second,collation,context,info); break; default: assert(false); } return result; }
static inline bool isEmptyOrNaN(const AnyAtomicType::Ptr &si) { return si.isNull() || (si->isNumericValue() && ((Numeric*)si.get())->isNaN()); }
/* 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); }
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; }