| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qatomiccomparators_p.h" |
| 41 | |
| 42 | #include "qatomiccomparatorlocators_p.h" |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE |
| 45 | |
| 46 | using namespace QPatternist; |
| 47 | |
| 48 | static const AtomicComparator::Operators AllCompOperators(AtomicComparator::OperatorNotEqual | |
| 49 | AtomicComparator::OperatorGreaterOrEqual | |
| 50 | AtomicComparator::OperatorLessOrEqual | |
| 51 | AtomicComparator::OperatorLessThanNaNLeast | |
| 52 | AtomicComparator::OperatorLessThanNaNGreatest); |
| 53 | /* --------------------------------------------------------------- */ |
| 54 | #define addVisitor(owner, type, comp, validOps) \ |
| 55 | AtomicTypeVisitorResult::Ptr \ |
| 56 | owner##ComparatorLocator::visit(const type *, \ |
| 57 | const qint16 opIn, \ |
| 58 | const SourceLocationReflection *const) const \ |
| 59 | { \ |
| 60 | /* Note the extra paranteses around validOps. */ \ |
| 61 | const AtomicComparator::Operator op = AtomicComparator::Operator(opIn); \ |
| 62 | if (((validOps) & op) == op) \ |
| 63 | return AtomicTypeVisitorResult::Ptr(new comp()); \ |
| 64 | else \ |
| 65 | return AtomicTypeVisitorResult::Ptr(); \ |
| 66 | } |
| 67 | /* --------------------------------------------------------------- */ |
| 68 | #define visitorForDouble(owner, type) \ |
| 69 | AtomicTypeVisitorResult::Ptr \ |
| 70 | owner##ComparatorLocator::visit(const type *, \ |
| 71 | const qint16 opIn, \ |
| 72 | const SourceLocationReflection *const) const \ |
| 73 | { \ |
| 74 | const AtomicComparator::Operator op = AtomicComparator::Operator(opIn); \ |
| 75 | if(((AtomicComparator::OperatorNotEqual | \ |
| 76 | AtomicComparator::OperatorGreaterOrEqual | \ |
| 77 | AtomicComparator::OperatorLessOrEqual) & 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>()); \ |
| 83 | else \ |
| 84 | return AtomicTypeVisitorResult::Ptr(); \ |
| 85 | } |
| 86 | /* --------------------------------------------------------------- */ |
| 87 | |
| 88 | /* ----------- xs:string, xs:anyURI, xs:untypedAtomic ----------- */ |
| 89 | addVisitor(String, StringType, StringComparator, |
| 90 | AllCompOperators) |
| 91 | addVisitor(String, UntypedAtomicType, StringComparator, |
| 92 | AllCompOperators) |
| 93 | addVisitor(String, AnyURIType, StringComparator, |
| 94 | AllCompOperators) |
| 95 | /* --------------------------------------------------------------- */ |
| 96 | |
| 97 | /* ------------------------- xs:hexBinary ------------------------ */ |
| 98 | addVisitor(HexBinary, HexBinaryType, BinaryDataComparator, |
| 99 | AtomicComparator::OperatorEqual | |
| 100 | AtomicComparator::OperatorNotEqual) |
| 101 | /* --------------------------------------------------------------- */ |
| 102 | |
| 103 | /* ----------------------- xs:base64Binary ----------------------- */ |
| 104 | addVisitor(Base64Binary, Base64BinaryType, BinaryDataComparator, |
| 105 | AtomicComparator::OperatorEqual | |
| 106 | AtomicComparator::OperatorNotEqual) |
| 107 | /* --------------------------------------------------------------- */ |
| 108 | |
| 109 | /* -------------------------- xs:boolean ------------------------- */ |
| 110 | addVisitor(Boolean, BooleanType, BooleanComparator, |
| 111 | AllCompOperators) |
| 112 | /* --------------------------------------------------------------- */ |
| 113 | |
| 114 | /* -------------------------- xs:double -------------------------- */ |
| 115 | visitorForDouble(Double, DoubleType) |
| 116 | visitorForDouble(Double, FloatType) |
| 117 | visitorForDouble(Double, DecimalType) |
| 118 | visitorForDouble(Double, IntegerType) |
| 119 | /* --------------------------------------------------------------- */ |
| 120 | |
| 121 | /* --------------------------- xs:float -------------------------- */ |
| 122 | visitorForDouble(Float, DoubleType) |
| 123 | visitorForDouble(Float, FloatType) |
| 124 | visitorForDouble(Float, DecimalType) |
| 125 | visitorForDouble(Float, IntegerType) |
| 126 | /* --------------------------------------------------------------- */ |
| 127 | |
| 128 | /* -------------------------- xs:decimal ------------------------- */ |
| 129 | visitorForDouble(Decimal, DoubleType) |
| 130 | visitorForDouble(Decimal, FloatType) |
| 131 | addVisitor(Decimal, DecimalType, DecimalComparator, |
| 132 | AllCompOperators) |
| 133 | addVisitor(Decimal, IntegerType, DecimalComparator, |
| 134 | AllCompOperators) |
| 135 | /* --------------------------------------------------------------- */ |
| 136 | |
| 137 | /* ------------------------- xs:integer -------------------------- */ |
| 138 | visitorForDouble(Integer, DoubleType) |
| 139 | visitorForDouble(Integer, FloatType) |
| 140 | addVisitor(Integer, DecimalType, DecimalComparator, |
| 141 | AllCompOperators) |
| 142 | addVisitor(Integer, IntegerType, IntegerComparator, |
| 143 | AllCompOperators) |
| 144 | /* --------------------------------------------------------------- */ |
| 145 | |
| 146 | /* -------------------------- xs:QName --------------------------- */ |
| 147 | addVisitor(QName, QNameType, QNameComparator, |
| 148 | AtomicComparator::OperatorEqual | |
| 149 | AtomicComparator::OperatorNotEqual) |
| 150 | /* --------------------------------------------------------------- */ |
| 151 | |
| 152 | /* -------------------------- xs:gYear --------------------------- */ |
| 153 | addVisitor(GYear, GYearType, AbstractDateTimeComparator, |
| 154 | AtomicComparator::OperatorEqual | |
| 155 | AtomicComparator::OperatorNotEqual) |
| 156 | /* --------------------------------------------------------------- */ |
| 157 | |
| 158 | /* -------------------------- xs:gDay ---------------------------- */ |
| 159 | addVisitor(GDay, GDayType, AbstractDateTimeComparator, |
| 160 | AtomicComparator::OperatorEqual | |
| 161 | AtomicComparator::OperatorNotEqual) |
| 162 | /* --------------------------------------------------------------- */ |
| 163 | |
| 164 | /* -------------------------- xs:gMonth -------------------------- */ |
| 165 | addVisitor(GMonth, GMonthType, AbstractDateTimeComparator, |
| 166 | AtomicComparator::OperatorEqual | |
| 167 | AtomicComparator::OperatorNotEqual) |
| 168 | /* --------------------------------------------------------------- */ |
| 169 | |
| 170 | /* ------------------------ xs:gYearMonth ------------------------ */ |
| 171 | addVisitor(GYearMonth, GYearMonthType, AbstractDateTimeComparator, |
| 172 | AtomicComparator::OperatorEqual | |
| 173 | AtomicComparator::OperatorNotEqual) |
| 174 | /* --------------------------------------------------------------- */ |
| 175 | |
| 176 | /* ------------------------ xs:gMonthDay ------------------------- */ |
| 177 | addVisitor(GMonthDay, GMonthDayType, AbstractDateTimeComparator, |
| 178 | AtomicComparator::OperatorEqual | |
| 179 | AtomicComparator::OperatorNotEqual) |
| 180 | /* --------------------------------------------------------------- */ |
| 181 | |
| 182 | /* ------------------------ xs:dateTime -------------------------- */ |
| 183 | addVisitor(DateTime, DateTimeType, AbstractDateTimeComparator, |
| 184 | AllCompOperators) |
| 185 | /* --------------------------------------------------------------- */ |
| 186 | |
| 187 | /* -------------------------- xs:time ---------------------------- */ |
| 188 | addVisitor(SchemaTime, SchemaTimeType, AbstractDateTimeComparator, |
| 189 | AllCompOperators) |
| 190 | /* --------------------------------------------------------------- */ |
| 191 | |
| 192 | /* -------------------------- xs:date ---------------------------- */ |
| 193 | addVisitor(Date, DateType, AbstractDateTimeComparator, |
| 194 | AllCompOperators) |
| 195 | /* --------------------------------------------------------------- */ |
| 196 | |
| 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 | /* --------------------------------------------------------------- */ |
| 208 | |
| 209 | /* ------------------ xs:dayTimeDuration ------------------------ */ |
| 210 | addVisitor(DayTimeDuration, DayTimeDurationType, AbstractDurationComparator, |
| 211 | AllCompOperators) |
| 212 | addVisitor(DayTimeDuration, DurationType, AbstractDurationComparator, |
| 213 | AtomicComparator::OperatorEqual | |
| 214 | AtomicComparator::OperatorNotEqual) |
| 215 | addVisitor(DayTimeDuration, YearMonthDurationType, AbstractDurationComparator, |
| 216 | AtomicComparator::OperatorEqual | |
| 217 | AtomicComparator::OperatorNotEqual) |
| 218 | /* --------------------------------------------------------------- */ |
| 219 | |
| 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, |
| 228 | AllCompOperators) |
| 229 | /* --------------------------------------------------------------- */ |
| 230 | #undef addVisitor |
| 231 | |
| 232 | QT_END_NAMESPACE |
| 233 | |