1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 * @short This file is included by qcomparisonplatform_p.h.
45 * If you need includes in this file, put them in qcomparisonplatform_p.h, outside of the namespace.
48 template <typename TSubClass, bool issueError,
49 AtomicComparator::ComparisonType comparisonType, ReportContext::ErrorCode errorCode>
50 bool ComparisonPlatform<TSubClass, issueError, comparisonType, errorCode>::
51 flexibleCompare(const Item &it1,
53 const DynamicContext::Ptr &context) const
56 /* The comparator was located at compile time. */
57 return compare(it1, it2, m_comparator, operatorID());
60 const AtomicComparator::Ptr cp(fetchComparator(it1.type(),
64 return cp ? compare(it1, it2, cp, operatorID()) : false;
68 template <typename TSubClass, bool issueError,
69 AtomicComparator::ComparisonType comparisonType, ReportContext::ErrorCode errorCode>
70 AtomicComparator::ComparisonResult
71 ComparisonPlatform<TSubClass, issueError, comparisonType, errorCode>::
72 detailedFlexibleCompare(const Item &it1,
74 const DynamicContext::Ptr &context) const
76 AtomicComparator::Ptr comp;
82 comp = fetchComparator(it1.type(),
87 Q_ASSERT_X(operatorID() == AtomicComparator::OperatorLessThanNaNLeast || operatorID() == AtomicComparator::OperatorLessThanNaNGreatest,
88 Q_FUNC_INFO, "Only OperatorLessThan is currently supported for this function.");
89 return comp->compare(it1, operatorID(), it2);
92 template <typename TSubClass, bool issueError,
93 AtomicComparator::ComparisonType comparisonType, ReportContext::ErrorCode errorCode>
94 bool ComparisonPlatform<TSubClass, issueError, comparisonType, errorCode>::
95 compare(const Item &oand1,
97 const AtomicComparator::Ptr &comp,
98 const AtomicComparator::Operator op) const
106 case AtomicComparator::OperatorEqual:
107 return comp->equals(oand1, oand2);
108 case AtomicComparator::OperatorNotEqual:
109 return !comp->equals(oand1, oand2);
110 case AtomicComparator::OperatorLessThanNaNLeast:
111 case AtomicComparator::OperatorLessThanNaNGreatest:
113 case AtomicComparator::OperatorLessThan:
114 return comp->compare(oand1, op, oand2) == AtomicComparator::LessThan;
115 case AtomicComparator::OperatorGreaterThan:
116 return comp->compare(oand1, op, oand2) == AtomicComparator::GreaterThan;
117 case AtomicComparator::OperatorLessOrEqual:
119 const AtomicComparator::ComparisonResult ret = comp->compare(oand1, op, oand2);
120 return ret == AtomicComparator::LessThan || ret == AtomicComparator::Equal;
122 case(AtomicComparator::OperatorGreaterOrEqual):
124 const AtomicComparator::ComparisonResult ret = comp->compare(oand1, op, oand2);
125 return ret == AtomicComparator::GreaterThan || ret == AtomicComparator::Equal;
129 /* GCC unbarfer, this line should never be reached. */
134 template <typename TSubClass, bool issueError,
135 AtomicComparator::ComparisonType comparisonType, ReportContext::ErrorCode errorCode>
136 AtomicComparator::Ptr ComparisonPlatform<TSubClass, issueError, comparisonType, errorCode>::
137 fetchComparator(const ItemType::Ptr &t1,
138 const ItemType::Ptr &t2,
139 const ReportContext::Ptr &context) const
144 if(*BuiltinTypes::xsAnyAtomicType == *t1 ||
145 *BuiltinTypes::xsAnyAtomicType == *t2 ||
146 *BuiltinTypes::item == *t1 ||
147 *BuiltinTypes::item == *t2 ||
148 *BuiltinTypes::numeric == *t1 ||
149 *BuiltinTypes::numeric == *t2 ||
150 *CommonSequenceTypes::Empty == *t1 ||
151 *CommonSequenceTypes::Empty == *t2)
153 /* The static type of(at least) one of the operands could not
154 * be narrowed further, so we do the operator
157 return AtomicComparator::Ptr();
160 const AtomicComparatorLocator::Ptr locator
161 (static_cast<const AtomicType *>(t1.data())->comparatorLocator());
167 context->error(QtXmlPatterns::tr("No comparisons can be done involving the type %1.")
168 .arg(formatType(context->namePool(), t1)),
169 errorCode, static_cast<const TSubClass *>(this)->actualReflection());
171 return AtomicComparator::Ptr();
174 const AtomicComparator::Ptr comp(static_cast<const AtomicType *>(t2.data())->accept(locator, operatorID(),
175 static_cast<const TSubClass *>(this)->actualReflection()));
181 context->error(QtXmlPatterns::tr("Operator %1 is not available between atomic values of type %2 and %3.")
182 .arg(formatKeyword(AtomicComparator::displayName(operatorID(),
184 formatType(context->namePool(), t1),
185 formatType(context->namePool(), t2)),
186 errorCode, static_cast<const TSubClass *>(this)->actualReflection());
189 return AtomicComparator::Ptr();
192 template <typename TSubClass, bool issueError,
193 AtomicComparator::ComparisonType comparisonType, ReportContext::ErrorCode errorCode>
194 void ComparisonPlatform<TSubClass, issueError, comparisonType, errorCode>::
195 prepareComparison(const AtomicComparator::Ptr &c)