Qt 4.8
qatomiccasters.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qnumeric.h>
43 
44 #include "qabstractfloat_p.h"
45 #include "qanyuri_p.h"
46 #include "qbase64binary_p.h"
47 #include "qboolean_p.h"
48 #include "qcommonvalues_p.h"
49 #include "qdate_p.h"
50 #include "qschemadatetime_p.h"
51 #include "qdaytimeduration_p.h"
52 #include "qdecimal_p.h"
53 #include "qduration_p.h"
54 #include "qgday_p.h"
55 #include "qgmonth_p.h"
56 #include "qgmonthday_p.h"
57 #include "qgyear_p.h"
58 #include "qgyearmonth_p.h"
59 #include "qhexbinary_p.h"
60 #include "qinteger_p.h"
61 #include "qatomicstring_p.h"
62 #include "qschematime_p.h"
63 #include "quntypedatomic_p.h"
64 #include "qyearmonthduration_p.h"
65 
66 #include "qatomiccasters_p.h"
67 
69 
70 using namespace QPatternist;
71 
74 {
76 }
77 
80 {
81  return toItem(AnyURI::fromLexical(from.stringValue()));
82 }
83 
86 {
88 }
89 
92 {
93  return HexBinary::fromLexical(context->namePool(), from.stringValue());
94 }
95 
98 {
100 }
101 
104 {
105  return Base64Binary::fromLexical(from.stringValue());
106 }
107 
110 {
111  const xsDouble val = from.as<Numeric>()->toDouble();
112  if(Double::isEqual(val, 0.0) || qIsNaN(val))
114  else
116 }
117 
120 {
121  return Boolean::fromLexical(from.stringValue());
122 }
123 
126 {
127  return Decimal::fromLexical(from.stringValue());
128 }
129 
132 {
133  return Integer::fromLexical(from.stringValue());
134 }
135 
138 {
139  if(from.as<AtomicValue>()->evaluateEBV(context))
141  else
143 }
144 
147 {
148  if(from.as<AtomicValue>()->evaluateEBV(context))
150  else
152 }
153 
156 {
157  return from;
158 }
159 
162 {
163  return GYear::fromLexical(from.stringValue());
164 }
165 
168 {
169  return GDay::fromLexical(from.stringValue());
170 }
171 
174 {
175  return GMonth::fromLexical(from.stringValue());
176 }
177 
180 {
181  return GYearMonth::fromLexical(from.stringValue());
182 }
183 
186 {
187  return GMonthDay::fromLexical(from.stringValue());
188 }
189 
192 {
193  return DateTime::fromLexical(from.stringValue());
194 }
195 
198 {
199  return SchemaTime::fromLexical(from.stringValue());
200 }
201 
204 {
205  return Date::fromLexical(from.stringValue());
206 }
207 
210 {
211  return Duration::fromLexical(from.stringValue());
212 }
213 
216 {
218 }
219 
222 {
223  const AbstractDuration *const val = from.as<AbstractDuration>();
224 
226  val->days(),
227  val->hours(),
228  val->minutes(),
229  val->seconds(),
230  val->mseconds()));
231 }
232 
235 {
236  const AbstractDuration *const val = from.as<AbstractDuration>();
237 
239  val->years(),
240  val->months()));
241 }
242 
245 {
246  const AbstractDuration *const val = from.as<AbstractDuration>();
247 
248  return Duration::fromComponents(val->isPositive(),
249  val->years(),
250  val->months(),
251  val->days(),
252  val->hours(),
253  val->minutes(),
254  val->seconds(),
255  val->mseconds());
256 }
257 
260 {
262 }
263 
266 {
267  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
268  // TODO DT dt.setDateOnly(true);
269 
270  return GYear::fromDateTime(dt);
271 }
272 
275 {
276  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
277  // TODO DT dt.setDateOnly(true);
278 
279  return GYearMonth::fromDateTime(dt);
280 }
281 
284 {
285  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
286  // TODO DT dt.setDateOnly(true);
287 
288  return GMonth::fromDateTime(dt);
289 }
290 
293 {
294  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
295  // TODO DT dt.setDateOnly(true);
296 
297  return GMonthDay::fromDateTime(dt);
298 }
299 
302 {
303  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
304  // TODO DT dt.setDateOnly(true);
305 
306  return GDay::fromDateTime(dt);
307 }
308 
311 {
312  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
313  // TODO DT dt.setDateOnly(false);
314 
315  return DateTime::fromDateTime(dt);
316 }
317 
320 {
321  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
322  // TODO DT dt.setDateOnly(true);
323 
324  return Date::fromDateTime(dt);
325 }
326 
329 {
330  QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
331  // TODO DT dt.setDateOnly(false);
332 
333  return SchemaTime::fromDateTime(dt);
334 }
335 
static GMonth::Ptr fromLexical(const QString &string)
Definition: qgmonth.cpp:54
virtual NamePool::Ptr namePool() const =0
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual SecondProperty seconds() const =0
static GMonth::Ptr fromDateTime(const QDateTime &dt)
Definition: qgmonth.cpp:77
static Date::Ptr fromLexical(const QString &string)
Definition: qdate.cpp:55
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Base class for classes implementing durations.
Base class for classes implementing values related to time, date or both.
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static DayTimeDuration::Ptr fromComponents(const bool isPositive, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
static AtomicValue::Ptr fromLexical(const QString &strNumeric)
Definition: qdecimal.cpp:64
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static const AtomicValue::Ptr BooleanTrue
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static Date::Ptr fromDateTime(const QDateTime &date)
Definition: qdate.cpp:88
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual MinuteProperty minutes() const =0
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static const Item IntegerOne
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
static AtomicValue::Ptr fromLexical(const NamePool::Ptr &np, const QString &value)
Definition: qhexbinary.cpp:80
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static DateTime::Ptr fromDateTime(const QDateTime &dt)
static Duration::Ptr fromComponents(const bool isPositive, const YearProperty years, const MonthProperty months, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
Definition: qduration.cpp:113
static GMonthDay::Ptr fromLexical(const QString &string)
Definition: qgmonthday.cpp:54
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static const AtomicValue::Ptr DecimalOne
static const Item IntegerZero
Contains class DateTime. This file was originally called qdatetime_p.h, but various build systems can...
static UntypedAtomic::Ptr fromValue(const QString &value)
static GYearMonth::Ptr fromDateTime(const QDateTime &dt)
Definition: qgyearmonth.cpp:85
static DayTimeDuration::Ptr fromLexical(const QString &string)
static YearMonthDuration::Ptr fromLexical(const QString &string)
virtual MonthProperty months() const =0
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static GYearMonth::Ptr fromLexical(const QString &string)
Definition: qgyearmonth.cpp:54
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static AtomicValue::Ptr fromLexical(const QString &val)
Definition: qboolean.cpp:120
static AtomicValue::Ptr fromLexical(const QString &value)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual DayCountProperty days() const =0
virtual bool evaluateEBV(const QExplicitlySharedDataPointer< DynamicContext > &context) const
Base class for all classes representing atomic values.
Definition: qitem_p.h:118
static GDay::Ptr fromLexical(const QString &string)
Definition: qgday.cpp:54
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static GMonthDay::Ptr fromDateTime(const QDateTime &dt)
Definition: qgmonthday.cpp:80
The namespace for the internal API of QtXmlPatterns.
static GDay::Ptr fromDateTime(const QDateTime &dt)
Definition: qgday.cpp:78
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
static GYear::Ptr fromLexical(const QString &string)
Definition: qgyear.cpp:54
static Duration::Ptr fromLexical(const QString &string)
Definition: qduration.cpp:70
const QDateTime & toDateTime() const
static DateTime::Ptr fromLexical(const QString &string)
virtual HourProperty hours() const =0
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual YearProperty years() const =0
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Contains classes sub-classing AtomicCaster and which are responsible of casting an atomic value to an...
static AnyURI::Ptr fromLexical(const QString &value, const TReportContext &context, const SourceLocationReflection *const r)
Constructs a xs:anyURI value from the lexical representation value.
Definition: qanyuri_p.h:153
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static YearMonthDuration::Ptr fromComponents(const bool isPositive, const YearProperty years, const MonthProperty months)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static bool isEqual(const xsDouble a, const xsDouble b)
Base class for all numeric values.
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static SchemaTime::Ptr fromDateTime(const QDateTime &dt)
Definition: qschematime.cpp:87
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static HexBinary::Ptr fromValue(const QByteArray &data)
Definition: qhexbinary.cpp:123
const QByteArray & asByteArray() const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static AtomicValue::Ptr fromLexical(const QString &strNumeric)
Definition: qinteger.cpp:57
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static qreal toDouble(const QChar *&str)
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static const AtomicValue::Ptr DecimalZero
TCastTarget * as() const
Definition: qitem_p.h:278
static const AtomicValue::Ptr BooleanFalse
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Implements the value instance of the xs:base64Binary type.
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
static SchemaTime::Ptr fromLexical(const QString &string)
Definition: qschematime.cpp:55
virtual MSecondProperty mseconds() const =0
static Base64Binary::Ptr fromValue(const QByteArray &data)
static GYear::Ptr fromDateTime(const QDateTime &dt)
Definition: qgyear.cpp:83
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const