author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
// |
|
43 |
// W A R N I N G |
|
44 |
// ------------- |
|
45 |
// |
|
46 |
// This file is not part of the Qt API. It exists purely as an |
|
47 |
// implementation detail. This header file may change from version to |
|
48 |
// version without notice, or even be removed. |
|
49 |
// |
|
50 |
// We mean it. |
|
51 |
||
52 |
#ifndef Patternist_AtomicComparators_H |
|
53 |
#define Patternist_AtomicComparators_H |
|
54 |
||
55 |
#include "qabstractfloat_p.h" |
|
56 |
#include "qatomiccomparator_p.h" |
|
57 |
#include "qprimitives_p.h" |
|
58 |
||
59 |
/** |
|
60 |
* @file |
|
61 |
* @short Contains all the classes implementing comparisons between atomic values. |
|
62 |
*/ |
|
63 |
||
64 |
QT_BEGIN_HEADER |
|
65 |
||
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
namespace QPatternist |
|
69 |
{ |
|
70 |
/** |
|
71 |
* @short Performs case @em sensitive string comparison |
|
72 |
* between @c xs:anyUri, @c xs:string, and @c xs:untypedAtomic. |
|
73 |
* |
|
74 |
* @ingroup Patternist_xdm |
|
75 |
* @author Frans Englich <frans.englich@nokia.com> |
|
76 |
*/ |
|
77 |
class StringComparator : public AtomicComparator |
|
78 |
{ |
|
79 |
public: |
|
80 |
/** |
|
81 |
* Compares two strings, and returns the appropriate AtomicComparator::ComparisonResult enum. This |
|
82 |
* is a bit simplified version of string comparison as defined in the XPath specifications, |
|
83 |
* since this does not take any string collations into account(which an implementation neither |
|
84 |
* is required to do). |
|
85 |
* |
|
86 |
* @see <a href="http://www.w3.org/TR/xpath-functions/#string-compare">XQuery 1.0 and XPath |
|
87 |
* 2.0 Functions and Operators, 7.3 ValueComparison::Equality and Comparison of Strings</a> |
|
88 |
*/ |
|
89 |
virtual ComparisonResult compare(const Item &op1, |
|
90 |
const AtomicComparator::Operator op, |
|
91 |
const Item &op2) const; |
|
92 |
||
93 |
/** |
|
94 |
* Compares two strings, and returns @c true if they are considered equal as per |
|
95 |
* an ordinary string comparison. In other words, this is an implementation with |
|
96 |
* the Unicode code point collation. |
|
97 |
* |
|
98 |
* @see <a href="http://www.w3.org/TR/xpath-functions/#string-compare">XQuery 1.0 and XPath |
|
99 |
* 2.0 Functions and Operators, 7.3 ValueComparison::Equality and Comparison of Strings</a> |
|
100 |
*/ |
|
101 |
virtual bool equals(const Item &op1, |
|
102 |
const Item &op2) const; |
|
103 |
}; |
|
104 |
||
105 |
/** |
|
106 |
* @short Performs case @em insensitive string comparison |
|
107 |
* between @c xs:anyUri, @c xs:string, and @c xs:untypedAtomic. |
|
108 |
* |
|
109 |
* @ingroup Patternist_xdm |
|
110 |
* @author Frans Englich <frans.englich@nokia.com> |
|
111 |
*/ |
|
112 |
class CaseInsensitiveStringComparator : public AtomicComparator |
|
113 |
{ |
|
114 |
public: |
|
115 |
/** |
|
116 |
* Converts both string values to upper case and afterwards compare them. |
|
117 |
*/ |
|
118 |
virtual ComparisonResult compare(const Item &op1, |
|
119 |
const AtomicComparator::Operator op, |
|
120 |
const Item &op2) const; |
|
121 |
||
122 |
/** |
|
123 |
* Converts both string values case insensitively. |
|
124 |
*/ |
|
125 |
virtual bool equals(const Item &op1, |
|
126 |
const Item &op2) const; |
|
127 |
}; |
|
128 |
||
129 |
/** |
|
130 |
* @short Compares @c xs:base64Binary and @c xs:hexBinary values. |
|
131 |
* |
|
132 |
* @author Frans Englich <frans.englich@nokia.com> |
|
133 |
*/ |
|
134 |
class BinaryDataComparator : public AtomicComparator |
|
135 |
{ |
|
136 |
public: |
|
137 |
virtual bool equals(const Item &op1, |
|
138 |
const Item &op2) const; |
|
139 |
}; |
|
140 |
||
141 |
/** |
|
142 |
* @short Compares @c xs:boolean values. |
|
143 |
* |
|
144 |
* This is done via the object's Boolean::evaluteEBV() function. |
|
145 |
* |
|
146 |
* @author Frans Englich <frans.englich@nokia.com> |
|
147 |
*/ |
|
148 |
class BooleanComparator : public AtomicComparator |
|
149 |
{ |
|
150 |
public: |
|
151 |
virtual ComparisonResult compare(const Item &op1, |
|
152 |
const AtomicComparator::Operator op, |
|
153 |
const Item &op2) const; |
|
154 |
||
155 |
virtual bool equals(const Item &op1, |
|
156 |
const Item &op2) const; |
|
157 |
}; |
|
158 |
||
159 |
/** |
|
160 |
* @short Compares @c xs:double values. |
|
161 |
* |
|
162 |
* @todo Add docs about numeric promotion |
|
163 |
* |
|
164 |
* @author Frans Englich <frans.englich@nokia.com> |
|
165 |
*/ |
|
166 |
class AbstractFloatComparator : public AtomicComparator |
|
167 |
{ |
|
168 |
public: |
|
169 |
virtual ComparisonResult compare(const Item &op1, |
|
170 |
const AtomicComparator::Operator op, |
|
171 |
const Item &op2) const; |
|
172 |
||
173 |
virtual bool equals(const Item &op1, |
|
174 |
const Item &op2) const; |
|
175 |
}; |
|
176 |
||
177 |
/** |
|
178 |
* @short Compares @c xs:double values for the purpose of sorting. |
|
179 |
* |
|
180 |
* @todo Add docs about numeric promotion |
|
181 |
* |
|
182 |
* @author Frans Englich <frans.englich@nokia.com> |
|
183 |
*/ |
|
184 |
template<const AtomicComparator::Operator t_op> |
|
185 |
class AbstractFloatSortComparator : public AbstractFloatComparator |
|
186 |
{ |
|
187 |
public: |
|
188 |
virtual ComparisonResult compare(const Item &o1, |
|
189 |
const AtomicComparator::Operator op, |
|
190 |
const Item &o2) const |
|
191 |
{ |
|
192 |
Q_ASSERT_X(t_op == OperatorLessThanNaNLeast || t_op == OperatorLessThanNaNGreatest, Q_FUNC_INFO, |
|
193 |
"Can only be instantiated with those two."); |
|
194 |
Q_ASSERT(op == t_op); |
|
195 |
Q_UNUSED(op); /* Needed when building in release mode. */ |
|
196 |
||
197 |
const xsDouble v1 = o1.template as<Numeric>()->toDouble(); |
|
198 |
const xsDouble v2 = o2.template as<Numeric>()->toDouble(); |
|
199 |
||
200 |
if(qIsNaN(v1) && !qIsNaN(v2)) |
|
201 |
return t_op == OperatorLessThanNaNLeast ? LessThan : GreaterThan; |
|
202 |
if(!qIsNaN(v1) && qIsNaN(v2)) |
|
203 |
return t_op == OperatorLessThanNaNLeast ? GreaterThan : LessThan; |
|
204 |
||
205 |
if(Double::isEqual(v1, v2)) |
|
206 |
return Equal; |
|
207 |
else if(v1 < v2) |
|
208 |
return LessThan; |
|
209 |
else |
|
210 |
return GreaterThan; |
|
211 |
} |
|
212 |
||
213 |
}; |
|
214 |
||
215 |
/** |
|
216 |
* @short Compares @c xs:decimal values. |
|
217 |
* |
|
218 |
* @author Frans Englich <frans.englich@nokia.com> |
|
219 |
*/ |
|
220 |
class DecimalComparator : public AtomicComparator |
|
221 |
{ |
|
222 |
public: |
|
223 |
virtual ComparisonResult compare(const Item &op1, |
|
224 |
const AtomicComparator::Operator op, |
|
225 |
const Item &op2) const; |
|
226 |
||
227 |
virtual bool equals(const Item &op1, |
|
228 |
const Item &op2) const; |
|
229 |
}; |
|
230 |
||
231 |
/** |
|
232 |
* @short Compares @c xs:integer values. |
|
233 |
* |
|
234 |
* @author Frans Englich <frans.englich@nokia.com> |
|
235 |
*/ |
|
236 |
class IntegerComparator : public AtomicComparator |
|
237 |
{ |
|
238 |
public: |
|
239 |
virtual ComparisonResult compare(const Item &op1, |
|
240 |
const AtomicComparator::Operator op, |
|
241 |
const Item &op2) const; |
|
242 |
||
243 |
virtual bool equals(const Item &op1, |
|
244 |
const Item &op2) const; |
|
245 |
}; |
|
246 |
||
247 |
/** |
|
248 |
* @short Compares @c xs:QName values. |
|
249 |
* |
|
250 |
* @author Frans Englich <frans.englich@nokia.com> |
|
251 |
*/ |
|
252 |
class QNameComparator : public AtomicComparator |
|
253 |
{ |
|
254 |
public: |
|
255 |
virtual bool equals(const Item &op1, |
|
256 |
const Item &op2) const; |
|
257 |
}; |
|
258 |
||
259 |
/** |
|
260 |
* @short Compares sub-classes of AbstractDateTime. |
|
261 |
* |
|
262 |
* @author Frans Englich <frans.englich@nokia.com> |
|
263 |
*/ |
|
264 |
class AbstractDateTimeComparator : public AtomicComparator |
|
265 |
{ |
|
266 |
public: |
|
267 |
virtual ComparisonResult compare(const Item &op1, |
|
268 |
const AtomicComparator::Operator op, |
|
269 |
const Item &op2) const; |
|
270 |
virtual bool equals(const Item &op1, |
|
271 |
const Item &op2) const; |
|
272 |
}; |
|
273 |
||
274 |
/** |
|
275 |
* @short Compares sub-classes of AbstractDuration. |
|
276 |
* |
|
277 |
* @author Frans Englich <frans.englich@nokia.com> |
|
278 |
*/ |
|
279 |
class AbstractDurationComparator : public AtomicComparator |
|
280 |
{ |
|
281 |
public: |
|
282 |
virtual ComparisonResult compare(const Item &op1, |
|
283 |
const AtomicComparator::Operator op, |
|
284 |
const Item &op2) const; |
|
285 |
virtual bool equals(const Item &op1, |
|
286 |
const Item &op2) const; |
|
287 |
||
288 |
private: |
|
289 |
static inline QDateTime addDurationToDateTime(const QDateTime &dateTime, |
|
290 |
const AbstractDuration *const duration); |
|
291 |
}; |
|
292 |
} |
|
293 |
||
294 |
QT_END_NAMESPACE |
|
295 |
||
296 |
QT_END_HEADER |
|
297 |
||
298 |
#endif |