1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qatomiccomparators_p.h"
44 #include "qatomiccomparatorlocators_p.h"
48 using namespace QPatternist;
50 static const AtomicComparator::Operators AllCompOperators(AtomicComparator::OperatorNotEqual |
51 AtomicComparator::OperatorGreaterOrEqual |
52 AtomicComparator::OperatorLessOrEqual |
53 AtomicComparator::OperatorLessThanNaNLeast |
54 AtomicComparator::OperatorLessThanNaNGreatest);
55 /* --------------------------------------------------------------- */
56 #define addVisitor(owner, type, comp, validOps) \
57 AtomicTypeVisitorResult::Ptr \
58 owner##ComparatorLocator::visit(const type *, \
60 const SourceLocationReflection *const) const \
62 /* Note the extra paranteses around validOps. */ \
63 if(((validOps) & AtomicComparator::Operator(op)) == op) \
64 return AtomicTypeVisitorResult::Ptr(new comp()); \
66 return AtomicTypeVisitorResult::Ptr(); \
68 /* --------------------------------------------------------------- */
69 #define visitorForDouble(owner, type) \
70 AtomicTypeVisitorResult::Ptr \
71 owner##ComparatorLocator::visit(const type *, \
73 const SourceLocationReflection *const) const \
75 if(((AtomicComparator::OperatorNotEqual | \
76 AtomicComparator::OperatorGreaterOrEqual | \
77 AtomicComparator::OperatorLessOrEqual) & AtomicComparator::Operator(op)) == op) \
78 return AtomicTypeVisitorResult::Ptr(new AbstractFloatComparator()); \
79 else if(op == AtomicComparator::OperatorLessThanNaNLeast) \
80 return AtomicTypeVisitorResult::Ptr(new AbstractFloatSortComparator<AtomicComparator::OperatorLessThanNaNLeast>()); \
81 else if(op == AtomicComparator::OperatorLessThanNaNGreatest) \
82 return AtomicTypeVisitorResult::Ptr(new AbstractFloatSortComparator<AtomicComparator::OperatorLessThanNaNGreatest>()); \
84 return AtomicTypeVisitorResult::Ptr(); \
86 /* --------------------------------------------------------------- */
88 /* ----------- xs:string, xs:anyURI, xs:untypedAtomic ----------- */
89 addVisitor(String, StringType, StringComparator,
91 addVisitor(String, UntypedAtomicType, StringComparator,
93 addVisitor(String, AnyURIType, StringComparator,
95 /* --------------------------------------------------------------- */
97 /* ------------------------- xs:hexBinary ------------------------ */
98 addVisitor(HexBinary, HexBinaryType, BinaryDataComparator,
99 AtomicComparator::OperatorEqual |
100 AtomicComparator::OperatorNotEqual)
101 /* --------------------------------------------------------------- */
103 /* ----------------------- xs:base64Binary ----------------------- */
104 addVisitor(Base64Binary, Base64BinaryType, BinaryDataComparator,
105 AtomicComparator::OperatorEqual |
106 AtomicComparator::OperatorNotEqual)
107 /* --------------------------------------------------------------- */
109 /* -------------------------- xs:boolean ------------------------- */
110 addVisitor(Boolean, BooleanType, BooleanComparator,
112 /* --------------------------------------------------------------- */
114 /* -------------------------- xs:double -------------------------- */
115 visitorForDouble(Double, DoubleType)
116 visitorForDouble(Double, FloatType)
117 visitorForDouble(Double, DecimalType)
118 visitorForDouble(Double, IntegerType)
119 /* --------------------------------------------------------------- */
121 /* --------------------------- xs:float -------------------------- */
122 visitorForDouble(Float, DoubleType)
123 visitorForDouble(Float, FloatType)
124 visitorForDouble(Float, DecimalType)
125 visitorForDouble(Float, IntegerType)
126 /* --------------------------------------------------------------- */
128 /* -------------------------- xs:decimal ------------------------- */
129 visitorForDouble(Decimal, DoubleType)
130 visitorForDouble(Decimal, FloatType)
131 addVisitor(Decimal, DecimalType, DecimalComparator,
133 addVisitor(Decimal, IntegerType, DecimalComparator,
135 /* --------------------------------------------------------------- */
137 /* ------------------------- xs:integer -------------------------- */
138 visitorForDouble(Integer, DoubleType)
139 visitorForDouble(Integer, FloatType)
140 addVisitor(Integer, DecimalType, DecimalComparator,
142 addVisitor(Integer, IntegerType, IntegerComparator,
144 /* --------------------------------------------------------------- */
146 /* -------------------------- xs:QName --------------------------- */
147 addVisitor(QName, QNameType, QNameComparator,
148 AtomicComparator::OperatorEqual |
149 AtomicComparator::OperatorNotEqual)
150 /* --------------------------------------------------------------- */
152 /* -------------------------- xs:gYear --------------------------- */
153 addVisitor(GYear, GYearType, AbstractDateTimeComparator,
154 AtomicComparator::OperatorEqual |
155 AtomicComparator::OperatorNotEqual)
156 /* --------------------------------------------------------------- */
158 /* -------------------------- xs:gDay ---------------------------- */
159 addVisitor(GDay, GDayType, AbstractDateTimeComparator,
160 AtomicComparator::OperatorEqual |
161 AtomicComparator::OperatorNotEqual)
162 /* --------------------------------------------------------------- */
164 /* -------------------------- xs:gMonth -------------------------- */
165 addVisitor(GMonth, GMonthType, AbstractDateTimeComparator,
166 AtomicComparator::OperatorEqual |
167 AtomicComparator::OperatorNotEqual)
168 /* --------------------------------------------------------------- */
170 /* ------------------------ xs:gYearMonth ------------------------ */
171 addVisitor(GYearMonth, GYearMonthType, AbstractDateTimeComparator,
172 AtomicComparator::OperatorEqual |
173 AtomicComparator::OperatorNotEqual)
174 /* --------------------------------------------------------------- */
176 /* ------------------------ xs:gMonthDay ------------------------- */
177 addVisitor(GMonthDay, GMonthDayType, AbstractDateTimeComparator,
178 AtomicComparator::OperatorEqual |
179 AtomicComparator::OperatorNotEqual)
180 /* --------------------------------------------------------------- */
182 /* ------------------------ xs:dateTime -------------------------- */
183 addVisitor(DateTime, DateTimeType, AbstractDateTimeComparator,
185 /* --------------------------------------------------------------- */
187 /* -------------------------- xs:time ---------------------------- */
188 addVisitor(SchemaTime, SchemaTimeType, AbstractDateTimeComparator,
190 /* --------------------------------------------------------------- */
192 /* -------------------------- xs:date ---------------------------- */
193 addVisitor(Date, DateType, AbstractDateTimeComparator,
195 /* --------------------------------------------------------------- */
197 /* ------------------------ xs:duration -------------------------- */
198 addVisitor(Duration, DayTimeDurationType, AbstractDurationComparator,
199 AtomicComparator::OperatorEqual |
200 AtomicComparator::OperatorNotEqual)
201 addVisitor(Duration, DurationType, AbstractDurationComparator,
202 AtomicComparator::OperatorEqual |
203 AtomicComparator::OperatorNotEqual)
204 addVisitor(Duration, YearMonthDurationType, AbstractDurationComparator,
205 AtomicComparator::OperatorEqual |
206 AtomicComparator::OperatorNotEqual)
207 /* --------------------------------------------------------------- */
209 /* ------------------ xs:dayTimeDuration ------------------------ */
210 addVisitor(DayTimeDuration, DayTimeDurationType, AbstractDurationComparator,
212 addVisitor(DayTimeDuration, DurationType, AbstractDurationComparator,
213 AtomicComparator::OperatorEqual |
214 AtomicComparator::OperatorNotEqual)
215 addVisitor(DayTimeDuration, YearMonthDurationType, AbstractDurationComparator,
216 AtomicComparator::OperatorEqual |
217 AtomicComparator::OperatorNotEqual)
218 /* --------------------------------------------------------------- */
220 /* ------------------- xs:yearMonthDuration --------------------- */
221 addVisitor(YearMonthDuration, DayTimeDurationType, AbstractDurationComparator,
222 AtomicComparator::OperatorEqual |
223 AtomicComparator::OperatorNotEqual)
224 addVisitor(YearMonthDuration, DurationType, AbstractDurationComparator,
225 AtomicComparator::OperatorEqual |
226 AtomicComparator::OperatorNotEqual)
227 addVisitor(YearMonthDuration, YearMonthDurationType, AbstractDurationComparator,
229 /* --------------------------------------------------------------- */