summaryrefslogtreecommitdiffstats
path: root/src/xmlpatterns/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlpatterns/data')
-rw-r--r--src/xmlpatterns/data/data.pri78
-rw-r--r--src/xmlpatterns/data/qabstractdatetime.cpp400
-rw-r--r--src/xmlpatterns/data/qabstractdatetime_p.h261
-rw-r--r--src/xmlpatterns/data/qabstractduration.cpp235
-rw-r--r--src/xmlpatterns/data/qabstractduration_p.h192
-rw-r--r--src/xmlpatterns/data/qabstractfloat.cpp321
-rw-r--r--src/xmlpatterns/data/qabstractfloat_p.h174
-rw-r--r--src/xmlpatterns/data/qabstractfloatcasters.cpp71
-rw-r--r--src/xmlpatterns/data/qabstractfloatcasters_p.h175
-rw-r--r--src/xmlpatterns/data/qabstractfloatmathematician.cpp97
-rw-r--r--src/xmlpatterns/data/qabstractfloatmathematician_p.h104
-rw-r--r--src/xmlpatterns/data/qanyuri.cpp104
-rw-r--r--src/xmlpatterns/data/qanyuri_p.h212
-rw-r--r--src/xmlpatterns/data/qatomiccaster.cpp56
-rw-r--r--src/xmlpatterns/data/qatomiccaster_p.h94
-rw-r--r--src/xmlpatterns/data/qatomiccasters.cpp336
-rw-r--r--src/xmlpatterns/data/qatomiccasters_p.h705
-rw-r--r--src/xmlpatterns/data/qatomiccomparator.cpp118
-rw-r--r--src/xmlpatterns/data/qatomiccomparator_p.h223
-rw-r--r--src/xmlpatterns/data/qatomiccomparators.cpp386
-rw-r--r--src/xmlpatterns/data/qatomiccomparators_p.h298
-rw-r--r--src/xmlpatterns/data/qatomicmathematician.cpp73
-rw-r--r--src/xmlpatterns/data/qatomicmathematician_p.h136
-rw-r--r--src/xmlpatterns/data/qatomicmathematicians.cpp352
-rw-r--r--src/xmlpatterns/data/qatomicmathematicians_p.h249
-rw-r--r--src/xmlpatterns/data/qatomicstring.cpp74
-rw-r--r--src/xmlpatterns/data/qatomicstring_p.h123
-rw-r--r--src/xmlpatterns/data/qatomicvalue.cpp228
-rw-r--r--src/xmlpatterns/data/qbase64binary.cpp216
-rw-r--r--src/xmlpatterns/data/qbase64binary_p.h118
-rw-r--r--src/xmlpatterns/data/qboolean.cpp137
-rw-r--r--src/xmlpatterns/data/qboolean_p.h126
-rw-r--r--src/xmlpatterns/data/qcommonvalues.cpp123
-rw-r--r--src/xmlpatterns/data/qcommonvalues_p.h228
-rw-r--r--src/xmlpatterns/data/qdate.cpp115
-rw-r--r--src/xmlpatterns/data/qdate_p.h95
-rw-r--r--src/xmlpatterns/data/qdaytimeduration.cpp242
-rw-r--r--src/xmlpatterns/data/qdaytimeduration_p.h154
-rw-r--r--src/xmlpatterns/data/qdecimal.cpp234
-rw-r--r--src/xmlpatterns/data/qdecimal_p.h156
-rw-r--r--src/xmlpatterns/data/qderivedinteger_p.h624
-rw-r--r--src/xmlpatterns/data/qderivedstring_p.h341
-rw-r--r--src/xmlpatterns/data/qduration.cpp244
-rw-r--r--src/xmlpatterns/data/qduration_p.h136
-rw-r--r--src/xmlpatterns/data/qgday.cpp96
-rw-r--r--src/xmlpatterns/data/qgday_p.h94
-rw-r--r--src/xmlpatterns/data/qgmonth.cpp95
-rw-r--r--src/xmlpatterns/data/qgmonth_p.h94
-rw-r--r--src/xmlpatterns/data/qgmonthday.cpp98
-rw-r--r--src/xmlpatterns/data/qgmonthday_p.h95
-rw-r--r--src/xmlpatterns/data/qgyear.cpp101
-rw-r--r--src/xmlpatterns/data/qgyear_p.h94
-rw-r--r--src/xmlpatterns/data/qgyearmonth.cpp103
-rw-r--r--src/xmlpatterns/data/qgyearmonth_p.h94
-rw-r--r--src/xmlpatterns/data/qhexbinary.cpp151
-rw-r--r--src/xmlpatterns/data/qhexbinary_p.h109
-rw-r--r--src/xmlpatterns/data/qinteger.cpp164
-rw-r--r--src/xmlpatterns/data/qinteger_p.h141
-rw-r--r--src/xmlpatterns/data/qitem.cpp58
-rw-r--r--src/xmlpatterns/data/qitem_p.h542
-rw-r--r--src/xmlpatterns/data/qnodebuilder.cpp48
-rw-r--r--src/xmlpatterns/data/qnodebuilder_p.h111
-rw-r--r--src/xmlpatterns/data/qnodemodel.cpp52
-rw-r--r--src/xmlpatterns/data/qqnamevalue.cpp75
-rw-r--r--src/xmlpatterns/data/qqnamevalue_p.h113
-rw-r--r--src/xmlpatterns/data/qresourceloader.cpp134
-rw-r--r--src/xmlpatterns/data/qresourceloader_p.h320
-rw-r--r--src/xmlpatterns/data/qschemadatetime.cpp117
-rw-r--r--src/xmlpatterns/data/qschemadatetime_p.h101
-rw-r--r--src/xmlpatterns/data/qschemanumeric.cpp92
-rw-r--r--src/xmlpatterns/data/qschemanumeric_p.h235
-rw-r--r--src/xmlpatterns/data/qschematime.cpp121
-rw-r--r--src/xmlpatterns/data/qschematime_p.h98
-rw-r--r--src/xmlpatterns/data/qsequencereceiver.cpp126
-rw-r--r--src/xmlpatterns/data/qsequencereceiver_p.h192
-rw-r--r--src/xmlpatterns/data/qsorttuple.cpp89
-rw-r--r--src/xmlpatterns/data/qsorttuple_p.h148
-rw-r--r--src/xmlpatterns/data/quntypedatomic.cpp64
-rw-r--r--src/xmlpatterns/data/quntypedatomic_p.h97
-rw-r--r--src/xmlpatterns/data/qvalidationerror.cpp90
-rw-r--r--src/xmlpatterns/data/qvalidationerror_p.h123
-rw-r--r--src/xmlpatterns/data/qyearmonthduration.cpp186
-rw-r--r--src/xmlpatterns/data/qyearmonthduration_p.h151
83 files changed, 14176 insertions, 0 deletions
diff --git a/src/xmlpatterns/data/data.pri b/src/xmlpatterns/data/data.pri
new file mode 100644
index 0000000..99591d4
--- /dev/null
+++ b/src/xmlpatterns/data/data.pri
@@ -0,0 +1,78 @@
+HEADERS += $$PWD/qabstractdatetime_p.h \
+ $$PWD/qabstractduration_p.h \
+ $$PWD/qabstractfloatcasters_p.h \
+ $$PWD/qabstractfloat_p.h \
+ $$PWD/qabstractfloatmathematician_p.h \
+ $$PWD/qanyuri_p.h \
+ $$PWD/qatomiccaster_p.h \
+ $$PWD/qatomiccasters_p.h \
+ $$PWD/qatomiccomparator_p.h \
+ $$PWD/qatomiccomparators_p.h \
+ $$PWD/qatomicmathematician_p.h \
+ $$PWD/qatomicmathematicians_p.h \
+ $$PWD/qatomicstring_p.h \
+ $$PWD/qbase64binary_p.h \
+ $$PWD/qboolean_p.h \
+ $$PWD/qcommonvalues_p.h \
+ $$PWD/qdate_p.h \
+ $$PWD/qschemadatetime_p.h \
+ $$PWD/qdaytimeduration_p.h \
+ $$PWD/qdecimal_p.h \
+ $$PWD/qderivedinteger_p.h \
+ $$PWD/qderivedstring_p.h \
+ $$PWD/qduration_p.h \
+ $$PWD/qgday_p.h \
+ $$PWD/qgmonthday_p.h \
+ $$PWD/qgmonth_p.h \
+ $$PWD/qgyear_p.h \
+ $$PWD/qgyearmonth_p.h \
+ $$PWD/qhexbinary_p.h \
+ $$PWD/qinteger_p.h \
+ $$PWD/qitem_p.h \
+ $$PWD/qnodebuilder_p.h \
+ $$PWD/qschemanumeric_p.h \
+ $$PWD/qqnamevalue_p.h \
+ $$PWD/qresourceloader_p.h \
+ $$PWD/qsorttuple.cpp \
+ $$PWD/qschematime_p.h \
+ $$PWD/quntypedatomic_p.h \
+ $$PWD/qvalidationerror_p.h \
+ $$PWD/qyearmonthduration_p.h
+
+SOURCES += $$PWD/qabstractdatetime.cpp \
+ $$PWD/qabstractduration.cpp \
+ $$PWD/qanyuri.cpp \
+ $$PWD/qatomiccaster.cpp \
+ $$PWD/qatomiccasters.cpp \
+ $$PWD/qatomiccomparator.cpp \
+ $$PWD/qatomiccomparators.cpp \
+ $$PWD/qatomicmathematician.cpp \
+ $$PWD/qatomicmathematicians.cpp \
+ $$PWD/qatomicstring.cpp \
+ $$PWD/qatomicvalue.cpp \
+ $$PWD/qbase64binary.cpp \
+ $$PWD/qboolean.cpp \
+ $$PWD/qcommonvalues.cpp \
+ $$PWD/qdate.cpp \
+ $$PWD/qschemadatetime.cpp \
+ $$PWD/qdaytimeduration.cpp \
+ $$PWD/qdecimal.cpp \
+ $$PWD/qduration.cpp \
+ $$PWD/qgday.cpp \
+ $$PWD/qgmonth.cpp \
+ $$PWD/qgmonthday.cpp \
+ $$PWD/qgyear.cpp \
+ $$PWD/qgyearmonth.cpp \
+ $$PWD/qhexbinary.cpp \
+ $$PWD/qinteger.cpp \
+ $$PWD/qitem.cpp \
+ $$PWD/qnodebuilder.cpp \
+ $$PWD/qnodemodel.cpp \
+ $$PWD/qschemanumeric.cpp \
+ $$PWD/qqnamevalue.cpp \
+ $$PWD/qresourceloader.cpp \
+ $$PWD/qsorttuple.cpp \
+ $$PWD/qschematime.cpp \
+ $$PWD/quntypedatomic.cpp \
+ $$PWD/qvalidationerror.cpp \
+ $$PWD/qyearmonthduration.cpp
diff --git a/src/xmlpatterns/data/qabstractdatetime.cpp b/src/xmlpatterns/data/qabstractdatetime.cpp
new file mode 100644
index 0000000..819f033
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractdatetime.cpp
@@ -0,0 +1,400 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QStringList>
+
+#include "qbuiltintypes_p.h"
+#include "qitem_p.h"
+#include "qpatternistlocale_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AbstractDateTime::AbstractDateTime(const QDateTime &dateTime) : m_dateTime(dateTime)
+{
+ Q_ASSERT(dateTime.isValid());
+}
+
+#define badData(msg) errorMessage = ValidationError::createError(msg); return QDateTime()
+#define getCapt(sym) ((captTable.sym == -1) ? QString() : capts.at(captTable.sym))
+#define getSafeCapt(sym) ((captTable.sym == -1) ? QString() : capts.value(captTable.sym))
+
+QDateTime AbstractDateTime::create(AtomicValue::Ptr &errorMessage,
+ const QString &lexicalSource,
+ const CaptureTable &captTable)
+{
+ QRegExp myExp(captTable.regExp);
+
+ if(!myExp.exactMatch(lexicalSource))
+ {
+ badData(QString());
+ }
+
+ const QStringList capts(myExp.capturedTexts());
+ const QString yearStr(getCapt(year));
+
+ if(yearStr.size() > 4 && yearStr.at(0) == QLatin1Char('0'))
+ {
+ badData(QtXmlPatterns::tr("Year %1 is invalid because it begins with %2.")
+ .arg(formatData(yearStr)).arg(formatData("0")));
+ }
+
+ /* If the strings are empty, load default values which are
+ * guranteed to pass the validness tests. */
+ const QString monthStr(getCapt(month));
+ const QString dayStr(getCapt(day));
+ YearProperty year = yearStr.isEmpty() ? DefaultYear : yearStr.toInt();
+ if(getCapt(yearSign) == QChar::fromLatin1('-'))
+ year = -year;
+ const MonthProperty month = monthStr.isEmpty() ? DefaultMonth : monthStr.toInt();
+ const MonthProperty day = dayStr.isEmpty() ? DefaultDay : dayStr.toInt();
+
+ if(!QDate::isValid(year, month, day))
+ {
+ /* Try to give an intelligent message. */
+ if(day > 31 || day < 1)
+ {
+ badData(QtXmlPatterns::tr("Day %1 is outside the range %2..%3.")
+ .arg(formatData(QString::number(day)))
+ .arg(formatData("01"))
+ .arg(formatData("31")));
+ }
+ else if(month > 12 || month < -12 || month == 0)
+ {
+ badData(QtXmlPatterns::tr("Month %1 is outside the range %2..%3.")
+ .arg(month)
+ .arg(formatData("01"))
+ .arg(formatData("12")));
+
+ }
+ else if(QDate::isValid(DefaultYear, month, day))
+ {
+ /* We can't use the badData() macro here because we need a different
+ * error code: FODT0001 instead of FORG0001. */
+ errorMessage = ValidationError::createError(QtXmlPatterns::tr(
+ "Overflow: Can't represent date %1.")
+ .arg(formatData(QLatin1String("%1-%2-%3"))
+ .arg(year).arg(month).arg(day)),
+ ReportContext::FODT0001);
+ return QDateTime();
+ }
+ else
+ {
+ badData(QtXmlPatterns::tr("Day %1 is invalid for month %2.")
+ .arg(formatData(QString::number(day)))
+ .arg(formatData(QString::number(month))));
+ }
+ }
+
+ /* Parse the zone offset. */
+ ZoneOffsetParseResult zoResult;
+ const ZOTotal offset = parseZoneOffset(zoResult, capts, captTable);
+
+ if(zoResult == Error)
+ {
+ errorMessage = ValidationError::createError();
+ /* We encountered an error, so stop processing. */
+ return QDateTime();
+ }
+
+ QDate date(year, month, day);
+
+ /* Only deal with time if time is needed. */
+ if(captTable.hour == -1)
+ {
+ QDateTime result(date);
+ setUtcOffset(result, zoResult, offset);
+ return result;
+ }
+ else
+ {
+ /* Now, it's time for the time-part.
+ *
+ * If the strings are empty, toInt() will return 0, which
+ * in all cases is valid properties. */
+ const QString hourStr(getCapt(hour));
+ const QString minutesStr(getCapt(minutes));
+ const QString secondsStr(getCapt(seconds));
+ HourProperty hour = hourStr.toInt();
+ const MinuteProperty mins = minutesStr.toInt();
+ const SecondProperty secs = secondsStr.toInt();
+
+ QString msecondsStr(getSafeCapt(mseconds));
+ if(!msecondsStr.isEmpty())
+ msecondsStr = msecondsStr.leftJustified(3, QLatin1Char('0'));
+ const MSecondProperty msecs = msecondsStr.toInt();
+
+ if(hour == 24)
+ {
+ /* 24:00:00.00 is an invalid time for QTime, so handle it here. */
+ if(mins != 0 || secs != 0 || msecs != 0)
+ {
+ badData(QtXmlPatterns::tr("Time 24:%1:%2.%3 is invalid. "
+ "Hour is 24, but minutes, seconds, "
+ "and milliseconds are not all 0; ")
+ .arg(mins).arg(secs).arg(msecs));
+ }
+ else
+ {
+ hour = 0;
+ date = date.addDays(1);
+ }
+ }
+ else if(!QTime::isValid(hour, mins, secs, msecs))
+ {
+ badData(QtXmlPatterns::tr("Time %1:%2:%3.%4 is invalid.")
+ .arg(hour).arg(mins).arg(secs).arg(msecs));
+ }
+
+ const QTime time(hour, mins, secs, msecs);
+ Q_ASSERT(time.isValid());
+
+ QDateTime result(date, time);
+ setUtcOffset(result, zoResult, offset);
+ return result;
+ }
+}
+
+ZOTotal AbstractDateTime::parseZoneOffset(ZoneOffsetParseResult &result,
+ const QStringList &capts,
+ const CaptureTable &captTable)
+{
+ const QString zoneOffsetSignStr(getCapt(zoneOffsetSign));
+
+ if(zoneOffsetSignStr.isEmpty())
+ {
+ const QString zoneOffsetUTCStr(getCapt(zoneOffsetUTCSymbol));
+ Q_ASSERT(zoneOffsetUTCStr.isEmpty() || zoneOffsetUTCStr == QLatin1String("Z"));
+
+ if(zoneOffsetUTCStr.isEmpty())
+ result = LocalTime;
+ else
+ result = UTC;
+
+ return 0;
+ }
+
+ Q_ASSERT(zoneOffsetSignStr == QLatin1String("-") || zoneOffsetSignStr == QLatin1String("+"));
+
+ const QString zoneOffsetHourStr(getCapt(zoneOffsetHour));
+ Q_ASSERT(!zoneOffsetHourStr.isEmpty());
+ const ZOHourProperty zoHour = zoneOffsetHourStr.toInt();
+
+ if(zoHour > 14 || zoHour < -14)
+ {
+ result = Error;
+ return 0;
+ /*
+ badZOData(QtXmlPatterns::tr("%1 it is not a valid hour property in a zone offset. "
+ "It must be less than or equal to 14.").arg(zoHour));
+ */
+ }
+
+ const QString zoneOffsetMinuteStr(getCapt(zoneOffsetMinute));
+ Q_ASSERT(!zoneOffsetMinuteStr.isEmpty());
+ const ZOHourProperty zoMins = zoneOffsetMinuteStr.toInt();
+
+ if(zoHour == 14 && zoMins != 0)
+ {
+ /*
+ badZOData(QtXmlPatterns::tr("When the hour property in a zone offset is 14, the minute property "
+ "must be 0, not %1.").arg(zoMins));
+ */
+ result = Error;
+ return 0;
+ }
+ else if(zoMins > 59 || zoMins < -59)
+ {
+ /*
+ badZOData(QtXmlPatterns::tr("The minute property in a zone offset cannot be larger than 59. "
+ "%1 is therefore invalid.").arg(zoMins));
+ */
+ result = Error;
+ return 0;
+ }
+
+ if(zoHour == 0 && zoMins == 0) /* "-00:00" and "+00:00" is equal to 'Z'. */
+ {
+ result = UTC;
+ return 0;
+ }
+ else
+ {
+ ZOTotal zoneOffset = (zoHour * 60 + zoMins) * 60;
+
+ if(zoneOffsetSignStr == QChar::fromLatin1('-'))
+ zoneOffset = -zoneOffset;
+
+ result = Offset;
+ return zoneOffset;
+ }
+}
+//#undef badZOData
+
+void AbstractDateTime::setUtcOffset(QDateTime &result,
+ const ZoneOffsetParseResult zoResult,
+ const int zoOffset)
+{
+ if(zoResult == UTC)
+ result.setTimeSpec(Qt::UTC);
+ else if(zoResult == LocalTime)
+ result.setTimeSpec(Qt::LocalTime);
+ else
+ {
+ Q_ASSERT(zoResult == Offset);
+ result.setUtcOffset(zoOffset);
+ }
+}
+
+#undef badData
+#undef getCapt
+#undef getSafeCapt
+
+bool AbstractDateTime::isRangeValid(const QDate &date,
+ QString &message)
+{
+ if(date.isValid())
+ return true;
+ else
+ {
+ message = QtXmlPatterns::tr("Overflow: Date can't be represented.");
+ return false;
+ }
+}
+
+QString AbstractDateTime::dateToString() const
+{
+ return m_dateTime.toString(QLatin1String("yyyy-MM-dd"));
+}
+
+QString AbstractDateTime::serializeMSeconds(const MSecondProperty mseconds)
+{
+ QString retval;
+ retval.append(QLatin1Char('.'));
+ int div = 100;
+ MSecondProperty msecs = mseconds;
+
+ while(msecs > 0)
+ {
+ int d = msecs / div;
+ retval.append(QLatin1Char(d + '0'));
+ msecs = msecs % div;
+ div = div / 10;
+ }
+
+ return retval;
+}
+
+QString AbstractDateTime::timeToString() const
+{
+ QString base(m_dateTime.toString(QLatin1String("hh:mm:ss")));
+ const MSecondProperty msecs = m_dateTime.time().msec();
+
+ if(msecs)
+ base.append(serializeMSeconds(msecs));
+
+ return base;
+}
+
+QString AbstractDateTime::zoneOffsetToString() const
+{
+ switch(m_dateTime.timeSpec())
+ {
+ case Qt::LocalTime:
+ return QString();
+ case Qt::UTC:
+ return QLatin1String("Z");
+ default:
+ {
+ Q_ASSERT(m_dateTime.timeSpec() == Qt::OffsetFromUTC);
+
+ const int zoneOffset = m_dateTime.utcOffset();
+ Q_ASSERT(zoneOffset != 0);
+ const int posZoneOffset = qAbs(zoneOffset);
+
+ /* zoneOffset is in seconds. */
+ const int hours = posZoneOffset/(60 * 60);
+ const int minutes = (posZoneOffset % (60 * 60)) / 60;
+
+ QString result;
+ result.reserve(6);
+
+ result.append(zoneOffset < 0 ? QLatin1Char('-') : QLatin1Char('+'));
+ result.append(QString::number(hours).rightJustified(2, QLatin1Char('0')));
+ result.append(QLatin1Char(':'));
+ result.append(QString::number(minutes).rightJustified(2, QLatin1Char('0')));
+ return result;
+ }
+ }
+}
+
+void AbstractDateTime::copyTimeSpec(const QDateTime &from,
+ QDateTime &to)
+{
+ switch(from.timeSpec())
+ {
+ case Qt::UTC:
+ /* Fallthrough. */
+ case Qt::LocalTime:
+ {
+ to.setTimeSpec(from.timeSpec());
+ return;
+ }
+ case Qt::OffsetFromUTC:
+ {
+ to.setUtcOffset(from.utcOffset());
+ Q_ASSERT(to.timeSpec() == Qt::OffsetFromUTC);
+ return;
+ }
+ }
+}
+
+Item AbstractDateTime::fromValue(const QDateTime &) const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "Calling AbstractDateTime::fromDateTime() makes no sense.");
+ return Item();
+}
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qabstractdatetime_p.h b/src/xmlpatterns/data/qabstractdatetime_p.h
new file mode 100644
index 0000000..2786adf
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractdatetime_p.h
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AbstractDateTime_H
+#define Patternist_AbstractDateTime_H
+
+#include <QDateTime>
+#include <QRegExp>
+
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Base class for classes implementing values related to time, date or both.
+ *
+ * @see <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">XML Schema
+ * Part 2: Datatypes Second Edition, 3.2.7 dateTime</a>
+ * @see <a href="http://www.w3.org/TR/xpath-datamodel/#dates-and-times">XQuery
+ * 1.0 and XPath 2.0 Data Model (XDM), 3.3.2 Dates and Times</a>
+ * @see <a href="http://www.cl.cam.ac.uk/~mgk25/iso-time.html">A summary of
+ * the international standard date and time notation, Markus Kuhn</a>
+ * @see <a href="http://en.wikipedia.org/wiki/Iso_date">ISO 8601,
+ * From Wikipedia, the free encyclopedia</a>
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class AbstractDateTime : public AtomicValue
+ {
+ public:
+ typedef QExplicitlySharedDataPointer<AbstractDateTime> Ptr;
+
+ AbstractDateTime(const QDateTime &dateTime);
+
+ enum
+ {
+ DefaultYear = 2000,
+ DefaultMonth = 1,
+ DefaultDay = 1
+ };
+
+ /**
+ * @returns the date time this class represents, as a QDateTime.
+ */
+ inline const QDateTime &toDateTime() const
+ {
+ return m_dateTime;
+ }
+
+
+ /**
+ * @short Acts as a mapping table for AbstractDateTime::create()
+ * and describes where certain fields in a QRegExp pattern can be found
+ * for a particular W3C XML Schema date/time type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class CaptureTable
+ {
+ public:
+ CaptureTable(const QRegExp &exp,
+ const qint8 zoneOffsetSignP,
+ const qint8 zoneOffsetHourP,
+ const qint8 zoneOffsetMinuteP,
+ const qint8 zoneOffsetUTCSymbolP,
+ const qint8 yearP,
+ const qint8 monthP = -1,
+ const qint8 dayP = -1,
+ const qint8 hourP = -1,
+ const qint8 minutesP = -1,
+ const qint8 secondsP = -1,
+ const qint8 msecondsP = -1,
+ const qint8 yearSignP = -1) : regExp(exp)
+ , zoneOffsetSign(zoneOffsetSignP)
+ , zoneOffsetHour(zoneOffsetHourP)
+ , zoneOffsetMinute(zoneOffsetMinuteP)
+ , zoneOffsetUTCSymbol(zoneOffsetUTCSymbolP)
+ , year(yearP)
+ , month(monthP)
+ , day(dayP)
+ , hour(hourP)
+ , minutes(minutesP)
+ , seconds(secondsP)
+ , mseconds(msecondsP)
+ , yearSign(yearSignP)
+ {
+ Q_ASSERT(exp.isValid());
+ }
+
+ const QRegExp regExp;
+ const qint8 zoneOffsetSign;
+ const qint8 zoneOffsetHour;
+ const qint8 zoneOffsetMinute;
+ const qint8 zoneOffsetUTCSymbol;
+ const qint8 year;
+ const qint8 month;
+ const qint8 day;
+ const qint8 hour;
+ const qint8 minutes;
+ const qint8 seconds;
+ const qint8 mseconds;
+ const qint8 yearSign;
+
+ private:
+ Q_DISABLE_COPY(CaptureTable)
+ };
+
+ /**
+ * @returns m_dateTime's time part converted to string. This is for
+ * example "12" or "01.023".
+ */
+ QString timeToString() const;
+
+ /**
+ * @returns m_dateTime's date part converted to string. This is for
+ * example "2004-05-12" or "-2004-05-12".
+ */
+ QString dateToString() const;
+
+ /**
+ * Serializes the milli seconds @p msecs into a string representation. For
+ * example, if @p msecs is 1, ".001" is returned; if @p msecs is 100 then
+ * is ".1" returned.
+ */
+ static QString serializeMSeconds(const MSecondProperty msecs);
+
+ /**
+ * A factory function for creating instances that are of the dynamic
+ * type of this class, that represents @p dt.
+ *
+ * The default implementation performs an assert() call. This function
+ * is not pure virtual because all sub-classes do not use it.
+ */
+ virtual Item fromValue(const QDateTime &dt) const;
+
+ /**
+ * Determines whether @p dt is a date-time that can be represented,
+ * and isn't too early or too late. If it is valid, @c true is returned. Otherwise,
+ * @c false is returned and @p message is set to contain a translated message for
+ * human consumption, describing the error.
+ */
+ static bool isRangeValid(const QDate &date,
+ QString &message);
+
+ protected:
+
+ /**
+ * @returns m_dateTime' zone offset converted to string, as per the
+ * the W3C XML Schema types. This is for
+ * example "Z" or "+12.00"(depending on m_dateTime).
+ */
+ QString zoneOffsetToString() const;
+
+ static QDateTime create(AtomicValue::Ptr &errorMessage,
+ const QString &lexicalSource,
+ const CaptureTable &captTable);
+
+ /**
+ * @short Makes the QDateTime::timeSpec() and QDateTime::zoneOffset()
+ * of @p ot * consistent to @p from.
+ */
+ static void copyTimeSpec(const QDateTime &from,
+ QDateTime &to);
+
+ const QDateTime m_dateTime;
+
+ private:
+ enum ZoneOffsetParseResult
+ {
+ /**
+ * syntax or logical error was encountered.
+ */
+ Error,
+ /**
+ * It's a valid offset from UTC.
+ */
+ Offset,
+
+ /**
+ * No zone offset was specified, it's an implementation defined zone offset.
+ */
+ LocalTime,
+ UTC
+ };
+
+ /**
+ * @short Parses the zone offset. All types use zone offsets.
+ *
+ * If result is set to Offset, the offset is returned, otherwise
+ * the return value is undefined.
+ *
+ * The offset is in seconds.
+ */
+ static ZOTotal parseZoneOffset(ZoneOffsetParseResult &result,
+ const QStringList &capts,
+ const CaptureTable &captTable);
+
+ static inline void setUtcOffset(QDateTime &result,
+ const ZoneOffsetParseResult zoResult,
+ const int zoOffset);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qabstractduration.cpp b/src/xmlpatterns/data/qabstractduration.cpp
new file mode 100644
index 0000000..4f34ff3
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractduration.cpp
@@ -0,0 +1,235 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QStringList>
+
+#include "qbuiltintypes_p.h"
+#include "qpatternistlocale_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qabstractduration_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AbstractDuration::AbstractDuration(const bool isPos) : m_isPositive(isPos)
+{
+}
+
+#define error(msg) return ValidationError::createError(msg);
+#define getCapt(sym) ((captTable.sym == -1) ? QString() : capts.at(captTable.sym))
+
+AtomicValue::Ptr AbstractDuration::create(const CaptureTable &captTable,
+ const QString &lexical,
+ bool *isPositive,
+ YearProperty *years,
+ MonthProperty *months,
+ DayCountProperty *days,
+ HourProperty *hours,
+ MinuteProperty *minutes,
+ SecondProperty *seconds,
+ MSecondProperty *mseconds)
+{
+ /* We don't directly write into the arguments(eg @p years) but uses these
+ * because the arguments are intended for normalized values, and therefore
+ * can cause overflows. */
+ MonthCountProperty monthCount = 0;
+ MinuteCountProperty minCount = 0;
+ HourCountProperty hourCount = 0;
+ SecondCountProperty secCount = 0;
+
+ Q_ASSERT(isPositive);
+ QRegExp myExp(captTable.regExp); /* Copy, in order to stay thread safe. */
+
+ if(!myExp.exactMatch(lexical))
+ {
+ error(QString());
+ }
+
+ const QStringList capts(myExp.capturedTexts());
+
+
+ if(days)
+ {
+ if(getCapt(tDelimiter).isEmpty())
+ {
+ if((years && getCapt(year).isEmpty() && getCapt(month).isEmpty() && getCapt(day).isEmpty())
+ ||
+ (!years && getCapt(day).isEmpty()))
+ {
+ error(QtXmlPatterns::tr("At least one component must be present."));
+ }
+ }
+ else if(getCapt(hour).isEmpty() &&
+ getCapt(minutes).isEmpty() &&
+ getCapt(seconds).isEmpty() &&
+ getCapt(mseconds).isEmpty())
+ {
+ error(QtXmlPatterns::tr("At least one time component must appear "
+ "after the %1-delimiter.")
+ .arg(formatKeyword("T")));
+ }
+ }
+ else if(getCapt(year).isEmpty() && getCapt(month).isEmpty()) /* This checks xs:yearMonthDuration. */
+ {
+ error(QtXmlPatterns::tr("At least one component must be present."));
+ }
+
+ /* If we got no '-', we are positive. */
+ *isPositive = capts.at(1).isEmpty();
+
+ if(days)
+ {
+ Q_ASSERT(hours);
+ Q_ASSERT(minutes);
+ Q_ASSERT(seconds);
+ Q_ASSERT(mseconds);
+
+ *days = getCapt(day).toInt();
+ hourCount = getCapt(hour).toInt();
+ minCount = getCapt(minutes).toInt();
+ secCount = getCapt(seconds).toInt();
+
+ const QString msecondsStr(getCapt(mseconds));
+ if(!msecondsStr.isEmpty())
+ *mseconds = msecondsStr.leftJustified(3, QLatin1Char('0')).toInt();
+ else
+ *mseconds = msecondsStr.toInt();
+
+ if(secCount > 59)
+ {
+ minCount += secCount / 60;
+ *seconds = secCount % 60;
+ }
+ else
+ *seconds = secCount;
+
+ if(minCount > 59)
+ {
+ hourCount += minCount / 60;
+ *minutes = minCount % 60;
+ }
+ else
+ *minutes = minCount;
+
+ if(hourCount > 23)
+ {
+ *days += hourCount / 24;
+ *hours = hourCount % 24;
+ }
+ else
+ *hours = hourCount;
+ }
+
+ if(!years)
+ return AtomicValue::Ptr();
+
+ /* We're supposed to handle years/months. */
+ Q_ASSERT(months);
+
+ *years = getCapt(year).toInt();
+ monthCount = getCapt(month).toInt();
+
+ if(monthCount > 11)
+ {
+ *years += monthCount / 12;
+ *months = monthCount % 12;
+ }
+ else
+ *months = monthCount;
+
+ return AtomicValue::Ptr();
+}
+#undef error
+#undef getCapt
+
+bool AbstractDuration::operator==(const AbstractDuration &other) const
+{
+ if(years() == other.years()
+ && months() == other.months()
+ && days() == other.days()
+ && hours() == other.hours()
+ && minutes() == other.minutes()
+ && seconds() == other.seconds()
+ && mseconds() == other.mseconds())
+ {
+ if(isPositive() == other.isPositive())
+ return true;
+ else if(years() == 0
+ && months() == 0
+ && days() == 0
+ && hours() == 0
+ && minutes() == 0
+ && seconds () == 0
+ && mseconds() == 0)
+ {
+ return true; /* Signedness doesn't matter if all are zero. */
+ }
+ }
+
+ return false;
+}
+
+QString AbstractDuration::serializeMSeconds(const MSecondProperty mseconds)
+{
+ QString retval;
+ retval.append(QLatin1Char('.'));
+ int div = 100;
+ MSecondProperty msecs = mseconds;
+
+ while(msecs > 0)
+ {
+ int d = msecs / div;
+ retval.append(QLatin1Char(d + '0'));
+ msecs = msecs % div;
+ div = div / 10;
+ }
+
+ return retval;
+}
+
+bool AbstractDuration::isPositive() const
+{
+ return m_isPositive;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qabstractduration_p.h b/src/xmlpatterns/data/qabstractduration_p.h
new file mode 100644
index 0000000..af2a985
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractduration_p.h
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AbstractDuration_H
+#define Patternist_AbstractDuration_H
+
+#include <QRegExp>
+
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Base class for classes implementing durations.
+ *
+ * @see <a href="http://www.w3.org/TR/xmlschema-2/#duration">XML Schema Part
+ * 2: Datatypes Second Edition, 3.2.6 duration</a>
+ * @see <a href="http://www.w3.org/TR/xpath-datamodel/#dates-and-times">XQuery
+ * 1.0 and XPath 2.0 Data Model (XDM), 3.3.2 Dates and Times</a>
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing/incomplete
+ */
+ class AbstractDuration : public AtomicValue
+ {
+ public:
+ typedef QExplicitlySharedDataPointer<AbstractDuration> Ptr;
+
+ /**
+ * @short The amount in milli seconds.
+ */
+ typedef qint64 Value;
+
+ /**
+ * @short Acts as a mapping table for AbstractDuration::create()
+ * and describes where certain fields in a QRegExp pattern can be found
+ * for a particular W3C XML Schema duration type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class CaptureTable
+ {
+ public:
+ CaptureTable(const QRegExp &exp,
+ const qint8 yearP,
+ const qint8 monthP,
+ const qint8 dayP = -1,
+ const qint8 tDelimiterP = -1,
+ const qint8 hourP = -1,
+ const qint8 minutesP = -1,
+ const qint8 secondsP = -1,
+ const qint8 msecondsP = -1) : regExp(exp),
+ year(yearP),
+ month(monthP),
+ day(dayP),
+ tDelimiter(tDelimiterP),
+ hour(hourP),
+ minutes(minutesP),
+ seconds(secondsP),
+ mseconds(msecondsP)
+ {
+ Q_ASSERT(exp.isValid());
+ Q_ASSERT(yearP == -1 || yearP == 2);
+ }
+
+ const QRegExp regExp;
+ const qint8 year;
+ const qint8 month;
+ const qint8 day;
+ const qint8 tDelimiter;
+ const qint8 hour;
+ const qint8 minutes;
+ const qint8 seconds;
+ const qint8 mseconds;
+ };
+
+ /**
+ * Determines whether this Duration is equal to @p other.
+ *
+ * @note Do not re-implement this function. It uses getters such as years() and
+ * mseconds() for determining its truth value.
+ */
+ bool operator==(const AbstractDuration &other) const;
+
+ virtual YearProperty years() const = 0;
+ virtual MonthProperty months() const = 0;
+ virtual DayCountProperty days() const = 0;
+ virtual HourProperty hours() const = 0;
+ virtual MinuteProperty minutes() const = 0;
+ virtual SecondProperty seconds() const = 0;
+ virtual MSecondProperty mseconds() const = 0;
+
+ /**
+ * @returns the value of this AbstractDuration. For example,
+ * in the case of xs:yearMonthDuration, that is YearMonthDuration,
+ * years times twelve plus the months is returned.
+ */
+ virtual Value value() const = 0;
+
+ /**
+ * A polymorphic factory function that returns instances of the
+ * sub-class with the value @p val.
+ */
+ virtual Item fromValue(const Value val) const = 0;
+
+ /**
+ * Determines whether this AbstractDuration is positive. For example,
+ * "P10H" is positive, while "-P10H" is not.
+ *
+ * @note Do not re-implement this function. Use the constructor, AbstractDuration(),
+ * for changing the value.
+ * @returns @c true if this AbstractDuration is positive, otherwise @c false.
+ */
+ bool isPositive() const;
+
+ protected:
+
+ AbstractDuration(const bool isPos);
+
+ static QString serializeMSeconds(const MSecondProperty mseconds);
+ static AtomicValue::Ptr create(const CaptureTable &captTable,
+ const QString &lexical,
+ bool *isPositive,
+ YearProperty *years,
+ MonthProperty *months,
+ DayCountProperty *days,
+ HourProperty *hours,
+ MinuteProperty *minutes,
+ SecondProperty *seconds,
+ MSecondProperty *mseconds);
+ const bool m_isPositive;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qabstractfloat.cpp b/src/xmlpatterns/data/qabstractfloat.cpp
new file mode 100644
index 0000000..b6226b5
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractfloat.cpp
@@ -0,0 +1,321 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/**
+ * @file
+ * @short This file is included by qabstractfloat_p.h.
+ * If you need includes in this file, put them in qabstractfloat_p.h, outside of the namespace.
+ */
+
+template <const bool isDouble>
+AbstractFloat<isDouble>::AbstractFloat(const xsDouble num) : m_value(num)
+{
+}
+
+template <const bool isDouble>
+Numeric::Ptr AbstractFloat<isDouble>::fromValue(const xsDouble num)
+{
+ return Numeric::Ptr(new AbstractFloat<isDouble>(num));
+}
+
+template <const bool isDouble>
+AtomicValue::Ptr AbstractFloat<isDouble>::fromLexical(const QString &strNumeric)
+{
+ /* QString::toDouble() handles the whitespace facet. */
+
+ if(strNumeric == QLatin1String("NaN"))
+ return isDouble ? CommonValues::DoubleNaN : CommonValues::FloatNaN;
+ else if(strNumeric == QLatin1String("-INF"))
+ return isDouble ? CommonValues::NegativeInfDouble : CommonValues::NegativeInfFloat;
+ else if(strNumeric == QLatin1String("INF"))
+ return isDouble ? CommonValues::InfDouble : CommonValues::InfFloat;
+
+ /* QString::toDouble() supports any case as well as +INF, but we don't. */
+ const QString toUpper(strNumeric.toUpper());
+ if(toUpper == QLatin1String("-INF") ||
+ toUpper == QLatin1String("INF") ||
+ toUpper == QLatin1String("+INF") ||
+ toUpper == QLatin1String("NAN"))
+ {
+ return ValidationError::createError();
+ }
+
+ bool conversionOk = false;
+ const xsDouble num = strNumeric.toDouble(&conversionOk);
+
+ if(conversionOk)
+ return AtomicValue::Ptr(new AbstractFloat<isDouble>(num));
+ else
+ return ValidationError::createError();
+}
+
+template <const bool isDouble>
+int AbstractFloat<isDouble>::internalSignbit(const xsDouble num)
+{
+ Q_ASSERT_X(sizeof(xsDouble) == 8 || sizeof(xsDouble) == 4, Q_FUNC_INFO,
+ "This implementation of signbit assumes xsDouble, that is qreal, is 64 bits large.");
+
+ union
+ {
+ xsDouble asDouble;
+ qint64 asInt;
+ } value;
+
+ value.asDouble = num;
+
+ /* The highest bit, the 64'th for those who have 64bit floats, is the sign bit. So we pull it down until that bit is the
+ * only one left. */
+ if(sizeof(xsDouble) == 8)
+ return value.asInt >> 63;
+ else
+ return value.asInt >> 31;
+}
+
+template <const bool isDouble>
+bool AbstractFloat<isDouble>::isEqual(const xsDouble a, const xsDouble b)
+{
+ if(qIsInf(a))
+ return qIsInf(b) && internalSignbit(a) == internalSignbit(b);
+ else if(qIsInf(b))
+ return qIsInf(a) && internalSignbit(a) == internalSignbit(b);
+ else
+ {
+ /* Preferrably, we would use std::numeric_limits<xsDouble>::espilon(), but
+ * we cannot since we cannot depend on the STL. The small xs:double value below,
+ * was extracted by printing the std::numeric_limits<xsDouble>::epsilon() using
+ * gdb. */
+ return qAbs(a - b) <= 2.2204460492503131e-16 * qAbs(a);
+ }
+}
+
+template <const bool isDouble>
+bool AbstractFloat<isDouble>::isZero() const
+{
+ return AbstractFloat<isDouble>::isEqual(m_value, 0.0);
+}
+
+template <const bool isDouble>
+bool AbstractFloat<isDouble>::evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ if(isZero() || qIsNaN(m_value))
+ return false;
+ else
+ return true;
+}
+
+template <const bool isDouble>
+QString AbstractFloat<isDouble>::stringValue() const
+{
+ if(qIsNaN(m_value))
+ return QLatin1String("NaN");
+ else if(qIsInf(m_value))
+ return internalSignbit(m_value) == 0 ? QLatin1String("INF") : QLatin1String("-INF");
+ /*
+ * If SV has an absolute value that is greater than or equal to 0.000001
+ * (one millionth) and less than 1000000 (one million),
+ * then the value is converted to an xs:decimal and the resulting xs:decimal
+ * is converted to an xs:string according to the rules above.
+ */
+ else if(0.000001 <= qAbs(m_value) && qAbs(m_value) < 1000000.0)
+ return Decimal::toString(toDecimal());
+ /*
+ * If SV has the value positive or negative zero, TV is "0" or "-0" respectively.
+ */
+ else if(isZero())
+ return internalSignbit(m_value) == 0 ? QLatin1String("0") : QLatin1String("-0");
+ else
+ {
+ /*
+ * Besides these special values, the general form of the canonical form for
+ * xs:float and xs:double is a mantissa, which is a xs:decimal, followed by
+ * the letter "E", followed by an exponent which is an xs:integer.
+ */
+ int sign;
+ int decimalPoint;
+ char *result = 0;
+ static_cast<void>(qdtoa(m_value, -1, 0, &decimalPoint, &sign, 0, &result));
+
+ /* If the copy constructor is used instead of QString::operator=(),
+ * it doesn't compile. I have no idea why. */
+ const QString qret(QString::fromLatin1(result));
+
+ /* We use free() instead of delete here, because qlocale.cpp use malloc(). Spotted
+ * by valgrind. */
+ free(result);
+
+ QString valueAsString;
+
+ if(sign)
+ valueAsString += QLatin1Char('-');
+
+ valueAsString += qret.left(1);
+ valueAsString += QLatin1Char('.');
+
+ if(1 == qret.size())
+ valueAsString += QLatin1Char('0');
+ else
+ valueAsString += qret.mid(1);
+
+ valueAsString += QLatin1Char('E');
+ decimalPoint--;
+ valueAsString += QString::number(decimalPoint);
+ return valueAsString;
+ }
+}
+
+template <const bool isDouble>
+xsDouble AbstractFloat<isDouble>::toDouble() const
+{
+ return m_value;
+}
+
+template <const bool isDouble>
+xsInteger AbstractFloat<isDouble>::toInteger() const
+{
+ return static_cast<xsInteger>(m_value);
+}
+
+template <const bool isDouble>
+xsFloat AbstractFloat<isDouble>::toFloat() const
+{
+ /* No cast, since xsFloat and xsDouble are typedef'ed with the same type. */
+ return m_value;
+}
+
+template <const bool isDouble>
+xsDecimal AbstractFloat<isDouble>::toDecimal() const
+{
+ return static_cast<xsDecimal>(m_value);
+}
+
+template <const bool isDouble>
+Numeric::Ptr AbstractFloat<isDouble>::round() const
+{
+ return AbstractFloat<isDouble>::fromValue(static_cast<xsDouble>(roundFloat(m_value)));
+}
+
+template <const bool isDouble>
+Numeric::Ptr AbstractFloat<isDouble>::roundHalfToEven(const xsInteger precision) const
+{
+ if(isNaN() || isInf() || isZero())
+ return Numeric::Ptr(const_cast<AbstractFloat<isDouble> *>(this));
+ else
+ {
+ /* The cast to double helps finding the correct pow() version on irix-cc. */
+ const xsDouble powered = pow(double(10), double(precision));
+ xsDouble val = powered * m_value;
+ bool isHalf = false;
+
+ if(val - 0.5 == ::floor(val))
+ isHalf = true;
+
+ val = m_value * powered + 0.5;
+ val = ::floor(val);
+
+ if(isHalf /*&& isOdd(val) or? TODO */)
+ val -= 1;
+
+ val /= powered;
+
+ return fromValue(val);
+ }
+}
+
+template <const bool isDouble>
+Numeric::Ptr AbstractFloat<isDouble>::floor() const
+{
+ return AbstractFloat<isDouble>::fromValue(static_cast<xsDouble>(::floor(m_value)));
+}
+
+template <const bool isDouble>
+Numeric::Ptr AbstractFloat<isDouble>::ceiling() const
+{
+ return AbstractFloat<isDouble>::fromValue(static_cast<xsDouble>(ceil(m_value)));
+}
+
+template <const bool isDouble>
+Numeric::Ptr AbstractFloat<isDouble>::abs() const
+{
+ /* We must use fabs() instead of qAbs() because qAbs()
+ * doesn't return 0 for -0.0. */
+ return AbstractFloat<isDouble>::fromValue(static_cast<xsDouble>(fabs(m_value)));
+}
+
+template <const bool isDouble>
+bool AbstractFloat<isDouble>::isNaN() const
+{
+ return qIsNaN(m_value);
+}
+
+template <const bool isDouble>
+bool AbstractFloat<isDouble>::isInf() const
+{
+ return qIsInf(m_value);
+}
+
+template <const bool isDouble>
+ItemType::Ptr AbstractFloat<isDouble>::type() const
+{
+ return isDouble ? BuiltinTypes::xsDouble : BuiltinTypes::xsFloat;
+}
+
+template <const bool isDouble>
+Item AbstractFloat<isDouble>::toNegated() const
+{
+ return fromValue(-m_value).data();
+}
+
+template <const bool isDouble>
+bool AbstractFloat<isDouble>::isSigned() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function, see Numeric::isSigned().");
+ return false;
+}
+
+template <const bool isDouble>
+qulonglong AbstractFloat<isDouble>::toUnsignedInteger() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function, see Numeric::toUnsignedInteger().");
+ return 0;
+}
+
diff --git a/src/xmlpatterns/data/qabstractfloat_p.h b/src/xmlpatterns/data/qabstractfloat_p.h
new file mode 100644
index 0000000..61ec9c1
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractfloat_p.h
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AbstractFloat_H
+#define Patternist_AbstractFloat_H
+
+#include <math.h>
+
+#include <qnumeric.h>
+
+#include "qcommonvalues_p.h"
+#include "qdecimal_p.h"
+#include "qschemanumeric_p.h"
+#include "qvalidationerror_p.h"
+#include "qbuiltintypes_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Base template class for Float and Double classes.
+ *
+ * @author Vincent Ricard <magic@magicninja.org>
+ * @ingroup Patternist_xdm
+ */
+ template <const bool isDouble>
+ class AbstractFloat : public Numeric
+ {
+ public:
+ static Numeric::Ptr fromValue(const xsDouble num);
+ static AtomicValue::Ptr fromLexical(const QString &strNumeric);
+
+ /**
+ * @todo more extensive docs.
+ *
+ * Performs floating point comparison.
+ *
+ * @returns @c true if @p a and @p are equal, otherwise @c false.
+ */
+ static bool isEqual(const xsDouble a, const xsDouble b);
+
+ /**
+ * Determines the Effective %Boolean Value of this number.
+ *
+ * @returns @c false if the number is 0 or @c NaN, otherwise @c true.
+ */
+ bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const;
+
+ /**
+ * Returns this AbstractFloat represented as an @c xs:string.
+ *
+ * @note In the XPath/XQuery languages, converting @c xs:double and @c xs:float
+ * to @c xs:string is not specified in XML Schema 1.0 Part 2: Datatypes Second Edition,
+ * but in XQuery 1.0 and XPath 2.0 Functions and Operators. This will change with W3C XML
+ * Schema 1.1
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#casting-to-string">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 17.1.2 Casting to xs:string and xdt:untypedAtomic</a>
+ */
+ virtual QString stringValue() const;
+
+ virtual xsDouble toDouble() const;
+ virtual xsInteger toInteger() const;
+ virtual xsFloat toFloat() const;
+ virtual xsDecimal toDecimal() const;
+
+ virtual Numeric::Ptr round() const;
+ virtual Numeric::Ptr roundHalfToEven(const xsInteger scale) const;
+ virtual Numeric::Ptr floor() const;
+ virtual Numeric::Ptr ceiling() const;
+ virtual Numeric::Ptr abs() const;
+
+ virtual bool isNaN() const;
+ virtual bool isInf() const;
+
+ virtual ItemType::Ptr type() const;
+ virtual Item toNegated() const;
+ virtual qulonglong toUnsignedInteger() const;
+
+ virtual bool isSigned() const;
+ protected:
+ AbstractFloat(const xsDouble num);
+
+ private:
+ /**
+ * From the Open Group's man page: "The signbit() macro shall return a
+ * non-zero value if and only if the sign of its argument value is
+ * negative."
+ *
+ * MS Windows doesn't have std::signbit() so here's
+ * a reinvention of that function.
+ */
+ static inline int internalSignbit(const xsDouble v);
+ inline bool isZero() const;
+
+ const xsDouble m_value;
+ };
+
+ template <const bool isDouble>
+ Numeric::Ptr createFloat(const xsDouble num);
+
+#include "qabstractfloat.cpp"
+
+ /**
+ * @short An instantiation of AbsbstractFloat suitable for @c xs:double.
+ *
+ * @ingroup Patternist_xdm
+ */
+ typedef AbstractFloat<true> Double;
+
+ /**
+ * @short An instantiation of AbstractFloat suitable for @c xs:float.
+ *
+ * @ingroup Patternist_xdm
+ */
+ typedef AbstractFloat<false> Float;
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qabstractfloatcasters.cpp b/src/xmlpatterns/data/qabstractfloatcasters.cpp
new file mode 100644
index 0000000..bf53fa4
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractfloatcasters.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * NOTE: This file is included by qabstractfloatcasters_p.h
+ * if you need some includes, put them in qabstractfloatcasters_p.h (outside of the namespace)
+ */
+
+template <const bool isDouble>
+Item NumericToAbstractFloatCaster<isDouble>::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ // toDouble() returns same thing than toFloat()
+ return toItem(AbstractFloat<isDouble>::fromValue(from.template as<Numeric>()->toDouble()));
+}
+
+template <const bool isDouble>
+Item StringToAbstractFloatCaster<isDouble>::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return toItem(AbstractFloat<isDouble>::fromLexical(from.stringValue()));
+}
+
+template <const bool isDouble>
+Item BooleanToAbstractFloatCaster<isDouble>::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ if(from.template as<AtomicValue>()->evaluateEBV(context))
+ return isDouble ? toItem(CommonValues::DoubleOne) : toItem(CommonValues::FloatOne);
+ else
+ return isDouble ? toItem(CommonValues::DoubleZero) : toItem(CommonValues::FloatZero);
+}
+
diff --git a/src/xmlpatterns/data/qabstractfloatcasters_p.h b/src/xmlpatterns/data/qabstractfloatcasters_p.h
new file mode 100644
index 0000000..36a5116
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractfloatcasters_p.h
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AbstractFloatCasters_H
+#define Patternist_AbstractFloatCasters_H
+
+#include "qabstractfloat_p.h"
+#include "qatomiccaster_p.h"
+#include "qschemanumeric_p.h"
+
+/**
+ * @file
+ * @short Contains classes sub-classing AtomicCaster and which
+ * are responsible of casting an atomic value to AbstractFloat.
+ */
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+
+ /**
+ * @short Casts a @c numeric value, such as @c xs:integer or @c xs:float, to @c xs:double or xs:float.
+ *
+ * castFrom() uses Numeric::toDouble() for doing the actual casting.
+ *
+ * @ingroup Patternist_xdm
+ * @author Vincent Ricard <magic@magicninja.org>
+ */
+ template <const bool isDouble>
+ class NumericToAbstractFloatCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a string value, @c xs:string or @c xs:untypedAtomic, to @c xs:double or xs:float.
+ *
+ * @ingroup Patternist_xdm
+ * @author Vincent Ricard <magic@magicninja.org>
+ */
+ template <const bool isDouble>
+ class StringToAbstractFloatCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a value of type @c xs:boolean to @c xs:double or xs:float.
+ *
+ * @ingroup Patternist_xdm
+ * @author Vincent Ricard <magic@magicninja.org>
+ */
+ template <const bool isDouble>
+ class BooleanToAbstractFloatCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+#include "qabstractfloatcasters.cpp"
+
+ /**
+ * @short Casts a @c numeric value, such as @c xs:integer or @c xs:float, to @c xs:double.
+ *
+ * castFrom() uses Numeric::toDouble() for doing the actual casting.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ typedef NumericToAbstractFloatCaster<true> NumericToDoubleCaster;
+
+ /**
+ * @short Casts a @c numeric value, such as @c xs:double or @c xs:decimal, to @c xs:float.
+ *
+ * castFrom() uses Numeric::toFloat() for doing the actual casting.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ typedef NumericToAbstractFloatCaster<false> NumericToFloatCaster;
+
+ /**
+ * @short Casts a string value, @c xs:string or @c xs:untypedAtomic, to @c xs:double.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ typedef StringToAbstractFloatCaster<true> StringToDoubleCaster;
+
+ /**
+ * @short Casts a string value, @c xs:string or @c xs:untypedAtomic, to @c xs:float.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ typedef StringToAbstractFloatCaster<false> StringToFloatCaster;
+
+ /**
+ * @short Casts a value of type @c xs:boolean to @c xs:double.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ typedef BooleanToAbstractFloatCaster<true> BooleanToDoubleCaster;
+
+ /**
+ * @short Casts a value of type @c xs:boolean to @c xs:float.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ typedef BooleanToAbstractFloatCaster<false> BooleanToFloatCaster;
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qabstractfloatmathematician.cpp b/src/xmlpatterns/data/qabstractfloatmathematician.cpp
new file mode 100644
index 0000000..767fa47
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractfloatmathematician.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * @file
+ * @short This file is included by qatomicmathematicians_p.h
+ * if you need some includes, put them in qabstractfloatmathematician_p.h, outside of the namespace.
+ */
+
+template <const bool isDouble>
+Item AbstractFloatMathematician<isDouble>::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ const Numeric *const num1 = o1.template as<Numeric>();
+ const Numeric *const num2 = o2.template as<Numeric>();
+ switch(op)
+ {
+ case Div:
+ return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() / num2->toDouble()));
+ case IDiv:
+ {
+ if(num1->isNaN() || num2->isNaN())
+ {
+ context->error(QtXmlPatterns::tr("No operand in an integer division, %1, can be %2.")
+ .arg(formatKeyword("idiv"))
+ .arg(formatData("NaN")),
+ ReportContext::FOAR0002, this);
+ }
+ else if(num1->isInf())
+ {
+ context->error(QtXmlPatterns::tr("The first operand in an integer division, %1, cannot be infinity (%2).")
+ .arg(formatKeyword("idiv"))
+ .arg(formatData("INF")),
+ ReportContext::FOAR0002, this);
+ }
+ else if(num2->toInteger() == 0)
+ context->error(QtXmlPatterns::tr("The second operand in a division, %1, cannot be zero (%2).")
+ .arg(formatKeyword("idiv"))
+ .arg(formatData("0")),
+ ReportContext::FOAR0001, this);
+
+ return Integer::fromValue(static_cast<xsInteger>(num1->toDouble() / num2->toDouble()));
+ }
+ case Substract:
+ return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() - num2->toDouble()));
+ case Mod:
+ return toItem(AbstractFloat<isDouble>::fromValue(::fmod(num1->toDouble(), num2->toDouble())));
+ case Multiply:
+ return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() * num2->toDouble()));
+ case Add:
+ return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() + num2->toDouble()));
+ }
+
+ Q_ASSERT(false);
+ return Item(); /* GCC unbarfer. */
+}
+
diff --git a/src/xmlpatterns/data/qabstractfloatmathematician_p.h b/src/xmlpatterns/data/qabstractfloatmathematician_p.h
new file mode 100644
index 0000000..eb9eb11
--- /dev/null
+++ b/src/xmlpatterns/data/qabstractfloatmathematician_p.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AbstractFloatMathematician_H
+#define Patternist_AbstractFloatMathematician_H
+
+#include "qabstractfloat_p.h"
+#include "qatomicmathematician_p.h"
+#include "qinteger_p.h"
+#include "qschemanumeric_p.h"
+#include "qpatternistlocale_p.h"
+#include "qsourcelocationreflection_p.h"
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Performs arithmetics between AbstractFloat values (Float and Double classes).
+ *
+ * @ingroup Patternist_xdm
+ * @author Vincent Ricard <magic@magicninja.org>
+ */
+ template <const bool isDouble>
+ class AbstractFloatMathematician : public AtomicMathematician
+ , public DelegatingSourceLocationReflection
+ {
+ public:
+ inline AbstractFloatMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
+ {
+ }
+
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+#include "qabstractfloatmathematician.cpp"
+
+ /**
+ * An instantiation of AbstractFloatMathematician that handles @c xs:double.
+ */
+ typedef AbstractFloatMathematician<true> DoubleMathematician;
+
+ /**
+ * An instantiation of AbstractFloatMathematician that handles @c xs:float.
+ */
+ typedef AbstractFloatMathematician<false> FloatMathematician;
+}
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qanyuri.cpp b/src/xmlpatterns/data/qanyuri.cpp
new file mode 100644
index 0000000..0c6288b
--- /dev/null
+++ b/src/xmlpatterns/data/qanyuri.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdynamiccontext_p.h"
+#include "qvalidationerror_p.h"
+#include "qitem_p.h"
+
+#include "qanyuri_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AnyURI::AnyURI(const QString &s) : AtomicString(s)
+{
+}
+
+AnyURI::Ptr AnyURI::fromValue(const QString &value)
+{
+ return AnyURI::Ptr(new AnyURI(value));
+}
+
+AnyURI::Ptr AnyURI::fromValue(const QUrl &uri)
+{
+ return AnyURI::Ptr(new AnyURI(uri.toString()));
+}
+
+AnyURI::Ptr AnyURI::resolveURI(const QString &relative,
+ const QString &base)
+{
+ const QUrl urlBase(base);
+ return AnyURI::fromValue(urlBase.resolved(relative).toString());
+}
+
+ItemType::Ptr AnyURI::type() const
+{
+ return BuiltinTypes::xsAnyURI;
+}
+
+AnyURI::Ptr AnyURI::fromLexical(const QString &value)
+{
+ bool isValid;
+ /* The error code doesn't matter, because we never raise error. */
+ const QUrl retval(toQUrl<ReportContext::FORG0001>(value,
+ DynamicContext::Ptr(),
+ 0,
+ &isValid,
+ false));
+ if(isValid)
+ return fromValue(retval);
+ else
+ return ValidationError::createError();
+}
+
+bool AnyURI::isValid(const QString &candidate)
+{
+ bool isOk = false;
+ /* The error code doesn't matter, because we never raise error. */
+ toQUrl<ReportContext::FORG0001>(candidate,
+ ReportContext::Ptr(),
+ 0,
+ &isOk,
+ false);
+ return isOk;
+}
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qanyuri_p.h b/src/xmlpatterns/data/qanyuri_p.h
new file mode 100644
index 0000000..3272635
--- /dev/null
+++ b/src/xmlpatterns/data/qanyuri_p.h
@@ -0,0 +1,212 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AnyURI_H
+#define Patternist_AnyURI_H
+
+#include <QUrl>
+#include <QtDebug>
+
+#include "qatomicstring_p.h"
+#include "qbuiltintypes_p.h"
+#include "qpatternistlocale_p.h"
+#include "qreportcontext_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short A value of type <tt>xs:anyURI</tt>.
+ *
+ * Due to bugs in QUrl and slight differences in behavior and
+ * interpretation, QUrl can never be used directly for dealing with URIs,
+ * values of type @c xs:anyURI. Therefore, it's important to use the
+ * functionality this class provides, such as the functions toQUrl(),
+ * fromLexical(), isValid(), and resolveURI().
+ *
+ * @see QUrl
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class AnyURI : public AtomicString
+ {
+ public:
+ typedef QExplicitlySharedDataPointer<AnyURI> Ptr;
+
+ /**
+ * Creates an instance representing @p value.
+ *
+ * @note @p value must be a valid @c xs:anyURI. If it is of interest
+ * to construct from a lexical representation, use fromLexical().
+ */
+ static AnyURI::Ptr fromValue(const QString &value);
+
+ static AnyURI::Ptr fromValue(const QUrl &uri);
+
+ /**
+ * @short Treates @p value as a lexical representation of @c xs:anyURI
+ * but returns the value instance as a QUrl.
+ *
+ * If @p value is not a valid lexical representation of @c xs:anyURI,
+ * an error is issued via @p context.
+ *
+ * If @p isValid is passed, no error is raised and it is instead set
+ * appropriately.
+ */
+ template<const ReportContext::ErrorCode code, typename TReportContext>
+ static inline QUrl toQUrl(const QString &value,
+ const TReportContext &context,
+ const SourceLocationReflection *const r,
+ bool *const isValid = 0,
+ const bool issueError = true)
+ {
+ /* QUrl doesn't flag ":/..." so we workaround it. */
+ const QString simplified(value.simplified());
+ const QUrl uri(simplified, QUrl::StrictMode);
+
+ if(uri.isEmpty() || (uri.isValid() && (!simplified.startsWith(QLatin1Char(':')) || !uri.isRelative())))
+ {
+ if(isValid)
+ *isValid = true;
+
+ return uri;
+ }
+ else
+ {
+ if(isValid)
+ *isValid = false;
+
+ if(issueError)
+ {
+ context->error(QtXmlPatterns::tr("%1 is not a valid value of type %2.").arg(formatURI(value), formatType(context->namePool(), BuiltinTypes::xsAnyURI)),
+ code, r);
+ }
+
+ return QUrl();
+ }
+ }
+
+ /**
+ * @short Return @c true if @p candidate is a valid @c xs:anyURI,
+ * otherwise @c false.
+ */
+ static bool isValid(const QString &candidate);
+
+ /**
+ * @short Constructs a @c xs:anyURI value from the lexical representation @p value.
+ *
+ * If @p value is not a valid lexical representation of @c xs:anyURI,
+ * an error is issued via @p context.
+ */
+ template<const ReportContext::ErrorCode code, typename TReportContext>
+ static inline AnyURI::Ptr fromLexical(const QString &value,
+ const TReportContext &context,
+ const SourceLocationReflection *const r)
+ {
+ return AnyURI::Ptr(new AnyURI(toQUrl<code>(value, context, r).toString()));
+ }
+
+ /**
+ * If @p value is not a valid lexical representation for @c xs:anyURI,
+ * a ValidationError is returned.
+ */
+ static AnyURI::Ptr fromLexical(const QString &value);
+
+ /**
+ * Creates an AnyURI instance representing an absolute URI which
+ * is created from resolving @p relative against @p base.
+ *
+ * This function must be compatible with the resolution semantics
+ * specified for fn:resolve-uri. In fact, the implementation of fn:resolve-uri,
+ * ResourceURIFN, relies on this function.
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3986.html">RFC 3986 - Uniform
+ * Resource Identifier (URI): Generic Syntax</a>
+ * @see <a href ="http://www.w3.org/TR/xpath-functions/#func-resolve-uri">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 8.1 fn:resolve-uri</a>
+ */
+ static AnyURI::Ptr resolveURI(const QString &relative,
+ const QString &base);
+
+ virtual ItemType::Ptr type() const;
+
+ /**
+ * @short Returns this @c xs:anyURI value in a QUrl.
+ */
+ inline QUrl toQUrl() const
+ {
+ Q_ASSERT_X(QUrl(m_value).isValid(), Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1("%1 is apparently not ok for QUrl.").arg(m_value)));
+ return QUrl(m_value);
+ }
+ protected:
+ friend class CommonValues;
+
+ AnyURI(const QString &value);
+ };
+
+ /**
+ * @short Formats @p uri, that's considered to be a URI, for display.
+ */
+ static inline QString formatURI(const NamePool::Ptr &np, const QXmlName::NamespaceCode &uri)
+ {
+ return formatURI(np->stringForNamespace(uri));
+ }
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomiccaster.cpp b/src/xmlpatterns/data/qatomiccaster.cpp
new file mode 100644
index 0000000..a087725
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccaster.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qatomiccaster_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AtomicCaster::AtomicCaster()
+{
+}
+
+AtomicCaster::~AtomicCaster()
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomiccaster_p.h b/src/xmlpatterns/data/qatomiccaster_p.h
new file mode 100644
index 0000000..6680dc5
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccaster_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AtomicCaster_H
+#define Patternist_AtomicCaster_H
+
+#include "qdynamiccontext_p.h"
+#include "qitem_p.h"
+#include "qatomictypedispatch_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short AtomicCaster is an abstract base class for classes
+ * that performs casting between two atomic values of specific types.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AtomicCaster : public AtomicTypeVisitorResult
+ {
+ public:
+ typedef QExplicitlySharedDataPointer<AtomicCaster> Ptr;
+ AtomicCaster();
+ virtual ~AtomicCaster();
+
+ /**
+ * Casts @p from to an atomic value of the type this class
+ * casts to, and returns that value. The @p context is used
+ * for reporting errors in case the casting fails, and to in general
+ * access information from the dynamic context.
+ */
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const = 0;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomiccasters.cpp b/src/xmlpatterns/data/qatomiccasters.cpp
new file mode 100644
index 0000000..893dce4
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccasters.cpp
@@ -0,0 +1,336 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qnumeric.h>
+
+#include "qabstractfloat_p.h"
+#include "qanyuri_p.h"
+#include "qbase64binary_p.h"
+#include "qboolean_p.h"
+#include "qcommonvalues_p.h"
+#include "qdate_p.h"
+#include "qschemadatetime_p.h"
+#include "qdaytimeduration_p.h"
+#include "qdecimal_p.h"
+#include "qduration_p.h"
+#include "qgday_p.h"
+#include "qgmonth_p.h"
+#include "qgmonthday_p.h"
+#include "qgyear_p.h"
+#include "qgyearmonth_p.h"
+#include "qhexbinary_p.h"
+#include "qinteger_p.h"
+#include "qatomicstring_p.h"
+#include "qschematime_p.h"
+#include "quntypedatomic_p.h"
+#include "qyearmonthduration_p.h"
+
+#include "qatomiccasters_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Item ToUntypedAtomicCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return UntypedAtomic::fromValue(from.stringValue());
+}
+
+Item ToAnyURICaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return toItem(AnyURI::fromLexical(from.stringValue()));
+}
+
+Item Base64BinaryToHexBinaryCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return HexBinary::fromValue(from.as<Base64Binary>()->asByteArray());
+}
+
+Item StringToHexBinaryCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ return HexBinary::fromLexical(context->namePool(), from.stringValue());
+}
+
+Item HexBinaryToBase64BinaryCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Base64Binary::fromValue(from.as<Base64Binary>()->asByteArray());
+}
+
+Item StringToBase64BinaryCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Base64Binary::fromLexical(from.stringValue());
+}
+
+Item NumericToBooleanCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ const xsDouble val = from.as<Numeric>()->toDouble();
+ if(Double::isEqual(val, 0.0) || qIsNaN(val))
+ return CommonValues::BooleanFalse;
+ else
+ return CommonValues::BooleanTrue;
+}
+
+Item StringToBooleanCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Boolean::fromLexical(from.stringValue());
+}
+
+Item StringToDecimalCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Decimal::fromLexical(from.stringValue());
+}
+
+Item StringToIntegerCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Integer::fromLexical(from.stringValue());
+}
+
+Item BooleanToDecimalCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ if(from.as<AtomicValue>()->evaluateEBV(context))
+ return CommonValues::DecimalOne;
+ else
+ return CommonValues::DecimalZero;
+}
+
+Item BooleanToIntegerCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ if(from.as<AtomicValue>()->evaluateEBV(context))
+ return CommonValues::IntegerOne;
+ else
+ return CommonValues::IntegerZero;
+}
+
+Item SelfToSelfCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return from;
+}
+
+Item StringToGYearCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return GYear::fromLexical(from.stringValue());
+}
+
+Item StringToGDayCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return GDay::fromLexical(from.stringValue());
+}
+
+Item StringToGMonthCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return GMonth::fromLexical(from.stringValue());
+}
+
+Item StringToGYearMonthCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return GYearMonth::fromLexical(from.stringValue());
+}
+
+Item StringToGMonthDayCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return GMonthDay::fromLexical(from.stringValue());
+}
+
+Item StringToDateTimeCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return DateTime::fromLexical(from.stringValue());
+}
+
+Item StringToTimeCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return SchemaTime::fromLexical(from.stringValue());
+}
+
+Item StringToDateCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Date::fromLexical(from.stringValue());
+}
+
+Item StringToDurationCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return Duration::fromLexical(from.stringValue());
+}
+
+Item StringToDayTimeDurationCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return toItem(DayTimeDuration::fromLexical(from.stringValue()));
+}
+
+Item AbstractDurationToDayTimeDurationCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ const AbstractDuration *const val = from.as<AbstractDuration>();
+
+ return toItem(DayTimeDuration::fromComponents(val->isPositive(),
+ val->days(),
+ val->hours(),
+ val->minutes(),
+ val->seconds(),
+ val->mseconds()));
+}
+
+Item AbstractDurationToYearMonthDurationCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ const AbstractDuration *const val = from.as<AbstractDuration>();
+
+ return toItem(YearMonthDuration::fromComponents(val->isPositive(),
+ val->years(),
+ val->months()));
+}
+
+Item AbstractDurationToDurationCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ const AbstractDuration *const val = from.as<AbstractDuration>();
+
+ return Duration::fromComponents(val->isPositive(),
+ val->years(),
+ val->months(),
+ val->days(),
+ val->hours(),
+ val->minutes(),
+ val->seconds(),
+ val->mseconds());
+}
+
+Item StringToYearMonthDurationCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return YearMonthDuration::fromLexical(from.stringValue());
+}
+
+Item AbstractDateTimeToGYearCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(true);
+
+ return GYear::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToGYearMonthCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(true);
+
+ return GYearMonth::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToGMonthCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(true);
+
+ return GMonth::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToGMonthDayCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(true);
+
+ return GMonthDay::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToGDayCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(true);
+
+ return GDay::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToDateTimeCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(false);
+
+ return DateTime::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToDateCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(true);
+
+ return Date::fromDateTime(dt);
+}
+
+Item AbstractDateTimeToTimeCaster::castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ QDateTime dt(from.as<AbstractDateTime>()->toDateTime());
+ // TODO DT dt.setDateOnly(false);
+
+ return SchemaTime::fromDateTime(dt);
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomiccasters_p.h b/src/xmlpatterns/data/qatomiccasters_p.h
new file mode 100644
index 0000000..888ad32
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccasters_p.h
@@ -0,0 +1,705 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AtomicCasters_H
+#define Patternist_AtomicCasters_H
+
+#include "qatomiccaster_p.h"
+#include "qdecimal_p.h"
+#include "qderivedinteger_p.h"
+#include "qderivedstring_p.h"
+#include "qinteger_p.h"
+#include "qvalidationerror_p.h"
+
+/**
+ * @file
+ * @short Contains classes sub-classing AtomicCaster and which
+ * are responsible of casting an atomic value to another type.
+ */
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+
+ /**
+ * @short Casts any atomic value to @c xs:string.
+ *
+ * This class uses Item::stringValue() for retrieving a string
+ * representation, and thus supports casting from atomic values
+ * of any type.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template<TypeOfDerivedString DerivedType>
+ class ToStringCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+ {
+ Q_ASSERT(from);
+ return DerivedString<DerivedType>::fromLexical(context->namePool(), from.stringValue());
+ }
+ };
+
+ /**
+ * @short Casts any atomic value to @c xs:untypedAtomic.
+ *
+ * This class uses Item::stringValue() for retrieving a string
+ * representation, and thus supports casting from atomic values
+ * of any type. The implementation is similar to ToStringCaster.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class ToUntypedAtomicCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a string value to @c xs:anyURI.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class ToAnyURICaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:hexBinary atomic value to @c xs:base64Binary.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class HexBinaryToBase64BinaryCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:base64Binary atomic value to @c xs:hexBinary.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Base64BinaryToHexBinaryCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:base64Binary.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToBase64BinaryCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:hexBinary.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToHexBinaryCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts any @c numeric value to @c xs:boolean.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class NumericToBooleanCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts any string value, @c xs:string or @c xs:untypedAtomic, to @c xs:boolean.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToBooleanCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c numeric value, such as @c xs:double or @c xs:decimal, to @c xs:integer or
+ * @c xs:decimal, depending on IsInteger.
+ *
+ * castFrom() uses Numeric::toInteger() for doing the actual casting.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template <const bool IsInteger>
+ class NumericToDecimalCaster : public AtomicCaster
+ {
+ public:
+ /**
+ * Used by NumericToDerivedIntegerCaster in addition to this class.
+ */
+ static inline QString errorMessage()
+ {
+ return QtXmlPatterns::tr("When casting to %1 from %2, the source value cannot be %3.");
+ }
+
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+ {
+ const ItemType::Ptr t(from.type());
+ const Numeric *const num = from.template as<Numeric>();
+
+ if(BuiltinTypes::xsDouble->xdtTypeMatches(t) || BuiltinTypes::xsFloat->xdtTypeMatches(t))
+ {
+ if(num->isInf() || num->isNaN())
+ {
+ return ValidationError::createError(errorMessage()
+ .arg(formatType(context->namePool(), IsInteger ? BuiltinTypes::xsInteger : BuiltinTypes::xsDecimal))
+ .arg(formatType(context->namePool(), t))
+ .arg(formatData(num->stringValue())),
+ ReportContext::FOCA0002);
+ }
+ }
+
+ if(IsInteger)
+ return Integer::fromValue(num->toInteger());
+ else
+ return toItem(Decimal::fromValue(num->toDecimal()));
+ }
+ };
+
+ /**
+ * @short Casts a string value, @c xs:string or @c xs:untypedAtomic, to @c xs:decimal.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToDecimalCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a string value, @c xs:string or @c xs:untypedAtomic, to @c xs:integer.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToIntegerCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a value of type @c xs:boolean to @c xs:decimal.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class BooleanToDecimalCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a value of type @c xs:boolean to @c xs:integer.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class BooleanToIntegerCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a value to itself. Essentially, this AtomicCaster does nothing.
+ *
+ * Casting a value to the type of itself is defined to be a noop,
+ * no operation. When it can be statically detected that will be done,
+ * CastAs rewrites itself appropriately during compilation, but
+ * in some cases insufficent data is available at compile time and then
+ * is this class need on a case-per-case base at evaluation time.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class SelfToSelfCaster : public AtomicCaster
+ {
+ public:
+
+ /**
+ * This function simply returns @p from.
+ */
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:gYear.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToGYearCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:gDay.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToGDayCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:gMonth.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToGMonthCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:gYearMonth.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToGYearMonthCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:gYearMonth.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToGMonthDayCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:dateTime.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToDateTimeCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:time.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToTimeCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:date.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToDateCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:duration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToDurationCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:dayTimeDuration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToDayTimeDurationCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:string or @c xs:untypedAtomic atomic value to @c xs:yearMonthDuration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringToYearMonthDurationCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+
+ /**
+ * @short Casts a @c xs:date or @c xs:dateTime atomic value to @c xs:gYear.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToGYearCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:date or @c xs:dateTime atomic value to @c xs:gYearMonth.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToGYearMonthCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:date or @c xs:dateTime atomic value to @c xs:gMonth.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToGMonthCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:date or @c xs:dateTime atomic value to @c xs:gMonthDay.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToGMonthDayCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts a @c xs:date or @c xs:dateTime atomic value to @c xs:gDay.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToGDayCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an AbstractDateTime instance to DateTime.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToDateTimeCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an AbstractDateTime instance to SchemaTime.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToDateCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an AbstractDateTime instance to SchemaTime.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeToTimeCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an AbstractDuration instance to Duration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDurationToDurationCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an AbstractDuration instance to DayTimeDuration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDurationToDayTimeDurationCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an AbstractDuration instance to YearMonthDuration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDurationToYearMonthDurationCaster : public AtomicCaster
+ {
+ public:
+ virtual Item castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Casts an @c xs:string instance to a derived type of @c xs:integer.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template<TypeOfDerivedInteger type>
+ class StringToDerivedIntegerCaster : public AtomicCaster
+ {
+ public:
+ virtual Item
+ castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+ {
+ return DerivedInteger<type>::fromLexical(context->namePool(), from.stringValue());
+ }
+ };
+
+ /**
+ * @short Casts an @c xs:boolean instance to a derived type of @c xs:integer.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template<TypeOfDerivedInteger type>
+ class BooleanToDerivedIntegerCaster : public AtomicCaster
+ {
+ public:
+ virtual Item
+ castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+ {
+ return DerivedInteger<type>::fromValue(context->namePool(), from.template as<AtomicValue>()->evaluateEBV(context) ? 1 : 0);
+ }
+ };
+
+ /**
+ * @short Casts an @c xs:boolean instance to a derived type of @c xs:integer.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template<TypeOfDerivedString type>
+ class AnyToDerivedStringCaster : public AtomicCaster
+ {
+ public:
+ virtual Item
+ castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+ {
+ return DerivedString<type>::fromLexical(context->namePool(), from.stringValue());
+ }
+ };
+
+ /**
+ * @short Casts any @c numeric instance to a derived type of @c xs:integer.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template<TypeOfDerivedInteger type>
+ class NumericToDerivedIntegerCaster : public AtomicCaster
+ {
+ public:
+ virtual Item
+ castFrom(const Item &from,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+ {
+ const ItemType::Ptr t(from.type());
+ const Numeric *const num = from.template as<Numeric>();
+
+ if(BuiltinTypes::xsDouble->xdtTypeMatches(t) || BuiltinTypes::xsFloat->xdtTypeMatches(t))
+ {
+ if(num->isInf() || num->isNaN())
+ {
+ return ValidationError::createError(NumericToDecimalCaster<false>::errorMessage()
+ .arg(formatType(context->namePool(), DerivedInteger<type>::itemType()))
+ .arg(formatType(context->namePool(), t))
+ .arg(formatData(num->stringValue())),
+ ReportContext::FOCA0002);
+ }
+ }
+
+ return toItem(DerivedInteger<type>::fromValue(context->namePool(), from.template as<Numeric>()->toInteger()));
+ }
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomiccomparator.cpp b/src/xmlpatterns/data/qatomiccomparator.cpp
new file mode 100644
index 0000000..34395fa
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccomparator.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QString>
+
+#include "qatomiccomparator_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AtomicComparator::AtomicComparator()
+{
+}
+
+AtomicComparator::~AtomicComparator()
+{
+}
+
+AtomicComparator::ComparisonResult
+AtomicComparator::compare(const Item &,
+ const AtomicComparator::Operator,
+ const Item &) const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO, "This function should never be called.");
+ return LessThan;
+}
+
+QString AtomicComparator::displayName(const AtomicComparator::Operator op,
+ const ComparisonType type)
+{
+ Q_ASSERT(type == AsGeneralComparison || type == AsValueComparison);
+ if(type == AsGeneralComparison)
+ {
+ switch(op)
+ {
+ case OperatorEqual:
+ return QLatin1String("=");
+ case OperatorGreaterOrEqual:
+ return QLatin1String("<=");
+ case OperatorGreaterThan:
+ return QLatin1String("<");
+ case OperatorLessOrEqual:
+ return QLatin1String(">=");
+ case OperatorLessThanNaNLeast:
+ /* Fallthrough. */
+ case OperatorLessThanNaNGreatest:
+ /* Fallthrough. */
+ case OperatorLessThan:
+ return QLatin1String(">");
+ case OperatorNotEqual:
+ return QLatin1String("!=");
+ }
+ }
+
+ switch(op)
+ {
+ case OperatorEqual:
+ return QLatin1String("eq");
+ case OperatorGreaterOrEqual:
+ return QLatin1String("ge");
+ case OperatorGreaterThan:
+ return QLatin1String("gt");
+ case OperatorLessOrEqual:
+ return QLatin1String("le");
+ case OperatorLessThanNaNLeast:
+ /* Fallthrough. */
+ case OperatorLessThanNaNGreatest:
+ /* Fallthrough. */
+ case OperatorLessThan:
+ return QLatin1String("lt");
+ case OperatorNotEqual:
+ return QLatin1String("ne");
+ }
+
+ Q_ASSERT(false);
+ return QString(); /* GCC unbarfer. */
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomiccomparator_p.h b/src/xmlpatterns/data/qatomiccomparator_p.h
new file mode 100644
index 0000000..2ec7815
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccomparator_p.h
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AtomicComparator_H
+#define Patternist_AtomicComparator_H
+
+#include <QFlags>
+
+#include "qitem_p.h"
+#include "qatomictypedispatch_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QString;
+
+namespace QPatternist
+{
+
+ /**
+ * @short Base class for classes responsible of comparing two atomic values.
+ *
+ * This class is also known as the AtomicParrot.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_AUTOTEST_EXPORT AtomicComparator : public AtomicTypeVisitorResult
+ {
+ public:
+ AtomicComparator();
+ virtual ~AtomicComparator();
+
+ typedef QExplicitlySharedDataPointer<AtomicComparator> Ptr;
+
+ /**
+ * Identifies operators used in value comparisons.
+ *
+ * The enum values are bit-significant.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath20/#id-value-comparisons">W3C XML Path
+ * Language (XPath) 2.0, 3.5.1 Value Comparisons</a>
+ */
+ enum Operator
+ {
+ /**
+ * Operator <tt>eq</tt> and <tt>=</tt>.
+ */
+ OperatorEqual = 1,
+
+ /**
+ * Operator <tt>ne</tt> and <tt>!=</tt>.
+ */
+ OperatorNotEqual = 1 << 1,
+
+ /**
+ * Operator <tt>gt</tt> and <tt>\></tt>.
+ */
+ OperatorGreaterThan = 1 << 2,
+
+ /**
+ * Operator <tt>lt</tt> and <tt>\<</tt>.
+ */
+ OperatorLessThan = 1 << 3,
+
+ /**
+ * One of the operators we use for sorting. The only difference from
+ * OperatorLessThan is that it sees NaN as ordered and smaller than
+ * other numbers.
+ */
+ OperatorLessThanNaNLeast = 1 << 4,
+
+ /**
+ * One of the operators we use for sorting. The only difference from
+ * OperatorLessThanLeast is that it sees NaN as ordered and larger than
+ * other numbers.
+ */
+ OperatorLessThanNaNGreatest = 1 << 5,
+
+ /**
+ * Operator <tt>ge</tt> and <tt>\>=</tt>.
+ */
+ OperatorGreaterOrEqual = OperatorEqual | OperatorGreaterThan,
+
+ /**
+ * Operator <tt>le</tt> and <tt>\<=</tt>.
+ */
+ OperatorLessOrEqual = OperatorEqual | OperatorLessThan
+ };
+
+ typedef QFlags<Operator> Operators;
+
+ /**
+ * Signifies the result of a value comparison. This is used for value comparisons,
+ * and in the future likely also for sorting.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath20/#id-value-comparisons">W3C XML Path
+ * Language (XPath) 2.0, 3.5.1 Value Comparisons</a>
+ */
+ enum ComparisonResult
+ {
+ LessThan = 1,
+ Equal = 2,
+ GreaterThan = 4,
+ Incomparable = 8
+ };
+
+ /**
+ * Compares @p op1 and @p op2 and determines the relationship between the two. This
+ * is used for sorting and comparisons. The implementation performs an assert crash,
+ * and must therefore be re-implemented if comparing the relevant values should be
+ * possible.
+ *
+ * @param op1 the first operand
+ * @param op the operator. How a comparison is carried out shouldn't depend on what the
+ * operator is, but in some cases it is of interest.
+ * @param op2 the second operand
+ */
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ /**
+ * Determines whether @p op1 and @p op2 are equal. It is the same as calling compare()
+ * and checking whether the return value is Equal, but since comparison testing is such
+ * a common operation, this specialized function exists.
+ *
+ * @returns true if @p op1 and @p op2 are equal.
+ *
+ * @param op1 the first operand
+ * @param op2 the second operand
+ */
+ virtual bool equals(const Item &op1,
+ const Item &op2) const = 0;
+
+ /**
+ * Identifies the kind of comparison.
+ */
+ enum ComparisonType
+ {
+ /**
+ * Identifies a general comparison; operator @c =, @c >, @c <=, and so on.
+ */
+ AsGeneralComparison = 1,
+
+ /**
+ * Identifies a value comparison; operator @c eq, @c lt, @c le, and so on.
+ */
+ AsValueComparison
+ };
+
+ /**
+ * Utility function for getting the lexical representation for
+ * the comparison operator @p op. Depending on the @p type argument,
+ * the string returned is either a general comparison or a value comparison
+ * operator.
+ *
+ * @param op the operator which the display name should be determined for.
+ * @param type signifies whether the returned display name should be for
+ * a value comparison or a general comparison. For example, if @p op is
+ * OperatorEqual and @p type is AsValueComparision, "eq" is returned.
+ */
+ static QString displayName(const AtomicComparator::Operator op,
+ const ComparisonType type);
+
+ };
+ Q_DECLARE_OPERATORS_FOR_FLAGS(AtomicComparator::Operators)
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomiccomparators.cpp b/src/xmlpatterns/data/qatomiccomparators.cpp
new file mode 100644
index 0000000..af28b42
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccomparators.cpp
@@ -0,0 +1,386 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractduration_p.h"
+#include "qabstractdatetime_p.h"
+#include "qbase64binary_p.h"
+#include "qboolean_p.h"
+#include "qdynamiccontext_p.h"
+#include "qqnamevalue_p.h"
+
+#include "qatomiccomparators_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+/* -------------------------------------------------- */
+AtomicComparator::ComparisonResult
+StringComparator::compare(const Item &o1,
+ const AtomicComparator::Operator,
+ const Item &o2) const
+{
+ const int result = QString::compare(o1.stringValue(), o2.stringValue());
+
+ if(result > 0)
+ return GreaterThan;
+ else if(result < 0)
+ return LessThan;
+ else
+ {
+ Q_ASSERT(result == 0);
+ return Equal;
+ }
+}
+
+bool StringComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ return o1.stringValue() == o2.stringValue();
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+AtomicComparator::ComparisonResult
+CaseInsensitiveStringComparator::compare(const Item &o1,
+ const AtomicComparator::Operator,
+ const Item &o2) const
+{
+ const QString i1(o1.stringValue().toLower());
+ const QString i2(o2.stringValue().toLower());
+ const int result = QString::compare(i1, i2);
+
+ if(result > 0)
+ return GreaterThan;
+ else if(result < 0)
+ return LessThan;
+ else
+ {
+ Q_ASSERT(result == 0);
+ return Equal;
+ }
+}
+
+bool CaseInsensitiveStringComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ const QString s1(o1.stringValue());
+ const QString s2(o2.stringValue());
+
+ return s1.length() == s2.length() &&
+ s1.startsWith(s2, Qt::CaseInsensitive);
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+bool BinaryDataComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ return o1.as<Base64Binary>()->asByteArray() ==
+ o2.as<Base64Binary>()->asByteArray();
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+AtomicComparator::ComparisonResult
+BooleanComparator::compare(const Item &o1,
+ const AtomicComparator::Operator,
+ const Item &o2) const
+{
+ /* We know Boolean::evaluateEBV doesn't use the DynamicContext. */
+ const bool v1 = o1.as<AtomicValue>()->evaluateEBV(QExplicitlySharedDataPointer<DynamicContext>());
+ const bool v2 = o2.as<AtomicValue>()->evaluateEBV(QExplicitlySharedDataPointer<DynamicContext>());
+
+ if(v1 == v2)
+ return Equal;
+ else if(v1 == false)
+ {
+ Q_ASSERT(v2 == true);
+ return LessThan;
+ }
+ else
+ {
+ Q_ASSERT(v1 == true && v2 == false);
+ return GreaterThan;
+ }
+}
+
+bool BooleanComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ /* Boolean is an atomic class. */
+ return o1.as<AtomicValue>() == o2.as<AtomicValue>();
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+AtomicComparator::ComparisonResult
+AbstractFloatComparator::compare(const Item &o1,
+ const AtomicComparator::Operator op,
+ const Item &o2) const
+{
+ const xsDouble v1 = o1.as<Numeric>()->toDouble();
+ const xsDouble v2 = o2.as<Numeric>()->toDouble();
+
+ if(Double::isEqual(v1, v2))
+ return Equal;
+ else if(v1 < v2)
+ return LessThan;
+ else if(v1 > v2)
+ return GreaterThan;
+ else
+ {
+ /* We have NaN values. Make sure we don't return a result which would
+ * signify success for the operator in question. */
+ if((op & OperatorGreaterThan) == OperatorGreaterThan)
+ return LessThan;
+ else
+ {
+ Q_ASSERT((op & OperatorLessThan) == OperatorLessThan);
+ return GreaterThan;
+ }
+ }
+}
+
+bool AbstractFloatComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ return Double::isEqual(o1.as<Numeric>()->toDouble(), o2.as<Numeric>()->toDouble());
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+AtomicComparator::ComparisonResult
+DecimalComparator::compare(const Item &o1,
+ const AtomicComparator::Operator,
+ const Item &o2) const
+{
+ const xsDecimal v1 = o1.as<Numeric>()->toDecimal();
+ const xsDecimal v2 = o2.as<Numeric>()->toDecimal();
+
+ if(Double::isEqual(v1, v2))
+ return Equal;
+ else if(v1 < v2)
+ return LessThan;
+ else
+ return GreaterThan;
+}
+
+bool DecimalComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ return Double::isEqual(o1.as<Numeric>()->toDecimal(), o2.as<Numeric>()->toDecimal());
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+AtomicComparator::ComparisonResult
+IntegerComparator::compare(const Item &o1,
+ const AtomicComparator::Operator,
+ const Item &o2) const
+{
+ const Numeric *const num1 = o1.as<Numeric>();
+ const Numeric *const num2 = o1.as<Numeric>();
+
+ /**
+ * Consider:
+ * xs:unsignedLong("100") > xs:unsignedLong("18446744073709551615")
+ *
+ * If we perform math on the values as if they were xsInteger, the right
+ * operand overflows, wraps around, and the expression evaluates to false.
+ * Hence we have this code to deal with it.
+ *
+ * This is runtime code, it would have been better if we had separate
+ * AtomicComparator classes for signed and unsigned values, but the changes
+ * required to the lookup code are extensive.
+ */
+ if(num1->isSigned() || num2->isSigned())
+ {
+ const xsInteger v1 = o1.as<Numeric>()->toInteger();
+ const xsInteger v2 = o2.as<Numeric>()->toInteger();
+
+ if(v1 == v2)
+ return Equal;
+ else if(v1 < v2)
+ return LessThan;
+ else
+ return GreaterThan;
+ }
+ else
+ {
+ const qulonglong v1 = o1.as<Numeric>()->toUnsignedInteger();
+ const qulonglong v2 = o2.as<Numeric>()->toUnsignedInteger();
+
+ if(v1 == v2)
+ return Equal;
+ else if(v1 < v2)
+ return LessThan;
+ else
+ return GreaterThan;
+ }
+}
+
+bool IntegerComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ return o1.as<Numeric>()->toInteger() == o2.as<Numeric>()->toInteger();
+}
+
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+bool QNameComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ return o1.as<QNameValue>()->m_qName ==
+ o2.as<QNameValue>()->m_qName;
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+bool AbstractDateTimeComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ const QDateTime dt1(o1.as<AbstractDateTime>()->toDateTime());
+ const QDateTime dt2(o2.as<AbstractDateTime>()->toDateTime());
+
+ /*
+ pDebug() << "COMPARING:"
+ << o1->as<AbstractDateTime>()->toDateTime().toString()
+ << o2->as<AbstractDateTime>()->toDateTime().toString();
+ pDebug() << "DATE ONLY:"
+ << o1->as<AbstractDateTime>()->toDateTime().isDateOnly()
+ << o2->as<AbstractDateTime>()->toDateTime().isDateOnly();
+ */
+ return dt1 == dt2 &&
+ dt1.timeSpec() == dt2.timeSpec();
+}
+
+AtomicComparator::ComparisonResult
+AbstractDateTimeComparator::compare(const Item &operand1,
+ const AtomicComparator::Operator,
+ const Item &operand2) const
+{
+ const QDateTime &dt1 = operand1.as<AbstractDateTime>()->toDateTime();
+ const QDateTime &dt2 = operand2.as<AbstractDateTime>()->toDateTime();
+
+ if(dt1 == dt2)
+ return Equal;
+ else if(dt1 < dt2)
+ return LessThan;
+ else
+ return GreaterThan;
+}
+/* -------------------------------------------------- */
+
+/* -------------------------------------------------- */
+bool AbstractDurationComparator::equals(const Item &o1,
+ const Item &o2) const
+{
+ /* We use AbstractDuration::operator==() */
+ return *o1.as<AbstractDuration>() ==
+ *o2.as<AbstractDuration>();
+}
+
+QDateTime AbstractDurationComparator::addDurationToDateTime(const QDateTime &dateTime,
+ const AbstractDuration *const duration)
+{
+ QDateTime result(dateTime);
+ qint64 seconds = 0;
+
+ const qint8 signMultiplier = (duration->isPositive() ? 1 : -1);
+
+ result = result.addYears(signMultiplier * duration->years());
+ result = result.addMonths(signMultiplier * duration->months());
+ result = result.addDays(signMultiplier * duration->days());
+
+ seconds = 60 * 60 * duration->hours();
+ seconds += 60 * duration->minutes();
+ seconds += duration->seconds();
+
+ result = result.addSecs(signMultiplier * seconds);
+ result = result.addMSecs(signMultiplier * duration->mseconds());
+
+ return result;
+}
+
+AtomicComparator::ComparisonResult
+AbstractDurationComparator::compare(const Item &o1,
+ const AtomicComparator::Operator,
+ const Item &o2) const
+{
+ const AbstractDuration *const duration = o1.as<AbstractDuration>();
+ const AbstractDuration *const otherDuration = o2.as<AbstractDuration>();
+
+ const QDateTime dateTime1(QDate(1696, 9, 1), QTime(0, 0, 0), Qt::UTC);
+ const QDateTime dateTime2(QDate(1697, 2, 1), QTime(0, 0, 0), Qt::UTC);
+ const QDateTime dateTime3(QDate(1903, 3, 1), QTime(0, 0, 0), Qt::UTC);
+ const QDateTime dateTime4(QDate(1903, 7, 1), QTime(0, 0, 0), Qt::UTC);
+
+ const QDateTime durationDateTime1 = addDurationToDateTime(dateTime1, duration);
+ const QDateTime durationDateTime2 = addDurationToDateTime(dateTime2, duration);
+ const QDateTime durationDateTime3 = addDurationToDateTime(dateTime3, duration);
+ const QDateTime durationDateTime4 = addDurationToDateTime(dateTime4, duration);
+
+ const QDateTime otherDurationDateTime1 = addDurationToDateTime(dateTime1, otherDuration);
+ const QDateTime otherDurationDateTime2 = addDurationToDateTime(dateTime2, otherDuration);
+ const QDateTime otherDurationDateTime3 = addDurationToDateTime(dateTime3, otherDuration);
+ const QDateTime otherDurationDateTime4 = addDurationToDateTime(dateTime4, otherDuration);
+
+ if (durationDateTime1 > otherDurationDateTime1 &&
+ durationDateTime2 > otherDurationDateTime2 &&
+ durationDateTime3 > otherDurationDateTime3 &&
+ durationDateTime4 > otherDurationDateTime4) {
+ return GreaterThan;
+ } else if (durationDateTime1 < otherDurationDateTime1 &&
+ durationDateTime2 < otherDurationDateTime2 &&
+ durationDateTime3 < otherDurationDateTime3 &&
+ durationDateTime4 < otherDurationDateTime4) {
+ return LessThan;
+ } else if (*duration == *otherDuration) {
+ return Equal;
+ } else {
+ return Incomparable;
+ }
+}
+
+/* -------------------------------------------------- */
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomiccomparators_p.h b/src/xmlpatterns/data/qatomiccomparators_p.h
new file mode 100644
index 0000000..82a6068
--- /dev/null
+++ b/src/xmlpatterns/data/qatomiccomparators_p.h
@@ -0,0 +1,298 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AtomicComparators_H
+#define Patternist_AtomicComparators_H
+
+#include "qabstractfloat_p.h"
+#include "qatomiccomparator_p.h"
+#include "qprimitives_p.h"
+
+/**
+ * @file
+ * @short Contains all the classes implementing comparisons between atomic values.
+ */
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Performs case @em sensitive string comparison
+ * between @c xs:anyUri, @c xs:string, and @c xs:untypedAtomic.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class StringComparator : public AtomicComparator
+ {
+ public:
+ /**
+ * Compares two strings, and returns the appropriate AtomicComparator::ComparisonResult enum. This
+ * is a bit simplified version of string comparison as defined in the XPath specifications,
+ * since this does not take any string collations into account(which an implementation neither
+ * is required to do).
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#string-compare">XQuery 1.0 and XPath
+ * 2.0 Functions and Operators, 7.3 ValueComparison::Equality and Comparison of Strings</a>
+ */
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ /**
+ * Compares two strings, and returns @c true if they are considered equal as per
+ * an ordinary string comparison. In other words, this is an implementation with
+ * the Unicode code point collation.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#string-compare">XQuery 1.0 and XPath
+ * 2.0 Functions and Operators, 7.3 ValueComparison::Equality and Comparison of Strings</a>
+ */
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Performs case @em insensitive string comparison
+ * between @c xs:anyUri, @c xs:string, and @c xs:untypedAtomic.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class CaseInsensitiveStringComparator : public AtomicComparator
+ {
+ public:
+ /**
+ * Converts both string values to upper case and afterwards compare them.
+ */
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ /**
+ * Converts both string values case insensitively.
+ */
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares @c xs:base64Binary and @c xs:hexBinary values.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class BinaryDataComparator : public AtomicComparator
+ {
+ public:
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares @c xs:boolean values.
+ *
+ * This is done via the object's Boolean::evaluteEBV() function.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class BooleanComparator : public AtomicComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares @c xs:double values.
+ *
+ * @todo Add docs about numeric promotion
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractFloatComparator : public AtomicComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares @c xs:double values for the purpose of sorting.
+ *
+ * @todo Add docs about numeric promotion
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ template<const AtomicComparator::Operator t_op>
+ class AbstractFloatSortComparator : public AbstractFloatComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &o1,
+ const AtomicComparator::Operator op,
+ const Item &o2) const
+ {
+ Q_ASSERT_X(t_op == OperatorLessThanNaNLeast || t_op == OperatorLessThanNaNGreatest, Q_FUNC_INFO,
+ "Can only be instantiated with those two.");
+ Q_ASSERT(op == t_op);
+ Q_UNUSED(op); /* Needed when building in release mode. */
+
+ const xsDouble v1 = o1.template as<Numeric>()->toDouble();
+ const xsDouble v2 = o2.template as<Numeric>()->toDouble();
+
+ if(qIsNaN(v1) && !qIsNaN(v2))
+ return t_op == OperatorLessThanNaNLeast ? LessThan : GreaterThan;
+ if(!qIsNaN(v1) && qIsNaN(v2))
+ return t_op == OperatorLessThanNaNLeast ? GreaterThan : LessThan;
+
+ if(Double::isEqual(v1, v2))
+ return Equal;
+ else if(v1 < v2)
+ return LessThan;
+ else
+ return GreaterThan;
+ }
+
+ };
+
+ /**
+ * @short Compares @c xs:decimal values.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class DecimalComparator : public AtomicComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares @c xs:integer values.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class IntegerComparator : public AtomicComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares @c xs:QName values.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class QNameComparator : public AtomicComparator
+ {
+ public:
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares sub-classes of AbstractDateTime.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeComparator : public AtomicComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+ };
+
+ /**
+ * @short Compares sub-classes of AbstractDuration.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDurationComparator : public AtomicComparator
+ {
+ public:
+ virtual ComparisonResult compare(const Item &op1,
+ const AtomicComparator::Operator op,
+ const Item &op2) const;
+ virtual bool equals(const Item &op1,
+ const Item &op2) const;
+
+ private:
+ static inline QDateTime addDurationToDateTime(const QDateTime &dateTime,
+ const AbstractDuration *const duration);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomicmathematician.cpp b/src/xmlpatterns/data/qatomicmathematician.cpp
new file mode 100644
index 0000000..816f731
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicmathematician.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qatomicmathematician_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AtomicMathematician::~AtomicMathematician()
+{
+}
+
+QString AtomicMathematician::displayName(const AtomicMathematician::Operator op)
+{
+ switch(op)
+ {
+ case AtomicMathematician::Div:
+ return QLatin1String("div");
+ case AtomicMathematician::IDiv:
+ return QLatin1String("idiv");
+ case AtomicMathematician::Substract:
+ return QLatin1String("-");
+ case AtomicMathematician::Mod:
+ return QLatin1String("mod");
+ case AtomicMathematician::Multiply:
+ return QLatin1String("*");
+ case AtomicMathematician::Add:
+ return QLatin1String("+");
+ }
+
+ return QString(); /* Silence GCC warning. */
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomicmathematician_p.h b/src/xmlpatterns/data/qatomicmathematician_p.h
new file mode 100644
index 0000000..37d0cc5
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicmathematician_p.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AtomicMathematician_H
+#define Patternist_AtomicMathematician_H
+
+#include <QFlags>
+
+#include "qdynamiccontext_p.h"
+#include "qitem_p.h"
+#include "qatomictypedispatch_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Base class for classes that performs arithmetic operations between atomic values.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_AUTOTEST_EXPORT AtomicMathematician : public AtomicTypeVisitorResult
+ {
+ public:
+ virtual ~AtomicMathematician();
+
+ typedef QExplicitlySharedDataPointer<AtomicMathematician> Ptr;
+
+ enum Operator
+ {
+ /**
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-numeric-divide">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.2.4 op:numeric-divide</a>
+ */
+ Div = 1,
+
+ /**
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-numeric-integer-divide">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.2.5 op:numeric-integer-divide</a>
+ */
+ IDiv = 2,
+
+ /**
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-numeric-subtract">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.2.2 op:numeric-subtract</a>
+ */
+ Substract = 4,
+
+ /**
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-numeric-mod">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.2.6 op:numeric-mod</a>
+ */
+ Mod = 8,
+
+ /**
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-numeric-multiply">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.2.3 op:numeric-multiply</a>
+ */
+ Multiply = 16,
+
+ /**
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-numeric-add">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.2.1 op:numeric-add</a>
+ */
+ Add = 32
+ };
+
+ typedef QFlags<Operator> Operators;
+
+ virtual Item calculate(const Item &operand1,
+ const Operator op,
+ const Item &operand2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const = 0;
+
+ static QString displayName(const AtomicMathematician::Operator op);
+
+ };
+ Q_DECLARE_OPERATORS_FOR_FLAGS(AtomicMathematician::Operators)
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomicmathematicians.cpp b/src/xmlpatterns/data/qatomicmathematicians.cpp
new file mode 100644
index 0000000..bd138a8
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicmathematicians.cpp
@@ -0,0 +1,352 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <math.h>
+
+#include <qnumeric.h>
+
+#include "qabstractdatetime_p.h"
+#include "qabstractduration_p.h"
+#include "qabstractfloat_p.h"
+#include "qdaytimeduration_p.h"
+#include "qdecimal_p.h"
+#include "qinteger_p.h"
+#include "qpatternistlocale_p.h"
+
+#include "qatomicmathematicians_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+/* The translation strings is place here once, in order to reduce work for translators,
+ * and provide consistency. */
+
+static inline QString idivZeroInvalid()
+{
+ return QtXmlPatterns::tr("Integer division (%1) by zero (%2) is undefined.")
+ .arg(formatKeyword("idiv"))
+ .arg(formatData("0"));
+}
+
+static inline QString divZeroInvalid()
+{
+ return QtXmlPatterns::tr("Division (%1) by zero (%2) is undefined.")
+ .arg(formatKeyword("div"))
+ .arg(formatData("0"));
+}
+
+static inline QString modZeroInvalid()
+{
+ return QtXmlPatterns::tr("Modulus division (%1) by zero (%2) is undefined.")
+ .arg(formatKeyword("mod"))
+ .arg(formatData("0"));
+}
+
+Item DecimalMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ switch(op)
+ {
+ case Div:
+ {
+ if(o2.as<Numeric>()->toInteger() == 0)
+ {
+ context->error(divZeroInvalid(), ReportContext::FOAR0001, this);
+ return Item(); /* Silences source code analyzer warning. */
+ }
+ else
+ return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() / o2.as<Numeric>()->toDecimal()));
+ }
+ case IDiv:
+ {
+ if(o2.as<Numeric>()->toInteger() == 0)
+ {
+ context->error(idivZeroInvalid(), ReportContext::FOAR0001, this);
+ return Item(); /* Silences source code analyzer warning. */
+ }
+ else
+ return Integer::fromValue(static_cast<xsInteger>(o1.as<Numeric>()->toDecimal() /
+ o2.as<Numeric>()->toDecimal()));
+ }
+ case Substract:
+ return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() - o2.as<Numeric>()->toDecimal()));
+ case Mod:
+ {
+ if(o2.as<Numeric>()->toInteger() == 0)
+ {
+ context->error(modZeroInvalid(), ReportContext::FOAR0001, this);
+ return Item(); /* Silences source code analyzer warning. */
+ }
+ else
+ return toItem(Decimal::fromValue(::fmod(o1.as<Numeric>()->toDecimal(), o2.as<Numeric>()->toDecimal())));
+ }
+ case Multiply:
+ return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() * o2.as<Numeric>()->toDecimal()));
+ case Add:
+ return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() + o2.as<Numeric>()->toDecimal()));
+ }
+
+ Q_ASSERT(false);
+ return Item(); /* GCC unbarfer. */
+}
+
+Item IntegerMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ switch(op)
+ {
+ case Div:
+ if(o2.as<Numeric>()->toInteger() == 0)
+ {
+ context->error(divZeroInvalid(), ReportContext::FOAR0001, this);
+ return Item(); /* Silences source code analyzer warning. */
+ }
+ else /* C++ automatically performs truncation of long integer(xsInteger). */
+ return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() / o2.as<Numeric>()->toDecimal()));
+ case IDiv:
+ {
+ if(o2.as<Numeric>()->toInteger() == 0)
+ {
+ context->error(idivZeroInvalid(), ReportContext::FOAR0001, this);
+ return Item(); /* Silences source code analyzer warning. */
+ }
+ else /* C++ automatically performs truncation of long integer(xsInteger). */
+ return Integer::fromValue(o1.as<Numeric>()->toInteger() / o2.as<Numeric>()->toInteger());
+ }
+ case Substract:
+ return Integer::fromValue(o1.as<Numeric>()->toInteger() - o2.as<Numeric>()->toInteger());
+ case Mod:
+ {
+ const xsInteger divisor = o2.as<Numeric>()->toInteger();
+
+ if(divisor == 0)
+ {
+ context->error(modZeroInvalid(), ReportContext::FOAR0001, this);
+ return Item(); /* Silences source code analyzer warning. */
+ }
+ else
+ return Integer::fromValue(o1.as<Numeric>()->toInteger() % divisor);
+ }
+ case Multiply:
+ return Integer::fromValue(o1.as<Numeric>()->toInteger() * o2.as<Numeric>()->toInteger());
+ case Add:
+ return Integer::fromValue(o1.as<Numeric>()->toInteger() + o2.as<Numeric>()->toInteger());
+ }
+
+ Q_ASSERT(false);
+ return Item(); /* GCC unbarfer. */
+}
+
+Item DurationNumericMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ Q_ASSERT(op == Div || op == Multiply);
+
+ const AbstractDuration::Ptr duration(o1.as<AbstractDuration>());
+ const xsDouble dbl = o2.as<Numeric>()->toDouble();
+
+ switch(op)
+ {
+ case Div:
+ {
+ if(qIsInf(dbl))
+ return duration->fromValue(0);
+ else if(qIsNaN(dbl))
+ {
+ context->error(QtXmlPatterns::tr(
+ "Dividing a value of type %1 by %2 (not-a-number) "
+ "is not allowed.")
+ .arg(formatType(context->namePool(),
+ duration->type()))
+ .arg(formatData("NaN")),
+ ReportContext::FOCA0005,
+ this);
+ return Item();
+ }
+ else if(Double::isEqual(dbl, 0))
+ {
+ context->error(QtXmlPatterns::tr(
+ "Dividing a value of type %1 by %2 or %3 (plus or "
+ "minus zero) is not allowed.")
+ .arg(formatType(context->namePool(),
+ duration->type()))
+ .arg(formatData("-0"))
+ .arg(formatData("0")),
+ ReportContext::FODT0002,
+ this);
+ return Item();
+ }
+
+ return duration->fromValue(static_cast<AbstractDuration::Value>(duration->value() / dbl));
+ }
+ case Multiply:
+ {
+ if(Double::isEqual(dbl, 0))
+ return duration->fromValue(0);
+ else if(qIsNaN(dbl))
+ {
+ context->error(QtXmlPatterns::tr(
+ "Dividing a value of type %1 by %2 (not-a-number) "
+ "is not allowed.")
+ .arg(formatType(context->namePool(),
+ duration->type()))
+ .arg(formatData("NaN")),
+ ReportContext::FOCA0005,
+ this);
+ return Item();
+ }
+ else if(qIsInf(dbl))
+ {
+ context->error(QtXmlPatterns::tr(
+ "Multiplication of a value of type %1 by %2 or %3 "
+ "(plus or minus infinity) is not allowed.")
+ .arg(formatType(context->namePool(),
+ duration->type()))
+ .arg(formatData("-INF"))
+ .arg(formatData("INF")),
+ ReportContext::FODT0002,
+ this);
+ return Item();
+ }
+
+ return duration->fromValue(static_cast<AbstractDuration::Value>(duration->value() * dbl));
+ }
+ default:
+ {
+ Q_ASSERT(false);
+ return Item(); /* Silence warning. */
+ }
+ }
+}
+
+Item DurationDurationMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ const AbstractDuration::Ptr duration(o1.as<AbstractDuration>());
+ const AbstractDuration::Value op2 = o2.as<AbstractDuration>()->value();
+
+ switch(op)
+ {
+ case Div:
+ return toItem(Decimal::fromValue(static_cast<xsDecimal>(duration->value()) / op2));
+ case Substract:
+ return duration->fromValue(duration->value() - op2);
+ case Add:
+ return duration->fromValue(duration->value() + op2);
+ default:
+ {
+ Q_ASSERT(false);
+ return Item(); /* Silence warning. */
+ }
+ }
+}
+
+OperandSwitcherMathematician::
+OperandSwitcherMathematician(const AtomicMathematician::Ptr &mathematician) : m_mather(mathematician)
+{
+ Q_ASSERT(mathematician);
+}
+
+Item OperandSwitcherMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ return m_mather->calculate(o2, op, o1, context);
+}
+
+
+Item DateTimeDurationMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ Q_ASSERT(op == Substract || op == Add);
+
+ const AbstractDateTime::Ptr adt(o1.as<AbstractDateTime>());
+ const AbstractDuration::Ptr dur(o2.as<AbstractDuration>());
+ QDateTime dt(adt->toDateTime());
+ //pDebug() << "DateTimeDurationMathematician::calculate():" << dt.toString();
+ //dt.setDateOnly(false);
+ const qint8 sign = (op == Add ? 1 : -1) * (dur->isPositive() ? 1 : -1);
+
+ // TODO milli seconds
+ dt = dt.addSecs(sign * (dur->seconds() + dur->minutes() * 60 + dur->hours() * 60 * 60));
+ dt = dt.addDays(sign * dur->days());
+ dt = dt.addMonths(sign * dur->months());
+ dt = dt.addYears(sign * dur->years());
+
+ QString msg;
+
+ if(AbstractDateTime::isRangeValid(dt.date(), msg))
+ return adt->fromValue(dt);
+ else
+ {
+ context->error(msg, ReportContext::FODT0001,
+ this);
+ return Item();
+ }
+}
+
+Item AbstractDateTimeMathematician::calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ Q_ASSERT(op == Substract || op == Add);
+ QDateTime dt1(o1.as<AbstractDateTime>()->toDateTime());
+ QDateTime dt2(o2.as<AbstractDateTime>()->toDateTime());
+
+ const int diff = op == Add ? dt1.secsTo(dt2) : dt2.secsTo(dt1);
+
+ return toItem(DayTimeDuration::fromSeconds(diff));
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomicmathematicians_p.h b/src/xmlpatterns/data/qatomicmathematicians_p.h
new file mode 100644
index 0000000..7bbdaef
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicmathematicians_p.h
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_AtomicMathematicians_H
+#define Patternist_AtomicMathematicians_H
+
+#include "qatomicmathematician_p.h"
+#include "qsourcelocationreflection_p.h"
+
+/**
+ * @file
+ * @short Contains classes performing arithemetic operations between atomic values, such as
+ * subtracting two dates.
+ */
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class DecimalMathematician : public AtomicMathematician
+ , public DelegatingSourceLocationReflection
+ {
+ public:
+ inline DecimalMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
+ {
+ }
+
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Performs arithmetics between Integer values.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class IntegerMathematician : public AtomicMathematician
+ , public DelegatingSourceLocationReflection
+ {
+ public:
+ inline IntegerMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
+ {
+ }
+
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Performs division or multiplication between either DayTimeDuration or YearMonthDuration
+ * and Double values.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class DurationNumericMathematician : public AtomicMathematician
+ , public DelegatingSourceLocationReflection
+ {
+ public:
+ inline DurationNumericMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
+ {
+ }
+
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Performs division between DayTimeDuration and DayTimeDuration, or
+ * YearMonthDuration and YearMonthDuration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class DurationDurationDivisor : public AtomicMathematician
+ {
+ public:
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Performs arithmetics between DayTimeDuration and DayTimeDuration, or
+ * YearMonthDuration and YearMonthDuration.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class DurationDurationMathematician : public AtomicMathematician
+ {
+ public:
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Delegates an AtomicMathematician and switches its operands.
+ *
+ * Switches the operands of the call to a call to the calculate()
+ * on an AtomicMathematician such that the left operand becomes the right, and
+ * vice versa.
+ *
+ * Its constructor takes an AtomicMathematician instance which this OperandSwitcherMathematician
+ * should act as as a middle-man for, having the role of switching the two operands. Thus,
+ * OperandSwitcherMathematician can be described as a proxy or delegator class.
+ *
+ * This class is used for implementing operator combinations such as
+ * <tt>numeric * xs:yearMonthDuration</tt> and
+ * <tt>xs:yearMonthDuration * numeric</tt>.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class OperandSwitcherMathematician : public AtomicMathematician
+ {
+ public:
+ /**
+ * Creates an OperandSwitcherMathematician.
+ *
+ * @param mathematician the AtomicMathematician this OperandSwitcherMathematician
+ * should switch the operands for. Must be a non @c null, valid pointer.
+ */
+ OperandSwitcherMathematician(const AtomicMathematician::Ptr &mathematician);
+
+ /**
+ * Switch @p o1 and @p o2, and returns the value from the AtomicMathematician
+ * this OperandSwitcherMathematician represents.
+ */
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ private:
+ const AtomicMathematician::Ptr m_mather;
+ };
+
+ /**
+ * @short Performs arithmetics between an AbstractDateTime value and
+ * an AbstractDuration value.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class DateTimeDurationMathematician : public AtomicMathematician
+ , public DelegatingSourceLocationReflection
+ {
+ public:
+
+ inline DateTimeDurationMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
+ {
+ }
+
+ /**
+ * @p o1 is an AbstractDateTime and @p o2 is an AbstractDuration.
+ *
+ */
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+
+ /**
+ * @short Performs arithmetics between two AbstractDateTime values.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AbstractDateTimeMathematician : public AtomicMathematician
+ {
+ public:
+ virtual Item calculate(const Item &o1,
+ const Operator op,
+ const Item &o2,
+ const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomicstring.cpp b/src/xmlpatterns/data/qatomicstring.cpp
new file mode 100644
index 0000000..5e92e94
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicstring.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qatomicstring_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AtomicString::AtomicString(const QString &s) : m_value(s)
+{
+}
+
+AtomicString::Ptr AtomicString::fromValue(const QString &value)
+{
+ return AtomicString::Ptr(new AtomicString(value));
+}
+
+bool AtomicString::evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return m_value.length() > 0;
+}
+
+QString AtomicString::stringValue() const
+{
+ return m_value;
+}
+
+ItemType::Ptr AtomicString::type() const
+{
+ return BuiltinTypes::xsString;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qatomicstring_p.h b/src/xmlpatterns/data/qatomicstring_p.h
new file mode 100644
index 0000000..bbdc66d
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicstring_p.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_String_H
+#define Patternist_String_H
+
+#include <QUrl>
+
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:string type.
+ *
+ *
+ * This class was originally called String, and correspondingly the header
+ * file was called String.h. However, this broke building on OS X, which
+ * looks up file names case insensitively, and therefore found string.h.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing/incomplete
+ */
+ class Q_AUTOTEST_EXPORT AtomicString : public AtomicValue
+ {
+ public:
+ friend class CommonValues;
+
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance representing @p value.
+ *
+ * @note This function does not remove the string literal escaping allowed in XPath 2.0
+ */
+ static AtomicString::Ptr fromValue(const QString &value);
+
+ static inline AtomicString::Ptr fromValue(const QUrl &value)
+ {
+ return fromValue(value.toString());
+ }
+
+ /**
+ * Get the Effective %Boolean Value of this string. A zero-length
+ * string has an effective boolean value of @c false, in all other cases @c true.
+ *
+ * @returns @c false if the contained string has a zero-length, otherwise @c true.
+ */
+ virtual bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const;
+
+ /**
+ * The string value of a AtomicString instance is the value space.
+ */
+ virtual QString stringValue() const;
+
+ virtual ItemType::Ptr type() const;
+
+ protected:
+ friend class StringComparator;
+ friend class CompareFN;
+ AtomicString(const QString &value);
+ const QString m_value;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qatomicvalue.cpp b/src/xmlpatterns/data/qatomicvalue.cpp
new file mode 100644
index 0000000..a68643f
--- /dev/null
+++ b/src/xmlpatterns/data/qatomicvalue.cpp
@@ -0,0 +1,228 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QVariant>
+
+#include "qabstractdatetime_p.h"
+#include "qabstractfloat_p.h"
+#include "qatomicstring_p.h"
+#include "qatomictype_p.h"
+#include "qboolean_p.h"
+#include "qbuiltintypes_p.h"
+#include "qdate_p.h"
+#include "qschemadatetime_p.h"
+#include "qderivedinteger_p.h"
+#include "qdynamiccontext_p.h"
+#include "qgenericsequencetype_p.h"
+#include "qhexbinary_p.h"
+#include "qinteger_p.h"
+#include "qpatternistlocale_p.h"
+#include "qqnamevalue_p.h"
+#include "qschematime_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qitem_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/**
+ * @file
+ * @short Contains the implementation for AtomicValue. The defintion is in qitem_p.h.
+ */
+
+using namespace QPatternist;
+
+AtomicValue::~AtomicValue()
+{
+}
+
+bool AtomicValue::evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &context) const
+{
+ context->error(QtXmlPatterns::tr("A value of type %1 cannot have an "
+ "Effective Boolean Value.")
+ .arg(formatType(context->namePool(), type())),
+ ReportContext::FORG0006,
+ QSourceLocation());
+ return false; /* Silence GCC warning. */
+}
+
+bool AtomicValue::hasError() const
+{
+ return false;
+}
+
+QVariant AtomicValue::toQt(const AtomicValue *const value)
+{
+ Q_ASSERT_X(value, Q_FUNC_INFO,
+ "Internal error, a null pointer cannot be passed.");
+
+ const ItemType::Ptr t(value->type());
+
+ if(BuiltinTypes::xsString->xdtTypeMatches(t)
+ || BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(t)
+ || BuiltinTypes::xsAnyURI->xdtTypeMatches(t))
+ return value->stringValue();
+ /* Note, this occurs before the xsInteger test, since xs:unsignedLong
+ * is a subtype of it. */
+ else if(*BuiltinTypes::xsUnsignedLong == *t)
+ return QVariant(value->as<DerivedInteger<TypeUnsignedLong> >()->storedValue());
+ else if(BuiltinTypes::xsInteger->xdtTypeMatches(t))
+ return QVariant(value->as<Numeric>()->toInteger());
+ else if(BuiltinTypes::xsFloat->xdtTypeMatches(t)
+ || BuiltinTypes::xsDouble->xdtTypeMatches(t)
+ || BuiltinTypes::xsDecimal->xdtTypeMatches(t))
+ return QVariant(value->as<Numeric>()->toDouble());
+ /* We currently does not support xs:time. */
+ else if(BuiltinTypes::xsDateTime->xdtTypeMatches(t))
+ return QVariant(value->as<AbstractDateTime>()->toDateTime());
+ else if(BuiltinTypes::xsDate->xdtTypeMatches(t))
+ return QVariant(value->as<AbstractDateTime>()->toDateTime().toUTC().date());
+ else if(BuiltinTypes::xsBoolean->xdtTypeMatches(t))
+ return QVariant(value->as<Boolean>()->value());
+ else if(BuiltinTypes::xsBase64Binary->xdtTypeMatches(t)
+ || BuiltinTypes::xsHexBinary->xdtTypeMatches(t))
+ return QVariant(value->as<Base64Binary>()->asByteArray());
+ else if(BuiltinTypes::xsQName->xdtTypeMatches(t))
+ return qVariantFromValue(value->as<QNameValue>()->qName());
+ else
+ {
+ /* A type we don't support in Qt. Includes xs:time currently. */
+ return QVariant();
+ }
+}
+
+Item AtomicValue::toXDM(const QVariant &value)
+{
+ Q_ASSERT_X(value.isValid(), Q_FUNC_INFO,
+ "QVariants sent to Patternist must be valid.");
+
+ switch(value.type())
+ {
+ case QVariant::Char:
+ /* Fallthrough. A single codepoint is a string in XQuery. */
+ case QVariant::String:
+ return AtomicString::fromValue(value.toString());
+ case QVariant::Url:
+ {
+ /* QUrl doesn't follow the spec properly, so we
+ * have to let it be an xs:string. Calling QVariant::toString()
+ * on a QVariant that contains a QUrl returns, surprisingly,
+ * an empty string. */
+ return AtomicString::fromValue(value.toUrl().toString());
+ }
+ case QVariant::ByteArray:
+ return HexBinary::fromValue(value.toByteArray());
+ case QVariant::Int:
+ /* Fallthrough. */
+ case QVariant::LongLong:
+ /* Fallthrough. */
+ case QVariant::UInt:
+ return Integer::fromValue(value.toLongLong());
+ case QVariant::ULongLong:
+ return DerivedInteger<TypeUnsignedLong>::fromValueUnchecked(value.toULongLong());
+ case QVariant::Bool:
+ return Boolean::fromValue(value.toBool());
+ case QVariant::Time:
+ return SchemaTime::fromDateTime(value.toDateTime());
+ case QVariant::Date:
+ return Date::fromDateTime(QDateTime(value.toDate(), QTime(), Qt::UTC));
+ case QVariant::DateTime:
+ return DateTime::fromDateTime(value.toDateTime());
+ case QVariant::Double:
+ return Item(Double::fromValue(value.toDouble()));
+ default:
+ {
+ Q_ASSERT_X(false,
+ Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1(
+ "QVariants of type %1 are not supported in "
+ "Patternist, see the documentation")
+ .arg(QLatin1String(value.typeName()))));
+ return AtomicValue::Ptr();
+ }
+ }
+}
+
+ItemType::Ptr AtomicValue::qtToXDMType(const QXmlItem &item)
+{
+ Q_ASSERT(!item.isNull());
+
+ if(item.isNull())
+ return ItemType::Ptr();
+
+ if(item.isNode())
+ return BuiltinTypes::node;
+
+ Q_ASSERT(item.isAtomicValue());
+ const QVariant v(item.toAtomicValue());
+
+ switch(v.type())
+ {
+ case QVariant::Char:
+ /* Fallthrough. */
+ case QVariant::String:
+ /* Fallthrough. */
+ case QVariant::Url:
+ return BuiltinTypes::xsString;
+ case QVariant::Bool:
+ return BuiltinTypes::xsBoolean;
+ case QVariant::ByteArray:
+ return BuiltinTypes::xsBase64Binary;
+ case QVariant::Int:
+ /* Fallthrough. */
+ case QVariant::LongLong:
+ return BuiltinTypes::xsInteger;
+ case QVariant::ULongLong:
+ return BuiltinTypes::xsUnsignedLong;
+ case QVariant::Date:
+ return BuiltinTypes::xsDate;
+ case QVariant::DateTime:
+ /* Fallthrough. */
+ case QVariant::Time:
+ return BuiltinTypes::xsDateTime;
+ case QVariant::Double:
+ return BuiltinTypes::xsDouble;
+ default:
+ return ItemType::Ptr();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qbase64binary.cpp b/src/xmlpatterns/data/qbase64binary.cpp
new file mode 100644
index 0000000..0f805c0
--- /dev/null
+++ b/src/xmlpatterns/data/qbase64binary.cpp
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QByteArray>
+#include <QtGlobal>
+
+#include "qbuiltintypes_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qbase64binary_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Base64Binary::Base64Binary(const QByteArray &val) : m_value(val)
+{
+}
+
+const char Base64Binary::Base64DecMap[128] =
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
+ 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+ 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
+ 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+ 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
+ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
+ 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+void Base64Binary::base64Decode(const QByteArray &in, QByteArray &out, bool &ok)
+{
+ out.resize(0);
+
+ if(in.isEmpty())
+ {
+ ok = false;
+ return;
+ }
+
+ ok = true;
+ int len = in.size(), tail = len;
+ const char *const data = in.data();
+ unsigned int eqCount = 0;
+
+ // Find the tail end of the actual encoded data even if
+ // there is/are trailing CR and/or LF.
+ while(data[tail - 1] == '=')
+ {
+ --tail;
+ if(data[tail] != '=')
+ len = tail;
+ else
+ ++eqCount;
+ }
+
+ if(eqCount > 2)
+ {
+ ok = false;
+ return;
+ }
+
+ unsigned int outIdx = 0;
+ const int count = len; // We modify len below
+ out.resize((count));
+
+ for(int idx = 0; idx < count; ++idx)
+ {
+ const unsigned char ch = data[idx];
+ if((ch > 47 && ch < 58) ||
+ (ch > 64 && ch < 91) ||
+ (ch > 96 && ch < 123) ||
+ ch == '+' ||
+ ch == '/')
+ {
+ out[outIdx++] = Base64DecMap[ch];
+ }
+ else if(ch == '=')
+ {
+ if((idx + 1) == count || data[idx + 1] == '=')
+ {
+ out[++outIdx] = Base64DecMap[ch];
+ continue;
+ }
+
+ ok = false;
+ return;
+ }
+ else if(ch == ' ')
+ {
+ /* One space is ok, and the previously applied whitespace facet(not implemented
+ * at this time of writing) have ensured it's only one space, so we assume that. */
+ --tail;
+ --len;
+ continue;
+ }
+ else
+ {
+ ok = false;
+ return;
+ }
+ }
+
+ if(outIdx % 4 != 0)
+ {
+ ok = false;
+ return;
+ }
+
+ out.resize(len);
+
+ // 4-byte to 3-byte conversion
+ len = (tail > (len / 4)) ? tail - (len / 4) : 0;
+ int sidx = 0, didx = 0;
+ if(len > 1)
+ {
+ while(didx < len - 2)
+ {
+ out[didx] =(((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
+ out[didx + 1] =(((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
+ out[didx + 2] =(((out[sidx + 2] << 6) & 255) | (out[sidx + 3] & 077));
+ sidx += 4;
+ didx += 3;
+ }
+ }
+
+ if(didx < len)
+ out[didx] =(((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
+
+ if(++didx < len)
+ out[didx] =(((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
+
+ // Resize the output buffer
+ if(len == 0 || len < out.size())
+ out.resize(len);
+}
+
+AtomicValue::Ptr Base64Binary::fromLexical(const QString &str)
+{
+ const QString simple(str.simplified());
+ if(simple.isEmpty())
+ return AtomicValue::Ptr(new Base64Binary(QByteArray()));
+
+ bool ok = false;
+ QByteArray result;
+ base64Decode(simple.toUtf8(), result, ok);
+
+ if(ok)
+ return AtomicValue::Ptr(new Base64Binary(result));
+ else
+ return ValidationError::createError();
+}
+
+Base64Binary::Ptr Base64Binary::fromValue(const QByteArray &data)
+{
+ return Base64Binary::Ptr(new Base64Binary(data));
+}
+
+QString Base64Binary::stringValue() const
+{
+ return QString::fromLatin1(m_value.toBase64().constData());
+}
+
+ItemType::Ptr Base64Binary::type() const
+{
+ return BuiltinTypes::xsBase64Binary;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qbase64binary_p.h b/src/xmlpatterns/data/qbase64binary_p.h
new file mode 100644
index 0000000..9eaa23b
--- /dev/null
+++ b/src/xmlpatterns/data/qbase64binary_p.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Base64Binary_H
+#define Patternist_Base64Binary_H
+
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+
+ /**
+ * @short Implements the value instance of the @c xs:base64Binary type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class Base64Binary : public AtomicValue
+ {
+ public:
+ friend class CommonValues;
+
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance representing @p value.
+ */
+ static AtomicValue::Ptr fromLexical(const QString &value);
+
+ static Base64Binary::Ptr fromValue(const QByteArray &data);
+
+ virtual QString stringValue() const;
+ virtual ItemType::Ptr type() const;
+ inline const QByteArray &asByteArray() const
+ {
+ return m_value;
+ }
+
+ protected:
+ Base64Binary(const QByteArray &val);
+
+ const QByteArray m_value;
+
+ private:
+ /**
+ * @short Assumes @p in is a lexical representation of @c xs:base64Binary, and
+ * converts it to the binary data set in @p out.
+ *
+ * If @p instr is invalid Base64 content, @p ok is set to
+ * false, and the returned QByteArray has an undefined value.
+ *
+ * We cannot use QByteArray::fromBase64() because it doesn't do the
+ * necessary validation that we need to properly implement W3C XML
+ * Schema's xs:base64Binary type.
+ */
+ static void base64Decode(const QByteArray &in, QByteArray &out, bool &ok);
+
+ static const char Base64DecMap[128];
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qboolean.cpp b/src/xmlpatterns/data/qboolean.cpp
new file mode 100644
index 0000000..e87d6c2
--- /dev/null
+++ b/src/xmlpatterns/data/qboolean.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qatomictype_p.h"
+#include "qbuiltintypes_p.h"
+#include "qcommonvalues_p.h"
+#include "qdynamiccontext_p.h"
+#include "qpatternistlocale_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qboolean_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+bool Boolean::evaluateEBV(const Item::Iterator::Ptr &it,
+ const QExplicitlySharedDataPointer<DynamicContext> &context)
+{
+ return evaluateEBV(it->next(), it, context);
+}
+
+bool Boolean::evaluateEBV(const Item &first,
+ const Item::Iterator::Ptr &it,
+ const QExplicitlySharedDataPointer<DynamicContext> &context)
+{
+ Q_ASSERT(it);
+ Q_ASSERT(context);
+
+ if(!first)
+ return false;
+ else if(first.isNode())
+ return true;
+
+ const Item second(it->next());
+
+ if(second)
+ {
+ Q_ASSERT(context);
+ context->error(QtXmlPatterns::tr("Effective Boolean Value cannot be calculated for a sequence "
+ "containing two or more atomic values."),
+ ReportContext::FORG0006,
+ QSourceLocation());
+ return false;
+ }
+ else
+ return first.as<AtomicValue>()->evaluateEBV(context);
+}
+
+bool Boolean::evaluateEBV(const Item &item,
+ const QExplicitlySharedDataPointer<DynamicContext> &context)
+{
+ if(!item)
+ return false;
+ else if(item.isNode())
+ return true;
+ else
+ return item.as<AtomicValue>()->evaluateEBV(context);
+}
+
+Boolean::Boolean(const bool value) : m_value(value)
+{
+}
+
+QString Boolean::stringValue() const
+{
+ return m_value
+ ? CommonValues::TrueString->stringValue()
+ : CommonValues::FalseString->stringValue();
+}
+
+bool Boolean::evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return m_value;
+}
+
+Boolean::Ptr Boolean::fromValue(const bool value)
+{
+ return value ? CommonValues::BooleanTrue : CommonValues::BooleanFalse;
+}
+
+AtomicValue::Ptr Boolean::fromLexical(const QString &lexical)
+{
+ const QString val(lexical.trimmed()); /* Apply the whitespace facet. */
+
+ if(val == QLatin1String("true") || val == QChar(QLatin1Char('1')))
+ return CommonValues::BooleanTrue;
+ else if(val == QLatin1String("false") || val == QChar(QLatin1Char('0')))
+ return CommonValues::BooleanFalse;
+ else
+ return ValidationError::createError();
+}
+
+ItemType::Ptr Boolean::type() const
+{
+ return BuiltinTypes::xsBoolean;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qboolean_p.h b/src/xmlpatterns/data/qboolean_p.h
new file mode 100644
index 0000000..10b1515
--- /dev/null
+++ b/src/xmlpatterns/data/qboolean_p.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Boolean_H
+#define Patternist_Boolean_H
+
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:boolean type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class Q_AUTOTEST_EXPORT Boolean : public AtomicValue
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * @returns the boolean value this Boolean represents
+ */
+ static bool evaluateEBV(const Item::Iterator::Ptr &e,
+ const QExplicitlySharedDataPointer<DynamicContext> &);
+
+ static bool evaluateEBV(const Item &first,
+ const Item::Iterator::Ptr &e,
+ const QExplicitlySharedDataPointer<DynamicContext> &);
+
+ static bool evaluateEBV(const Item &item,
+ const QExplicitlySharedDataPointer<DynamicContext> &context);
+
+ virtual QString stringValue() const;
+
+ /**
+ * @returns a Boolean object instantiating @p value. Use True() or False()
+ * if you already know what value you need.
+ */
+ static Boolean::Ptr fromValue(const bool value);
+
+ /**
+ * Creates a boolean value from a lexical representation. "true" and "1"
+ * becomes @c true, while "false" and "0" becomes @c false.
+ */
+ static AtomicValue::Ptr fromLexical(const QString &val);
+
+ /**
+ * Get the Effective %Boolean Value of this boolean value. For <tt>xs:boolean</tt>, this
+ * is simply the value.
+ */
+ virtual bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const;
+
+ virtual ItemType::Ptr type() const;
+
+ inline bool value() const
+ {
+ return m_value;
+ }
+
+ protected:
+ friend class CommonValues;
+ Boolean(const bool value);
+
+ private:
+ const bool m_value;
+ };
+}
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qcommonvalues.cpp b/src/xmlpatterns/data/qcommonvalues.cpp
new file mode 100644
index 0000000..07a273d
--- /dev/null
+++ b/src/xmlpatterns/data/qcommonvalues.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <limits>
+
+#include "qabstractfloat_p.h"
+#include "qanyuri_p.h"
+#include "qboolean_p.h"
+#include "qdecimal_p.h"
+#include "qinteger_p.h"
+#include "qatomicstring_p.h"
+#include "quntypedatomic_p.h"
+
+#include "qcommonvalues_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+// STATIC DATA
+const AtomicString::Ptr CommonValues::EmptyString
+ (new AtomicString(QString(QLatin1String(""))));
+const AtomicString::Ptr CommonValues::TrueString
+ (new AtomicString(QLatin1String("true")));
+const AtomicString::Ptr CommonValues::FalseString
+ (new AtomicString(QLatin1String("false")));
+
+const UntypedAtomic::Ptr CommonValues::UntypedAtomicTrue
+ (new UntypedAtomic(QLatin1String("true")));
+const UntypedAtomic::Ptr CommonValues::UntypedAtomicFalse
+ (new UntypedAtomic(QLatin1String("false")));
+
+const AtomicValue::Ptr CommonValues::BooleanTrue
+ (new Boolean(true));
+const AtomicValue::Ptr CommonValues::BooleanFalse(new Boolean(false));
+
+const AtomicValue::Ptr CommonValues::DoubleNaN
+ (Double::fromValue(std::numeric_limits<xsDouble>::quiet_NaN()));
+
+const AtomicValue::Ptr CommonValues::FloatNaN
+ (Float::fromValue(std::numeric_limits<xsFloat>::quiet_NaN()));
+
+const Item CommonValues::IntegerZero
+ (Integer::fromValue(0));
+
+const AtomicValue::Ptr CommonValues::EmptyAnyURI
+ (AnyURI::fromValue(QLatin1String("")));
+
+const AtomicValue::Ptr CommonValues::DoubleOne
+ (Double::fromValue(1));
+const AtomicValue::Ptr CommonValues::FloatOne
+ (Float::fromValue(1));
+const AtomicValue::Ptr CommonValues::DecimalOne
+ (Decimal::fromValue(1));
+const Item CommonValues::IntegerOne
+ (Integer::fromValue(1));
+const Item CommonValues::IntegerOneNegative
+ (Integer::fromValue(-1));
+
+const AtomicValue::Ptr CommonValues::DoubleZero
+ (Double::fromValue(0));
+const AtomicValue::Ptr CommonValues::FloatZero
+ (Float::fromValue(0));
+const AtomicValue::Ptr CommonValues::DecimalZero
+ (Decimal::fromValue(0));
+
+const Item::EmptyIterator::Ptr CommonValues::emptyIterator
+ (new Item::EmptyIterator());
+
+const AtomicValue::Ptr CommonValues::NegativeInfDouble
+ (Double::fromValue(-std::numeric_limits<xsDouble>::infinity()));
+const AtomicValue::Ptr CommonValues::InfDouble
+ (Double::fromValue(std::numeric_limits<xsDouble>::infinity()));
+const AtomicValue::Ptr CommonValues::NegativeInfFloat
+ (Float::fromValue(-std::numeric_limits<xsFloat>::infinity()));
+const AtomicValue::Ptr CommonValues::InfFloat
+ (Float::fromValue(std::numeric_limits<xsFloat>::infinity()));
+
+const DayTimeDuration::Ptr CommonValues::DayTimeDurationZero
+ (DayTimeDuration::fromSeconds(0));
+const DayTimeDuration::Ptr CommonValues::YearMonthDurationZero
+ (YearMonthDuration::fromComponents(true, 0, 0));
+
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qcommonvalues_p.h b/src/xmlpatterns/data/qcommonvalues_p.h
new file mode 100644
index 0000000..6b9cf64
--- /dev/null
+++ b/src/xmlpatterns/data/qcommonvalues_p.h
@@ -0,0 +1,228 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_CommonValues_H
+#define Patternist_CommonValues_H
+
+#include "qdaytimeduration_p.h"
+#include "qyearmonthduration_p.h"
+#include "qemptyiterator_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+
+ /**
+ * @short A collection of common values.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing/incomplete
+ */
+ class CommonValues
+ {
+ public:
+ /**
+ * An empty, zero-length string.
+ *
+ * @note It is not @c null, but empty.
+ */
+ static const AtomicValue::Ptr EmptyString;
+
+ /**
+ * The string "true", the lexical representation of
+ * @c xs:boolean's value @c true.
+ */
+ static const AtomicValue::Ptr TrueString;
+
+ /**
+ * The string "false", the lexical representation of
+ * @c xs:boolean's value @c false.
+ */
+ static const AtomicValue::Ptr UntypedAtomicFalse;
+
+ /**
+ * The string "true", the lexical representation of
+ * @c xs:boolean's value @c true.
+ */
+ static const AtomicValue::Ptr UntypedAtomicTrue;
+
+ /**
+ * The string "false", the lexical representation of
+ * @c xs:boolean's value @c false.
+ */
+ static const AtomicValue::Ptr FalseString;
+
+ /**
+ * @returns a Boolean instance carrying the boolean value @c true.
+ * Use this value instead of Boolean::fromValue() if you
+ * know what boolean value you need.
+ */
+ static const AtomicValue::Ptr BooleanTrue;
+
+ /**
+ * @returns a Boolean instance carrying the boolean value @c true.
+ * Use this value instead of Boolean::fromValue() if you
+ * know what boolean value you need.
+ */
+ static const AtomicValue::Ptr BooleanFalse;
+
+ /**
+ * Not-a-Numeric typed as @c xs:double.
+ */
+ static const AtomicValue::Ptr DoubleNaN;
+
+ /**
+ * Not-a-Number typed as @c xs:float, <tt>xs:float("NaN")</tt>.
+ */
+ static const AtomicValue::Ptr FloatNaN;
+
+ /**
+ * Zero(0) typed as @c xs:integer, <tt>xs:integer("0")</tt>.
+ */
+ static const Item IntegerZero;
+
+ /**
+ * An empty, "", @c xs:anyURI.
+ */
+ static const AtomicValue::Ptr EmptyAnyURI;
+
+ /**
+ * The empty sequence.
+ */
+ static const EmptyIterator<Item>::Ptr emptyIterator;
+
+ /**
+ * <tt>xs:float("-INF")</tt>
+ */
+ static const AtomicValue::Ptr NegativeInfFloat;
+
+ /**
+ * <tt>xs:float("INF")</tt>
+ */
+ static const AtomicValue::Ptr InfFloat;
+
+ /**
+ * <tt>xs:double("-INF")</tt>
+ */
+ static const AtomicValue::Ptr NegativeInfDouble;
+
+ /**
+ * <tt>xs:double("INF")</tt>
+ */
+ static const AtomicValue::Ptr InfDouble;
+
+ /**
+ * <tt>xs:float("1")</tt>
+ */
+ static const AtomicValue::Ptr FloatOne;
+ /**
+ * <tt>xs:double("1")</tt>
+ */
+ static const AtomicValue::Ptr DoubleOne;
+ /**
+ * <tt>xs:decimal("1")</tt>
+ */
+ static const AtomicValue::Ptr DecimalOne;
+
+ /**
+ * <tt>xs:integer("1")</tt>
+ */
+ static const Item IntegerOne;
+
+ /**
+ * <tt>xs:integer("-1")</tt>
+ */
+ static const Item IntegerOneNegative;
+
+ /**
+ * <tt>xs:double("0")</tt>
+ */
+ static const AtomicValue::Ptr DoubleZero;
+
+ /**
+ * <tt>xs:float("0")</tt>
+ */
+ static const AtomicValue::Ptr FloatZero;
+ /**
+ * <tt>xs:integer("0")</tt>
+ */
+ static const AtomicValue::Ptr DecimalZero;
+
+ /**
+ * The @c xs:dayTimeDuration value PT0S
+ */
+ static const DayTimeDuration::Ptr DayTimeDurationZero;
+
+ /**
+ * The @c xs:yearMonthDuration value P0M
+ */
+ static const DayTimeDuration::Ptr YearMonthDurationZero;
+
+ private:
+ /**
+ * The constructor is private because this class is not meant to be instantiated,
+ * but should only be used via its static const members.
+ */
+ inline CommonValues();
+
+ Q_DISABLE_COPY(CommonValues)
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qdate.cpp b/src/xmlpatterns/data/qdate.cpp
new file mode 100644
index 0000000..d451e29
--- /dev/null
+++ b/src/xmlpatterns/data/qdate.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+#include "qitem_p.h"
+
+#include "qdate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Date::Date(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+Date::Ptr Date::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-?)" /* Any preceding minus. */
+ "(\\d{4,})" /* The year part. */
+ "-" /* Delimiter. */
+ "(\\d{2})" /* The month part. */
+ "-" /* Delimiter. */
+ "(\\d{2})" /* The day part. */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*zoneOffsetSignP*/ 5,
+ /*zoneOffsetHourP*/ 6,
+ /*zoneOffsetMinuteP*/ 7,
+ /*zoneOffsetUTCSymbolP*/ 8,
+ /*yearP*/ 2,
+ /*monthP*/ 3,
+ /*dayP*/ 4,
+ /*hourP*/ -1,
+ /*minutesP*/ -1,
+ /*secondsP*/ -1,
+ /*msecondsP*/ -1,
+ /*yearSign*/ 1);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : Date::Ptr(new Date(retval));
+}
+
+Date::Ptr Date::fromDateTime(const QDateTime &date)
+{
+ /* Don't include the QTime; "reset" the time. */
+ QDateTime result;
+ copyTimeSpec(date, result);
+ result.setDate(date.date());
+ Q_ASSERT(date.isValid());
+
+ return Date::Ptr(new Date(result));
+}
+
+Item Date::fromValue(const QDateTime &dt) const
+{
+ Q_ASSERT(dt.isValid());
+ return fromDateTime(dt);
+}
+
+QString Date::stringValue() const
+{
+ return dateToString() + zoneOffsetToString();
+}
+
+ItemType::Ptr Date::type() const
+{
+ return BuiltinTypes::xsDate;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qdate_p.h b/src/xmlpatterns/data/qdate_p.h
new file mode 100644
index 0000000..e804bfa
--- /dev/null
+++ b/src/xmlpatterns/data/qdate_p.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Date_H
+#define Patternist_Date_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:date type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class Date : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static Date::Ptr fromLexical(const QString &string);
+ static Date::Ptr fromDateTime(const QDateTime &date);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+ virtual Item fromValue(const QDateTime &dt) const;
+
+ protected:
+ friend class CommonValues;
+
+ Date(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qdaytimeduration.cpp b/src/xmlpatterns/data/qdaytimeduration.cpp
new file mode 100644
index 0000000..3555e59
--- /dev/null
+++ b/src/xmlpatterns/data/qdaytimeduration.cpp
@@ -0,0 +1,242 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractdatetime_p.h"
+#include "qbuiltintypes_p.h"
+#include "qcommonvalues_p.h"
+
+#include "qdaytimeduration_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+DayTimeDuration::DayTimeDuration(const bool isPositiveP,
+ const DayCountProperty daysP,
+ const HourProperty hoursP,
+ const MinuteProperty minutesP,
+ const SecondProperty secs,
+ const MSecondProperty msecs) : AbstractDuration(isPositiveP),
+ m_days(daysP),
+ m_hours(hoursP),
+ m_minutes(minutesP),
+ m_seconds(secs),
+ m_mseconds(msecs)
+{
+}
+
+DayTimeDuration::Ptr DayTimeDuration::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable(
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-)?" /* Any minus sign. */
+ "P" /* Delimiter. */
+ "(?:(\\d+)D)?" /* Day part. */
+ "(?:" /* Here starts the optional time part. */
+ "(T)" /* SchemaTime delimiter. */
+ "(?:(\\d+)H)?" /* Hour part. */
+ "(?:(\\d+)M)?" /* Minute part. */
+ "(?:(\\d+)(?:\\.(\\d+))?S)?" /* Seconds & milli seconds. */
+ ")?" /* End of optional time part. */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*yearP*/ -1,
+ /*monthP*/ -1,
+ /*dayP*/ 2,
+ /*tDelimiterP*/ 3,
+ /*hourP*/ 4,
+ /*minutesP*/ 5,
+ /*secondsP*/ 6,
+ /*msecondsP*/ 7);
+
+ DayCountProperty days = 0;
+ HourProperty hours = 0;
+ MinuteProperty minutes = 0;
+ SecondProperty sec = 0;
+ MSecondProperty msec = 0;
+ bool isPos;
+
+ const DayTimeDuration::Ptr err(create(captureTable, lexical, &isPos, 0, 0, &days,
+ &hours, &minutes, &sec, &msec));
+ return err ? err : DayTimeDuration::Ptr(new DayTimeDuration(isPos, days, hours, minutes,
+ sec, msec));
+}
+
+DayTimeDuration::Ptr DayTimeDuration::fromComponents(const bool isPositive,
+ const DayCountProperty days,
+ const HourProperty hours,
+ const MinuteProperty minutes,
+ const SecondProperty seconds,
+ const MSecondProperty mseconds)
+{
+ return DayTimeDuration::Ptr(new DayTimeDuration(isPositive,
+ days,
+ hours,
+ minutes,
+ seconds,
+ mseconds));
+}
+
+DayTimeDuration::Ptr DayTimeDuration::fromSeconds(const SecondCountProperty sourceSecs,
+ const MSecondProperty msecs)
+{
+ Q_ASSERT(msecs >= 0);
+ const SecondCountProperty source = qAbs(sourceSecs);
+ const bool isPos = sourceSecs >= 0;
+ const SecondCountProperty secs = source % 60;
+ const MinuteCountProperty mins = (source / 60) % 60;
+ const HourCountProperty hours = source / (60 * 60) % 24;
+ const DayCountProperty days = source / (60 * 60) / 24;
+
+ return DayTimeDuration::Ptr(new DayTimeDuration(isPos, days, hours, mins, secs, msecs));
+}
+
+QString DayTimeDuration::stringValue() const
+{
+ QString retval;
+
+ if(!m_isPositive)
+ retval.append(QLatin1Char('-'));
+
+ retval.append(QLatin1Char('P'));
+
+ if(m_days)
+ {
+ retval.append(QString::number(m_days));
+ retval.append(QLatin1Char('D'));
+ }
+
+ if(!m_hours && !m_minutes && !m_seconds && !m_seconds)
+ {
+ if(!m_days)
+ return QLatin1String("PT0S");
+ else
+ return retval;
+ }
+
+ retval.append(QLatin1Char('T'));
+
+ if(m_hours)
+ {
+ retval.append(QString::number(m_hours));
+ retval.append(QLatin1Char('H'));
+ }
+
+ if(m_minutes)
+ {
+ retval.append(QString::number(m_minutes));
+ retval.append(QLatin1Char('M'));
+ }
+
+ if(m_seconds || m_seconds)
+ {
+ retval.append(QString::number(m_seconds));
+
+ if(m_mseconds)
+ retval.append(serializeMSeconds(m_mseconds));
+
+ retval.append(QLatin1Char('S'));
+ }
+ else if(!m_days && !m_hours && !m_minutes)
+ retval.append(QLatin1String("0S"));
+
+ return retval;
+}
+
+AbstractDuration::Value DayTimeDuration::value() const
+{
+ return ((m_days * 24 * 60 * 60 * 1000) +
+ (m_hours * 60 * 60 * 1000) +
+ (m_minutes * 60 * 1000) +
+ (m_seconds * 1000) +
+ m_mseconds) * (m_isPositive ? 1 : -1);
+}
+
+Item DayTimeDuration::fromValue(const Value val) const
+{
+ if(val == 0)
+ return toItem(CommonValues::DayTimeDurationZero);
+ else
+ return toItem(fromSeconds(val / 1000, qAbs(val) % 1000));
+}
+
+ItemType::Ptr DayTimeDuration::type() const
+{
+ return BuiltinTypes::xsDayTimeDuration;
+}
+
+YearProperty DayTimeDuration::years() const
+{
+ return 0;
+}
+
+MonthProperty DayTimeDuration::months() const
+{
+ return 0;
+}
+
+DayCountProperty DayTimeDuration::days() const
+{
+ return m_days;
+}
+
+HourProperty DayTimeDuration::hours() const
+{
+ return m_hours;
+}
+
+MinuteProperty DayTimeDuration::minutes() const
+{
+ return m_minutes;
+}
+
+SecondProperty DayTimeDuration::seconds() const
+{
+ return m_seconds;
+}
+
+MSecondProperty DayTimeDuration::mseconds() const
+{
+ return m_mseconds;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qdaytimeduration_p.h b/src/xmlpatterns/data/qdaytimeduration_p.h
new file mode 100644
index 0000000..f6a3117
--- /dev/null
+++ b/src/xmlpatterns/data/qdaytimeduration_p.h
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_DayTimeDuration_H
+#define Patternist_DayTimeDuration_H
+
+#include "qabstractduration_p.h"
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:dayTimeDuration type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class DayTimeDuration : public AbstractDuration
+ {
+ public:
+
+ typedef QExplicitlySharedDataPointer<DayTimeDuration> Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static DayTimeDuration::Ptr fromLexical(const QString &string);
+
+ static DayTimeDuration::Ptr fromComponents(const bool isPositive,
+ const DayCountProperty days,
+ const HourProperty hours,
+ const MinuteProperty minutes,
+ const SecondProperty seconds,
+ const MSecondProperty mseconds);
+ /**
+ * Creates a DayTimeDuration that has the value expressed in seconds @p secs
+ * and milli seconds @p msecs. The signedness of @p secs communicates
+ * whether this DayTimeDuration is positive or negative. @p msecs must always
+ * be positive.
+ */
+ static DayTimeDuration::Ptr fromSeconds(const SecondCountProperty secs,
+ const MSecondProperty msecs = 0);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual YearProperty years() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual MonthProperty months() const;
+ virtual DayCountProperty days() const;
+ virtual HourProperty hours() const;
+ virtual MinuteProperty minutes() const;
+ virtual MSecondProperty mseconds() const;
+ virtual SecondProperty seconds() const;
+
+ /**
+ * @returns the value of this xs:dayTimeDuration
+ * in milli seconds.
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#dt-dayTimeDuration">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 10.3.2.2 Calculating the value of a
+ * xs:dayTimeDuration from the lexical representation</a>
+ */
+ virtual Value value() const;
+
+ /**
+ * Creates a DayTimeDuration containing the value @p val. @p val is
+ * expressed in milli seconds.
+ *
+ * If @p val is zero, is CommonValues::DayTimeDurationZero returned.
+ */
+ virtual Item fromValue(const Value val) const;
+
+ protected:
+ friend class CommonValues;
+
+ DayTimeDuration(const bool isPositive,
+ const DayCountProperty days,
+ const HourProperty hours,
+ const MinuteProperty minutes,
+ const SecondProperty seconds,
+ const MSecondProperty mseconds);
+
+ private:
+ const DayCountProperty m_days;
+ const HourProperty m_hours;
+ const MinuteProperty m_minutes;
+ const SecondProperty m_seconds;
+ const MSecondProperty m_mseconds;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qdecimal.cpp b/src/xmlpatterns/data/qdecimal.cpp
new file mode 100644
index 0000000..05f84b4
--- /dev/null
+++ b/src/xmlpatterns/data/qdecimal.cpp
@@ -0,0 +1,234 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <math.h>
+
+#include "qabstractfloat_p.h"
+#include "qatomictype_p.h"
+#include "qbuiltintypes_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qdecimal_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Decimal::Decimal(const xsDecimal num) : m_value(num)
+{
+}
+
+Decimal::Ptr Decimal::fromValue(const xsDecimal num)
+{
+ return Decimal::Ptr(new Decimal(num));
+}
+
+AtomicValue::Ptr Decimal::fromLexical(const QString &strNumeric)
+{
+ /* QString::toDouble() handles the whitespace facet. */
+ const QString strNumericTrimmed(strNumeric.trimmed());
+
+ /* Block these out, as QString::toDouble() supports them. */
+ if(strNumericTrimmed.compare(QLatin1String("-INF"), Qt::CaseInsensitive) == 0
+ || strNumericTrimmed.compare(QLatin1String("INF"), Qt::CaseInsensitive) == 0
+ || strNumericTrimmed.compare(QLatin1String("+INF"), Qt::CaseInsensitive) == 0
+ || strNumericTrimmed.compare(QLatin1String("nan"), Qt::CaseInsensitive) == 0
+ || strNumericTrimmed.contains(QLatin1Char('e'))
+ || strNumericTrimmed.contains(QLatin1Char('E')))
+ {
+ return ValidationError::createError();
+ }
+
+ bool conversionOk = false;
+ const xsDecimal num = strNumericTrimmed.toDouble(&conversionOk);
+
+ if(conversionOk)
+ return AtomicValue::Ptr(new Decimal(num));
+ else
+ return ValidationError::createError();
+}
+
+bool Decimal::evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return !Double::isEqual(m_value, 0.0);
+}
+
+QString Decimal::stringValue() const
+{
+ return toString(m_value);
+}
+
+QString Decimal::toString(const xsDecimal value)
+{
+ /*
+ * If SV is in the value space of xs:integer, that is, if there are no
+ * significant digits after the decimal point, then the value is converted
+ * from an xs:decimal to an xs:integer and the resulting xs:integer is
+ * converted to an xs:string using the rule above.
+ */
+ if(Double::isEqual(::floor(value), value))
+ {
+ /* The static_cast is identical to Integer::toInteger(). */
+ return QString::number(static_cast<xsInteger>(value));
+ }
+ else
+ {
+ int sign;
+ int decimalPoint;
+ char *result = 0;
+ static_cast<void>(qdtoa(value, 0, 0, &decimalPoint, &sign, 0, &result));
+ /* If the copy constructor is used instead of QString::operator=(),
+ * it doesn't compile. I have no idea why. */
+ const QString qret(QString::fromLatin1(result));
+ delete result;
+
+ QString valueAsString;
+
+ if(sign)
+ valueAsString += QLatin1Char('-');
+
+ if(0 < decimalPoint)
+ {
+ valueAsString += qret.left(decimalPoint);
+ valueAsString += QLatin1Char('.');
+ if (qret.size() <= decimalPoint)
+ valueAsString += QLatin1Char('0');
+ else
+ valueAsString += qret.mid(decimalPoint);
+ }
+ else
+ {
+ valueAsString += QLatin1Char('0');
+ valueAsString += QLatin1Char('.');
+
+ for(int d = decimalPoint; d < 0; d++)
+ valueAsString += QLatin1Char('0');
+
+ valueAsString += qret;
+ }
+
+ return valueAsString;
+ }
+}
+
+ItemType::Ptr Decimal::type() const
+{
+ return BuiltinTypes::xsDecimal;
+}
+
+xsDouble Decimal::toDouble() const
+{
+ return static_cast<xsDouble>(m_value);
+}
+
+xsInteger Decimal::toInteger() const
+{
+ return static_cast<xsInteger>(m_value);
+}
+
+xsFloat Decimal::toFloat() const
+{
+ return static_cast<xsFloat>(m_value);
+}
+
+xsDecimal Decimal::toDecimal() const
+{
+ return m_value;
+}
+
+qulonglong Decimal::toUnsignedInteger() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function, see Numeric::toUnsignedInteger().");
+ return 0;
+}
+
+Numeric::Ptr Decimal::round() const
+{
+ return Numeric::Ptr(new Decimal(roundFloat(m_value)));
+}
+
+Numeric::Ptr Decimal::roundHalfToEven(const xsInteger /*scale*/) const
+{
+ return Numeric::Ptr();
+}
+
+Numeric::Ptr Decimal::floor() const
+{
+ return Numeric::Ptr(new Decimal(static_cast<xsDecimal>(::floor(m_value))));
+}
+
+Numeric::Ptr Decimal::ceiling() const
+{
+ return Numeric::Ptr(new Decimal(static_cast<xsDecimal>(ceil(m_value))));
+}
+
+Numeric::Ptr Decimal::abs() const
+{
+ return Numeric::Ptr(new Decimal(static_cast<xsDecimal>(fabs(m_value))));
+}
+
+bool Decimal::isNaN() const
+{
+ return false;
+}
+
+bool Decimal::isInf() const
+{
+ return false;
+}
+
+Item Decimal::toNegated() const
+{
+ if(AbstractFloat<true>::isEqual(m_value, 0.0))
+ return fromValue(0).data();
+ else
+ return fromValue(-m_value).data();
+}
+
+bool Decimal::isSigned() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function, see Numeric::isSigned().");
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qdecimal_p.h b/src/xmlpatterns/data/qdecimal_p.h
new file mode 100644
index 0000000..2552b21
--- /dev/null
+++ b/src/xmlpatterns/data/qdecimal_p.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Decimal_H
+#define Patternist_Decimal_H
+
+#include "qschemanumeric_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+/**
+ * Defined in QtCore's qlocale.cpp.
+ */
+extern char *qdtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp);
+
+namespace QPatternist
+{
+
+ /**
+ * @short Implements the value instance of the @c xs:decimal type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing/incomplete
+ */
+ class Decimal : public Numeric
+ {
+ public:
+
+ static Decimal::Ptr fromValue(const xsDecimal num);
+
+ /**
+ * Creates a Decimal from the lexical representation of @c xs:decimal stored in
+ * @p strNumeric.
+ *
+ * A possible optimization is to create an Integer if the string ends
+ * with ".0". But this is not conformant. For example, the user writes N.0
+ * which according to the specification is an xs:decimal, but where the
+ * expression is, is an xs:integer is required. That would pass with
+ * such an optimization.
+ */
+ static AtomicValue::Ptr fromLexical(const QString &strNumeric);
+
+ /**
+ * Gets the Effective %Boolean Value of this number.
+ *
+ * @returns @c false if the number is 0 or @c NaN, otherwise @c true.
+ */
+ bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const;
+
+ virtual QString stringValue() const;
+
+ /**
+ * @returns always BuiltinTypes::xsDecimal
+ */
+ virtual ItemType::Ptr type() const;
+
+ virtual xsDouble toDouble() const;
+ virtual xsInteger toInteger() const;
+ virtual xsFloat toFloat() const;
+ virtual xsDecimal toDecimal() const;
+ virtual qulonglong toUnsignedInteger() const;
+
+ virtual Numeric::Ptr round() const;
+ virtual Numeric::Ptr roundHalfToEven(const xsInteger scale) const;
+ virtual Numeric::Ptr floor() const;
+ virtual Numeric::Ptr ceiling() const;
+ virtual Numeric::Ptr abs() const;
+
+ /**
+ * @returns always @c false, xs:decimal doesn't have
+ * not-a-number in its value space.
+ */
+ virtual bool isNaN() const;
+
+ /**
+ * @returns always @c false, xs:decimal doesn't have
+ * infinity in its value space.
+ */
+ virtual bool isInf() const;
+
+ virtual Item toNegated() const;
+
+ /**
+ * Converts @p value into a canonical string representation for @c xs:decimal. This
+ * function is used internally by various classes. Users probably wants to call
+ * stringValue() which in turn calls this function.
+ */
+ static QString toString(const xsDecimal value);
+
+ virtual bool isSigned() const;
+
+ protected:
+
+ Decimal(const xsDecimal num);
+
+ private:
+ const xsDecimal m_value;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qderivedinteger_p.h b/src/xmlpatterns/data/qderivedinteger_p.h
new file mode 100644
index 0000000..4a394b3
--- /dev/null
+++ b/src/xmlpatterns/data/qderivedinteger_p.h
@@ -0,0 +1,624 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_DerivedInteger_H
+#define Patternist_DerivedInteger_H
+
+#include "qbuiltintypes_p.h"
+#include "qinteger_p.h"
+#include "qpatternistlocale_p.h"
+#include "qvalidationerror_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @relates DerivedInteger
+ */
+ enum DerivedIntegerLimitsUsage
+ {
+ None = 1,
+ LimitUpwards = 2,
+ LimitDownwards = 4,
+ LimitBoth = LimitUpwards | LimitDownwards
+ };
+
+ enum
+ {
+ IgnorableSignedValue = 0,
+ IgnorableUnsignedValue = 0
+ };
+
+ template<TypeOfDerivedInteger DerivedType> class DerivedInteger;
+
+ template<TypeOfDerivedInteger DerivedType> class DerivedIntegerDetails;
+
+ template<>
+ class DerivedIntegerDetails<TypeByte>
+ {
+ private:
+ friend class DerivedInteger<TypeByte>;
+ typedef qint8 StorageType;
+ typedef xsInteger TemporaryStorageType;
+ static const StorageType maxInclusive = 127;
+ static const StorageType minInclusive = -128;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeInt>
+ {
+ private:
+ friend class DerivedInteger<TypeInt>;
+ typedef qint32 StorageType;
+ typedef xsInteger TemporaryStorageType;
+ static const StorageType maxInclusive = Q_INT64_C(2147483647);
+ static const StorageType minInclusive = Q_INT64_C(-2147483648);
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeLong>
+ {
+ private:
+ friend class DerivedInteger<TypeLong>;
+ typedef qint64 StorageType;
+ typedef StorageType TemporaryStorageType;
+ static const StorageType maxInclusive = Q_INT64_C(9223372036854775807);
+
+ /**
+ * This messy arithmetic expression ensures that we don't get a warning
+ * on neither GCC nor MSVC.
+ */
+ static const StorageType minInclusive = -(Q_INT64_C(9223372036854775807)) - 1;
+
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeNegativeInteger>
+ {
+ private:
+ friend class DerivedInteger<TypeNegativeInteger>;
+ typedef xsInteger StorageType;
+ typedef StorageType TemporaryStorageType;
+ static const StorageType maxInclusive = -1;
+ static const StorageType minInclusive = IgnorableSignedValue;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitUpwards;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeNonNegativeInteger>
+ {
+ private:
+ friend class DerivedInteger<TypeNonNegativeInteger>;
+ typedef xsInteger StorageType;
+ typedef StorageType TemporaryStorageType;
+ static const StorageType maxInclusive = IgnorableSignedValue;
+ static const StorageType minInclusive = 0;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitDownwards;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeNonPositiveInteger>
+ {
+ private:
+ friend class DerivedInteger<TypeNonPositiveInteger>;
+ typedef xsInteger StorageType;
+ typedef StorageType TemporaryStorageType;
+ static const StorageType maxInclusive = 0;
+ static const StorageType minInclusive = IgnorableSignedValue;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitUpwards;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypePositiveInteger>
+ {
+ private:
+ friend class DerivedInteger<TypePositiveInteger>;
+ typedef xsInteger StorageType;
+ typedef StorageType TemporaryStorageType;
+ static const StorageType maxInclusive = IgnorableSignedValue;
+ static const StorageType minInclusive = 1;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitDownwards;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeShort>
+ {
+ private:
+ friend class DerivedInteger<TypeShort>;
+ typedef qint16 StorageType;
+ typedef xsInteger TemporaryStorageType;
+ static const StorageType maxInclusive = 32767;
+ static const StorageType minInclusive = -32768;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeUnsignedByte>
+ {
+ private:
+ friend class DerivedInteger<TypeUnsignedByte>;
+ typedef quint8 StorageType;
+ typedef qint64 TemporaryStorageType;
+ static const StorageType maxInclusive = 255;
+ static const StorageType minInclusive = 0;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeUnsignedInt>
+ {
+ private:
+ friend class DerivedInteger<TypeUnsignedInt>;
+ typedef quint32 StorageType;
+ typedef qint64 TemporaryStorageType;
+ static const StorageType maxInclusive = Q_UINT64_C(4294967295);
+ static const StorageType minInclusive = 0;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeUnsignedLong>
+ {
+ private:
+ friend class DerivedInteger<TypeUnsignedLong>;
+ typedef quint64 StorageType;
+ typedef StorageType TemporaryStorageType;
+ static const StorageType maxInclusive = Q_UINT64_C(18446744073709551615);
+ static const StorageType minInclusive = 0;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ template<>
+ class DerivedIntegerDetails<TypeUnsignedShort>
+ {
+ private:
+ friend class DerivedInteger<TypeUnsignedShort>;
+ typedef quint16 StorageType;
+ typedef qint64 TemporaryStorageType;
+ static const StorageType maxInclusive = 65535;
+ static const StorageType minInclusive = 0;
+ static const DerivedIntegerLimitsUsage limitsUsage = LimitBoth;
+
+ /**
+ * Disable the default constructor.
+ */
+ DerivedIntegerDetails() {}
+
+ Q_DISABLE_COPY(DerivedIntegerDetails)
+ };
+
+ /**
+ * @short Represents instances of derived @c xs:integer types, such as @c
+ * xs:byte.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ template<TypeOfDerivedInteger DerivedType>
+ class DerivedInteger : public Numeric
+ {
+ private:
+ typedef typename DerivedIntegerDetails<DerivedType>::StorageType StorageType;
+ typedef typename DerivedIntegerDetails<DerivedType>::TemporaryStorageType TemporaryStorageType;
+
+ static const StorageType maxInclusive = DerivedIntegerDetails<DerivedType>::maxInclusive;
+ static const StorageType minInclusive = DerivedIntegerDetails<DerivedType>::minInclusive;
+ static const DerivedIntegerLimitsUsage limitsUsage = DerivedIntegerDetails<DerivedType>::limitsUsage;
+
+ const StorageType m_value;
+
+ inline DerivedInteger(const StorageType num) : m_value(num)
+ {
+ }
+
+ /**
+ * By refactoring out the simple comparison below into a template
+ * function, we avoid the warning "warning: comparison of unsigned expression < 0 is always false" with gcc
+ * when the class is instantiated with TypeUnsignedLong. The warning is
+ * a false positive since we check wehther LimitUpwards is set before
+ * instantiating.
+ *
+ * This template function exists for no other reason. */
+ template<typename A, typename B>
+ static bool lessThan(const A &a, const B &b)
+ {
+ return a < b;
+ }
+
+ /**
+ * This function exists for the same reason that lessThan() do.
+ */
+ template<typename A, typename B>
+ static bool largerOrEqual(const A &a, const B &b)
+ {
+ return qint64(a) >= b;
+ }
+
+ public:
+
+ static ItemType::Ptr itemType()
+ {
+ switch(DerivedType)
+ {
+ case TypeByte: return BuiltinTypes::xsByte;
+ case TypeInt: return BuiltinTypes::xsInt;
+ case TypeLong: return BuiltinTypes::xsLong;
+ case TypeNegativeInteger: return BuiltinTypes::xsNegativeInteger;
+ case TypeNonNegativeInteger: return BuiltinTypes::xsNonNegativeInteger;
+ case TypeNonPositiveInteger: return BuiltinTypes::xsNonPositiveInteger;
+ case TypePositiveInteger: return BuiltinTypes::xsPositiveInteger;
+ case TypeShort: return BuiltinTypes::xsShort;
+ case TypeUnsignedByte: return BuiltinTypes::xsUnsignedByte;
+ case TypeUnsignedInt: return BuiltinTypes::xsUnsignedInt;
+ case TypeUnsignedLong: return BuiltinTypes::xsUnsignedLong;
+ case TypeUnsignedShort: return BuiltinTypes::xsUnsignedShort;
+ }
+
+ Q_ASSERT(false);
+ return ItemType::Ptr();
+ }
+
+ static AtomicValue::Ptr fromValue(const NamePool::Ptr &np, const TemporaryStorageType num)
+ {
+ /* If we use minInclusive when calling lessThan(), we for some
+ * reason get a linker error with GCC. Using this temporary
+ * variable solves it. */
+ const StorageType minimum = minInclusive;
+
+ if((limitsUsage & LimitUpwards) &&
+ num > maxInclusive)
+ {
+ return ValidationError::createError(QtXmlPatterns::tr(
+ "Value %1 of type %2 exceeds maximum (%3).")
+ .arg(formatData(static_cast<xsInteger>(num)))
+ .arg(formatType(np, itemType()))
+ .arg(formatData(static_cast<xsInteger>(maxInclusive))));
+ }
+ else if((limitsUsage & LimitDownwards) &&
+ lessThan(num, minimum))
+ {
+ return ValidationError::createError(QtXmlPatterns::tr(
+ "Value %1 of type %2 is below minimum (%3).")
+ .arg(formatData(static_cast<xsInteger>(num)))
+ .arg(formatType(np, itemType()))
+ .arg(formatData(static_cast<xsInteger>(minInclusive))));
+ }
+ else
+ return AtomicValue::Ptr(new DerivedInteger(num));
+ }
+
+ static AtomicValue::Ptr fromValueUnchecked(const TemporaryStorageType num)
+ {
+ return AtomicValue::Ptr(new DerivedInteger(num));
+ }
+
+ /**
+ * Constructs an instance from the lexical
+ * representation @p strNumeric.
+ */
+ static AtomicValue::Ptr fromLexical(const NamePool::Ptr &np, const QString &strNumeric)
+ {
+ bool conversionOk = false;
+ TemporaryStorageType num;
+
+ /* Depending on the type, we need to call different conversion
+ * functions on QString. */
+ switch(DerivedType)
+ {
+ case TypeUnsignedLong:
+ {
+ /* Qt decides to flag '-' as invalid, so remove it before. */
+ if(strNumeric.contains(QLatin1Char('-')))
+ {
+ num = QString(strNumeric).remove(QLatin1Char('-')).toULongLong(&conversionOk);
+
+ if(num != 0)
+ conversionOk = false;
+ }
+ else
+ num = strNumeric.toULongLong(&conversionOk);
+
+ break;
+ }
+ default:
+ {
+ num = strNumeric.toLongLong(&conversionOk);
+ break;
+ }
+ }
+
+ if(conversionOk)
+ return fromValue(np, num);
+ else
+ return ValidationError::createError();
+ }
+
+ inline StorageType storedValue() const
+ {
+ return m_value;
+ }
+
+ /**
+ * Determines the Effective %Boolean Value of this number.
+ *
+ * @returns @c false if the number is 0, otherwise @c true.
+ */
+ bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+ {
+ return m_value != 0;
+ }
+
+ virtual QString stringValue() const
+ {
+ return QString::number(m_value);
+ }
+
+ virtual ItemType::Ptr type() const
+ {
+ return itemType();
+ }
+
+ virtual xsDouble toDouble() const
+ {
+ return static_cast<xsDouble>(m_value);
+ }
+
+ virtual xsInteger toInteger() const
+ {
+ return m_value;
+ }
+
+ virtual xsFloat toFloat() const
+ {
+ return static_cast<xsFloat>(m_value);
+ }
+
+ virtual xsDecimal toDecimal() const
+ {
+ return static_cast<xsDecimal>(m_value);
+ }
+
+ virtual Numeric::Ptr round() const
+ {
+ /* xs:integerS never have a mantissa. */
+ return Numeric::Ptr(static_cast<Numeric *>(const_cast<AtomicValue *>(Integer::fromValue(m_value).asAtomicValue())));
+ }
+
+ virtual Numeric::Ptr roundHalfToEven(const xsInteger) const
+ {
+ return Numeric::Ptr(static_cast<Numeric *>(const_cast<AtomicValue *>(Integer::fromValue(m_value).asAtomicValue())));
+ }
+
+ virtual Numeric::Ptr floor() const
+ {
+ return Numeric::Ptr(static_cast<Numeric *>(const_cast<AtomicValue *>(Integer::fromValue(m_value).asAtomicValue())));
+ }
+
+ virtual Numeric::Ptr ceiling() const
+ {
+ return Numeric::Ptr(static_cast<Numeric *>(const_cast<AtomicValue *>(Integer::fromValue(m_value).asAtomicValue())));
+ }
+
+ virtual Numeric::Ptr abs() const
+ {
+ /* We unconditionally create an Integer even if we're a positive
+ * value, because one part of this is the type change to
+ * xs:integer.
+ *
+ * We've manually inlined qAbs() and invoke xsInteger's
+ * constructor. The reason being that we other gets truncation down
+ * to StorageType. See for instance XQTS test case absint1args-1. */
+ return Numeric::Ptr(static_cast<Numeric *>(const_cast<AtomicValue *>(Integer::fromValue(largerOrEqual(m_value, 0) ? xsInteger(m_value) : -xsInteger(m_value)).asAtomicValue())));
+ }
+
+ /**
+ * @returns always @c false, @c xs:DerivedInteger doesn't have
+ * not-a-number in its value space.
+ */
+ virtual bool isNaN() const
+ {
+ return false;
+ }
+
+ /**
+ * @returns always @c false, @c xs:DerivedInteger doesn't have
+ * infinity in its value space.
+ */
+ virtual bool isInf() const
+ {
+ return false;
+ }
+
+ virtual Item toNegated() const
+ {
+ return Integer::fromValue(-xsInteger(m_value));
+ }
+
+ virtual bool isSigned() const
+ {
+ switch(DerivedType)
+ {
+ /* Fallthrough all these. */
+ case TypeByte:
+ case TypeInt:
+ case TypeLong:
+ case TypeNegativeInteger:
+ case TypeNonNegativeInteger:
+ case TypeNonPositiveInteger:
+ case TypePositiveInteger:
+ case TypeShort:
+ return true;
+ /* Fallthrough all these. */
+ case TypeUnsignedByte:
+ case TypeUnsignedInt:
+ case TypeUnsignedLong:
+ case TypeUnsignedShort:
+ return false;
+ }
+ return false;
+ }
+
+ virtual qulonglong toUnsignedInteger() const
+ {
+ switch(DerivedType)
+ {
+ /* Fallthrough all these. */
+ case TypeByte:
+ case TypeInt:
+ case TypeLong:
+ case TypeNegativeInteger:
+ case TypeNonNegativeInteger:
+ case TypeNonPositiveInteger:
+ case TypePositiveInteger:
+ case TypeShort:
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function, see Numeric::toUnsignedInteger().");
+ /* Fallthrough all these. */
+ case TypeUnsignedByte:
+ case TypeUnsignedInt:
+ case TypeUnsignedLong:
+ case TypeUnsignedShort:
+ return m_value;
+ }
+ return 0;
+ }
+
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qderivedstring_p.h b/src/xmlpatterns/data/qderivedstring_p.h
new file mode 100644
index 0000000..a9d4f16
--- /dev/null
+++ b/src/xmlpatterns/data/qderivedstring_p.h
@@ -0,0 +1,341 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_DerivedString_H
+#define Patternist_DerivedString_H
+
+#include <QRegExp>
+
+#include "private/qxmlutils_p.h"
+#include "qbuiltintypes_p.h"
+#include "qpatternistlocale_p.h"
+#include "qvalidationerror_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Represents instances of derived @c xs:string types, such as @c
+ * xs:normalizedString.
+ *
+ * Whitespace is a significant part for creating values from the lexical
+ * space. Of course the specification is tricky here. Here's some pointers:
+ *
+ * - From <a href="4.3.6.1 The whiteSpace Schema Component">XML Schema Part 2: Datatypes
+ * Second Edition, 4.3.6 whiteSpace</a>:
+ * "For all atomic datatypes other than string (and types
+ * derived by restriction from it) the value of whiteSpace is
+ * collapse and cannot be changed by a schema author; for string the
+ * value of whiteSpace is preserve; for any type derived by
+ * restriction from string the value of whiteSpace can be any of the
+ * three legal values."
+ * - From <a href="http://www.w3.org/TR/xmlschema-1/#d0e1654">XML Schema Part 1: Structures
+ * Second Edition, 3.1.4 White Space Normalization during Validation</a>:
+ * "[Definition:] The normalized value of an element or attribute
+ * information item is an initial value whose white space, if any,
+ * has been normalized according to the value of the whiteSpace facet of
+ * the simple type definition used in its validation."
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing
+ */
+ template<TypeOfDerivedString DerivedType>
+ class DerivedString : public AtomicValue
+ {
+ private:
+ static inline ItemType::Ptr itemType()
+ {
+ switch(DerivedType)
+ {
+ case TypeNormalizedString: return BuiltinTypes::xsNormalizedString;
+ case TypeToken: return BuiltinTypes::xsToken;
+ case TypeLanguage: return BuiltinTypes::xsLanguage;
+ case TypeNMTOKEN: return BuiltinTypes::xsNMTOKEN;
+ case TypeName: return BuiltinTypes::xsName;
+ case TypeNCName: return BuiltinTypes::xsNCName;
+ case TypeID: return BuiltinTypes::xsID;
+ case TypeIDREF: return BuiltinTypes::xsIDREF;
+ case TypeENTITY: return BuiltinTypes::xsENTITY;
+ case TypeString: return BuiltinTypes::xsString;
+ }
+
+ Q_ASSERT_X(false, Q_FUNC_INFO, "This line is not supposed to be reached.");
+ return ItemType::Ptr();
+ }
+
+ const QString m_value;
+
+ inline DerivedString(const QString &value) : m_value(value)
+ {
+ }
+
+ /**
+ * @short This is an incomplete test for whether @p ch conforms to
+ * the XML 1.0 NameChar production.
+ */
+ static inline bool isNameChar(const QChar &ch)
+ {
+ return ch.isLetter() ||
+ ch.isDigit() ||
+ ch == QLatin1Char('.') ||
+ ch == QLatin1Char('-') ||
+ ch == QLatin1Char('_') ||
+ ch == QLatin1Char(':');
+ }
+
+ /**
+ * @returns @c true if @p input is a valid @c xs:Name.
+ * @see <a href="http://www.w3.org/TR/REC-xml/#NT-Name">Extensible
+ * Markup Language (XML) 1.0 (Fourth Edition), [5] Name</a>
+ */
+ static inline bool isValidName(const QString &input)
+ {
+ if(input.isEmpty())
+ return false;
+
+ const QChar first(input.at(0));
+
+ if(first.isLetter() ||
+ first == QLatin1Char('_') ||
+ first == QLatin1Char(':'))
+ {
+ const int len = input.length();
+
+ if(len == 1)
+ return true;
+
+ /* Since we've checked the first character above, we start at
+ * position 1. */
+ for(int i = 1; i < len; ++i)
+ {
+ if(!isNameChar(input.at(i)))
+ return false;
+ }
+
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @returns @c true if @p input conforms to the XML 1.0 @c Nmtoken product.
+ *
+ * @see <a
+ * href="http://www.w3.org/TR/2000/WD-xml-2e-20000814#NT-Nmtoken">Extensible
+ * Markup Language (XML) 1.0 (Second Edition), [7] Nmtoken</a>
+ */
+ static inline bool isValidNMTOKEN(const QString &input)
+ {
+ const int len = input.length();
+
+ if(len == 0)
+ return false;
+
+ for(int i = 0; i < len; ++i)
+ {
+ if(!isNameChar(input.at(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @short Performs attribute value normalization as if @p input was not
+ * from a @c CDATA section.
+ *
+ * Each whitespace character in @p input that's not a space, such as tab
+ * or new line character, is replaced with a space. This algorithm
+ * differs from QString::simplified() in that it doesn't collapse
+ * subsequent whitespace characters to a single one, or remove trailing
+ * and leading space.
+ *
+ * @see <a href="http://www.w3.org/TR/REC-xml/#AVNormalize">Extensible
+ * Markup Language (XML) 1.0 (Second Edition), 3.3.3 [E70]Attribute-Value Normalization</a>
+ */
+ static QString attributeNormalize(const QString &input)
+ {
+ QString retval(input);
+ const int len = retval.length();
+ const QLatin1Char space(' ');
+
+ for(int i = 0; i < len; ++i)
+ {
+ const QChar ati(retval.at(i));
+
+ if(ati.isSpace() && ati != space)
+ retval[i] = space;
+ }
+
+ return retval;
+ }
+
+ static AtomicValue::Ptr error(const NamePool::Ptr &np, const QString &invalidValue)
+ {
+ return ValidationError::createError(QString::fromLatin1("%1 is not a valid value for "
+ "type %2.").arg(formatData(invalidValue))
+ .arg(formatType(np, itemType())));
+ }
+
+ public:
+
+ /**
+ * @note This function doesn't perform any cleanup/normalizaiton of @p
+ * value. @p value must be a canonical value space of the type.
+ *
+ * If you want cleanup to be performed and/or the lexical space
+ * checked, use fromLexical().
+ */
+ static AtomicValue::Ptr fromValue(const QString &value)
+ {
+ return AtomicValue::Ptr(new DerivedString(value));
+ }
+
+ /**
+ * Constructs an instance from the lexical
+ * representation @p lexical.
+ */
+ static AtomicValue::Ptr fromLexical(const NamePool::Ptr &np, const QString &lexical)
+ {
+ switch(DerivedType)
+ {
+ case TypeString:
+ return AtomicValue::Ptr(new DerivedString(lexical));
+ case TypeNormalizedString:
+ return AtomicValue::Ptr(new DerivedString(attributeNormalize(lexical)));
+ case TypeToken:
+ return AtomicValue::Ptr(new DerivedString(lexical.simplified()));
+ case TypeLanguage:
+ {
+ const QString simplified(lexical.trimmed());
+
+ const QRegExp validate(QLatin1String("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*"));
+ Q_ASSERT(validate.isValid());
+
+ if(validate.exactMatch(simplified))
+ return AtomicValue::Ptr(new DerivedString(lexical.simplified()));
+ else
+ return error(np, simplified);
+ }
+ case TypeNMTOKEN:
+ {
+ const QString trimmed(lexical.trimmed());
+
+ if(isValidNMTOKEN(trimmed))
+ return AtomicValue::Ptr(new DerivedString(trimmed));
+ else
+ return error(np, trimmed);
+ }
+ case TypeName:
+ {
+ const QString simplified(lexical.simplified());
+
+ if(isValidName(simplified))
+ return AtomicValue::Ptr(new DerivedString(simplified));
+ else
+ return error(np, simplified);
+ }
+ case TypeID:
+ /* Fallthrough. */
+ case TypeIDREF:
+ /* Fallthrough. */
+ case TypeENTITY:
+ /* Fallthrough. */
+ case TypeNCName:
+ {
+ /* We treat xs:ID, xs:ENTITY, xs:IDREF and xs:NCName in the exact same
+ * way, except for the type annotation.
+ *
+ * We use trimmed() instead of simplified() because it's
+ * faster and whitespace isn't allowed between
+ * non-whitespace characters anyway, for these types. */
+ const QString trimmed(lexical.trimmed());
+
+ if(QXmlUtils::isNCName(trimmed))
+ return AtomicValue::Ptr(new DerivedString(trimmed));
+ else
+ return error(np, trimmed);
+ }
+ default:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO, "This line is not supposed to be reached.");
+ return AtomicValue::Ptr();
+ }
+ }
+ }
+
+ virtual QString stringValue() const
+ {
+ return m_value;
+ }
+
+ virtual bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+ {
+ return m_value.length() > 0;
+ }
+
+ virtual ItemType::Ptr type() const
+ {
+ return itemType();
+ }
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qduration.cpp b/src/xmlpatterns/data/qduration.cpp
new file mode 100644
index 0000000..c36adc4
--- /dev/null
+++ b/src/xmlpatterns/data/qduration.cpp
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractdatetime_p.h"
+#include "qbuiltintypes_p.h"
+#include "qitem_p.h"
+
+#include "qduration_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Duration::Duration(const bool isPositiveP,
+ const YearProperty yearsP,
+ const MonthProperty monthsP,
+ const DayCountProperty daysP,
+ const HourProperty hoursP,
+ const MinuteProperty mins,
+ const SecondProperty secs,
+ const MSecondProperty msecs) : AbstractDuration(isPositiveP),
+ m_years(yearsP),
+ m_months(monthsP),
+ m_days(daysP),
+ m_hours(hoursP),
+ m_minutes(mins),
+ m_seconds(secs),
+ m_mseconds(msecs)
+{
+}
+
+Duration::Ptr Duration::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable(
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-)?" /* Any minus sign. */
+ "P" /* Delimiter. */
+ "(?:(\\d+)Y)?" /* Year part. */
+ "(?:(\\d+)M)?" /* Month part. */
+ "(?:(\\d+)D)?" /* Day part. */
+ "(?:" /* Here starts the optional time part. */
+ "(T)" /* SchemaTime delimiter. */
+ "(?:(\\d+)H)?" /* Hour part. */
+ "(?:(\\d+)M)?" /* Minute part. */
+ "(?:(\\d+)(?:\\.(\\d+))?S)?" /* Seconds & milli seconds. */
+ ")?" /* End of optional time part. */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*yearP*/ 2,
+ /*monthP*/ 3,
+ /*dayP*/ 4,
+ /*tDelimiterP*/ 5,
+ /*hourP*/ 6,
+ /*minutesP*/ 7,
+ /*secondsP*/ 8,
+ /*msecondsP*/ 9);
+
+ YearProperty years = 0;
+ MonthProperty months = 0;
+ DayCountProperty days = 0;
+ HourProperty hours = 0;
+ MinuteProperty minutes = 0;
+ SecondProperty sec = 0;
+ MSecondProperty msec = 0;
+ bool isPos;
+
+ const AtomicValue::Ptr err(create(captureTable, lexical, &isPos, &years, &months,
+ &days, &hours, &minutes, &sec, &msec));
+
+ return err ? err : Duration::Ptr(new Duration(isPos, years, months, days, hours,
+ minutes, sec, msec));
+}
+
+Duration::Ptr Duration::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)
+{
+ return Duration::Ptr(new Duration(isPositive, years, months, days,
+ hours, minutes, seconds, mseconds));
+}
+
+AbstractDuration::Value Duration::value() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "Calling Duration::value() makes no sense");
+ return 0;
+}
+
+Item Duration::fromValue(const Value) const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "Calling Duration::fromValue() makes no sense");
+ return Item();
+}
+
+QString Duration::stringValue() const
+{
+ QString retval;
+
+ if(!m_isPositive)
+ retval.append(QLatin1Char('-'));
+
+ retval.append(QLatin1Char('P'));
+
+ if(m_years)
+ {
+ retval.append(QString::number(m_years));
+ retval.append(QLatin1Char('Y'));
+ }
+
+ if(m_months)
+ {
+ retval.append(QString::number(m_months));
+ retval.append(QLatin1Char('M'));
+ }
+
+ if(m_days)
+ {
+ retval.append(QString::number(m_days));
+ retval.append(QLatin1Char('D'));
+ }
+
+ if(!m_hours && !m_minutes && !m_seconds && !m_seconds)
+ {
+ if(!m_years && !m_months && !m_days)
+ return QLatin1String("PT0S");
+ else
+ return retval;
+ }
+
+ retval.append(QLatin1Char('T'));
+
+ if(m_hours)
+ {
+ retval.append(QString::number(m_hours));
+ retval.append(QLatin1Char('H'));
+ }
+
+ if(m_minutes)
+ {
+ retval.append(QString::number(m_minutes));
+ retval.append(QLatin1Char('M'));
+ }
+
+ if(m_seconds || m_seconds)
+ {
+ retval.append(QString::number(m_seconds));
+
+ if(m_mseconds)
+ retval.append(serializeMSeconds(m_mseconds));
+
+ retval.append(QLatin1Char('S'));
+ }
+ else if(!m_years && !m_months && !m_days && !m_hours && !m_minutes)
+ retval.append(QLatin1String("0S"));
+
+ return retval;
+}
+
+YearProperty Duration::years() const
+{
+ return m_years;
+}
+
+MonthProperty Duration::months() const
+{
+ return m_months;
+}
+
+DayCountProperty Duration::days() const
+{
+ return m_days;
+}
+
+HourProperty Duration::hours() const
+{
+ return m_hours;
+}
+
+MinuteProperty Duration::minutes() const
+{
+ return m_minutes;
+}
+
+SecondProperty Duration::seconds() const
+{
+ return m_seconds;
+}
+
+MSecondProperty Duration::mseconds() const
+{
+ return m_mseconds;
+}
+
+ItemType::Ptr Duration::type() const
+{
+ return BuiltinTypes::xsDuration;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qduration_p.h b/src/xmlpatterns/data/qduration_p.h
new file mode 100644
index 0000000..fe58317
--- /dev/null
+++ b/src/xmlpatterns/data/qduration_p.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Duration_H
+#define Patternist_Duration_H
+
+#include "qabstractduration_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:duration type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class Duration : public AbstractDuration
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static Duration::Ptr fromLexical(const QString &string);
+ 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);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ /**
+ * Always results in an assert crash. Calling this function makes no
+ * sense due to that the value space of xs:duration is not well defined.
+ */
+ virtual Value value() const;
+
+ /**
+ * Always results in an assert crash. Calling this function makes no
+ * sense due to that the value space of xs:duration is not well defined.
+ */
+ virtual Item fromValue(const Value val) const;
+
+ virtual YearProperty years() const;
+ virtual MonthProperty months() const;
+ virtual DayCountProperty days() const;
+ virtual HourProperty hours() const;
+ virtual MinuteProperty minutes() const;
+ virtual SecondProperty seconds() const;
+ virtual MSecondProperty mseconds() const;
+
+ protected:
+ friend class CommonValues;
+
+ Duration(const bool isPositive,
+ const YearProperty years,
+ const MonthProperty months,
+ const DayCountProperty days,
+ const HourProperty hours,
+ const MinuteProperty minutes,
+ const SecondProperty seconds,
+ const MSecondProperty mseconds);
+ private:
+ const YearProperty m_years;
+ const MonthProperty m_months;
+ const DayCountProperty m_days;
+ const HourProperty m_hours;
+ const MinuteProperty m_minutes;
+ const SecondProperty m_seconds;
+ const MSecondProperty m_mseconds;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qgday.cpp b/src/xmlpatterns/data/qgday.cpp
new file mode 100644
index 0000000..e2bd2e5
--- /dev/null
+++ b/src/xmlpatterns/data/qgday.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qgday_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+GDay::GDay(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+GDay::Ptr GDay::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "---" /* Delimiter. */
+ "(\\d{2})" /* The day part, "03". */
+ "(?:(?:(\\+|-))(\\d{2}):(\\d{2})|(Z))?" /* Timezone, "+08:24". */
+ "\\s*$" /* Any whitespace at the end. */))),
+ /*zoneOffsetSignP*/ 2,
+ /*zoneOffsetHourP*/ 3,
+ /*zoneOffsetMinuteP*/ 4,
+ /*zoneOffsetUTCSymbolP*/ 5,
+ /*yearP*/ -1,
+ /*monthP*/ -1,
+ /*dayP*/ 1);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : GDay::Ptr(new GDay(retval));
+}
+
+GDay::Ptr GDay::fromDateTime(const QDateTime &dt)
+{
+ QDateTime result(QDate(DefaultYear, DefaultMonth, dt.date().day()));
+ copyTimeSpec(dt, result);
+
+ return GDay::Ptr(new GDay(result));
+}
+
+QString GDay::stringValue() const
+{
+ return m_dateTime.toString(QLatin1String("---dd")) + zoneOffsetToString();
+}
+
+ItemType::Ptr GDay::type() const
+{
+ return BuiltinTypes::xsGDay;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qgday_p.h b/src/xmlpatterns/data/qgday_p.h
new file mode 100644
index 0000000..1d69494
--- /dev/null
+++ b/src/xmlpatterns/data/qgday_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_GDay_H
+#define Patternist_GDay_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:gDay type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class GDay : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static GDay::Ptr fromLexical(const QString &string);
+ static GDay::Ptr fromDateTime(const QDateTime &dt);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ protected:
+ friend class CommonValues;
+
+ GDay(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qgmonth.cpp b/src/xmlpatterns/data/qgmonth.cpp
new file mode 100644
index 0000000..ddac353
--- /dev/null
+++ b/src/xmlpatterns/data/qgmonth.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qgmonth_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+GMonth::GMonth(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+GMonth::Ptr GMonth::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "--" /* Delimier. */
+ "(\\d{2})" /* The month part, "03". */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* Timezone, "+08:24". */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*zoneOffsetSignP*/ 2,
+ /*zoneOffsetHourP*/ 3,
+ /*zoneOffsetMinuteP*/ 4,
+ /*zoneOffsetUTCSymbolP*/ 5,
+ /*yearP*/ -1,
+ /*monthP*/ 1);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : GMonth::Ptr(new GMonth(retval));
+}
+
+GMonth::Ptr GMonth::fromDateTime(const QDateTime &dt)
+{
+ QDateTime result(QDate(DefaultYear, dt.date().month(), DefaultDay));
+ copyTimeSpec(dt, result);
+
+ return GMonth::Ptr(new GMonth(result));
+}
+
+QString GMonth::stringValue() const
+{
+ return m_dateTime.toString(QLatin1String("--MM")) + zoneOffsetToString();
+}
+
+ItemType::Ptr GMonth::type() const
+{
+ return BuiltinTypes::xsGMonth;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qgmonth_p.h b/src/xmlpatterns/data/qgmonth_p.h
new file mode 100644
index 0000000..9b1a2c8
--- /dev/null
+++ b/src/xmlpatterns/data/qgmonth_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_GMonth_H
+#define Patternist_GMonth_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:gMonth type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class GMonth : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static GMonth::Ptr fromLexical(const QString &string);
+ static GMonth::Ptr fromDateTime(const QDateTime &dt);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ protected:
+ friend class CommonValues;
+
+ GMonth(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qgmonthday.cpp b/src/xmlpatterns/data/qgmonthday.cpp
new file mode 100644
index 0000000..d7df81b
--- /dev/null
+++ b/src/xmlpatterns/data/qgmonthday.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qgmonthday_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+GMonthDay::GMonthDay(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+GMonthDay::Ptr GMonthDay::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "--" /* Delimiter. */
+ "(\\d{2})" /* The month part. */
+ "-" /* Delimiter. */
+ "(\\d{2})" /* The day part. */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*zoneOffsetSignP*/ 3,
+ /*zoneOffsetHourP*/ 4,
+ /*zoneOffsetMinuteP*/ 5,
+ /*zoneOffsetUTCSymbolP*/ 6,
+ /*yearP*/ -1,
+ /*monthP*/ 1,
+ /*dayP*/ 2);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : GMonthDay::Ptr(new GMonthDay(retval));
+}
+
+GMonthDay::Ptr GMonthDay::fromDateTime(const QDateTime &dt)
+{
+ QDateTime result(QDate(DefaultYear, dt.date().month(), dt.date().day()));
+ copyTimeSpec(dt, result);
+
+ return GMonthDay::Ptr(new GMonthDay(result));
+}
+
+QString GMonthDay::stringValue() const
+{
+ return m_dateTime.toString(QLatin1String("--MM-dd")) + zoneOffsetToString();
+}
+
+ItemType::Ptr GMonthDay::type() const
+{
+ return BuiltinTypes::xsGMonthDay;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qgmonthday_p.h b/src/xmlpatterns/data/qgmonthday_p.h
new file mode 100644
index 0000000..dbb507d
--- /dev/null
+++ b/src/xmlpatterns/data/qgmonthday_p.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_GMonthDay_H
+#define Patternist_GMonthDay_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:gYearMonth type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class GMonthDay : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static GMonthDay::Ptr fromLexical(const QString &string);
+ static GMonthDay::Ptr fromDateTime(const QDateTime &dt);
+
+ virtual ItemType::Ptr type() const;
+
+ virtual QString stringValue() const;
+
+ protected:
+ friend class CommonValues;
+
+ GMonthDay(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qgyear.cpp b/src/xmlpatterns/data/qgyear.cpp
new file mode 100644
index 0000000..a58e1c1
--- /dev/null
+++ b/src/xmlpatterns/data/qgyear.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qgyear_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+GYear::GYear(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+GYear::Ptr GYear::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-?)" /* Any preceding minus. */
+ "(-?\\d{4,})" /* The year part, "1999". */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*zoneOffsetSignP*/ 3,
+ /*zoneOffsetHourP*/ 4,
+ /*zoneOffsetMinuteP*/ 5,
+ /*zoneOffsetUTCSymbolP*/ 6,
+ /*yearP*/ 2,
+ /*monthP*/ -1,
+ /*dayP*/ -1,
+ /*hourP*/ -1,
+ /*minutesP*/ -1,
+ /*secondsP*/ -1,
+ /*msecondsP*/ -1,
+ /*yearSign*/ 1);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : GYear::Ptr(new GYear(retval));
+}
+
+GYear::Ptr GYear::fromDateTime(const QDateTime &dt)
+{
+ QDateTime result(QDate(dt.date().year(), DefaultMonth, DefaultDay));
+ copyTimeSpec(dt, result);
+
+ return GYear::Ptr(new GYear(result));
+}
+
+QString GYear::stringValue() const
+{
+ return m_dateTime.toString(QLatin1String("yyyy")) + zoneOffsetToString();
+}
+
+ItemType::Ptr GYear::type() const
+{
+ return BuiltinTypes::xsGYear;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qgyear_p.h b/src/xmlpatterns/data/qgyear_p.h
new file mode 100644
index 0000000..eef81dc
--- /dev/null
+++ b/src/xmlpatterns/data/qgyear_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_GYear_H
+#define Patternist_GYear_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:gYear type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class GYear : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static GYear::Ptr fromLexical(const QString &string);
+ static GYear::Ptr fromDateTime(const QDateTime &dt);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ protected:
+ friend class CommonValues;
+
+ GYear(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qgyearmonth.cpp b/src/xmlpatterns/data/qgyearmonth.cpp
new file mode 100644
index 0000000..f8f2131
--- /dev/null
+++ b/src/xmlpatterns/data/qgyearmonth.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qgyearmonth_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+GYearMonth::GYearMonth(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+GYearMonth::Ptr GYearMonth::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-?)" /* Any preceding minus. */
+ "(\\d{4,})" /* The year part. */
+ "-" /* Delimiter. */
+ "(\\d{2})" /* The month part. */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*zoneOffsetSignP*/ 4,
+ /*zoneOffsetHourP*/ 5,
+ /*zoneOffsetMinuteP*/ 6,
+ /*zoneOffsetUTCSymbolP*/ 7,
+ /*yearP*/ 2,
+ /*monthP*/ 3,
+ /*dayP*/ -1,
+ /*hourP*/ -1,
+ /*minutesP*/ -1,
+ /*secondsP*/ -1,
+ /*msecondsP*/ -1,
+ /*yearSign*/ 1);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : GYearMonth::Ptr(new GYearMonth(retval));
+}
+
+GYearMonth::Ptr GYearMonth::fromDateTime(const QDateTime &dt)
+{
+ QDateTime result(QDate(dt.date().year(), dt.date().month(), DefaultDay));
+ copyTimeSpec(dt, result);
+
+ return GYearMonth::Ptr(new GYearMonth(result));
+}
+
+QString GYearMonth::stringValue() const
+{
+ return m_dateTime.toString(QLatin1String("yyyy-MM")) + zoneOffsetToString();
+}
+
+ItemType::Ptr GYearMonth::type() const
+{
+ return BuiltinTypes::xsGYearMonth;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qgyearmonth_p.h b/src/xmlpatterns/data/qgyearmonth_p.h
new file mode 100644
index 0000000..134c795
--- /dev/null
+++ b/src/xmlpatterns/data/qgyearmonth_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_GYearMonth_H
+#define Patternist_GYearMonth_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:gYearMonth type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class GYearMonth : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static GYearMonth::Ptr fromLexical(const QString &string);
+ static GYearMonth::Ptr fromDateTime(const QDateTime &dt);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ protected:
+ friend class CommonValues;
+
+ GYearMonth(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qhexbinary.cpp b/src/xmlpatterns/data/qhexbinary.cpp
new file mode 100644
index 0000000..00028e7
--- /dev/null
+++ b/src/xmlpatterns/data/qhexbinary.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGlobal>
+
+#include "qbase64binary_p.h"
+#include "qbuiltintypes_p.h"
+#include "qpatternistlocale_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qhexbinary_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+HexBinary::HexBinary(const QByteArray &val) : Base64Binary(val)
+{
+}
+
+qint8 HexBinary::fromHex(const QChar &c)
+{
+ if(c.unicode() > 'f')
+ return -1;
+
+ const char *const range = "0123456789ABCDEFabcdef";
+
+ const char *const in = strchr(range, c.unicode());
+
+ if(!in)
+ return -1;
+
+ /* Pointer arithmetic. */
+ int digit = in - range;
+
+ if(digit > 15)
+ digit -= 6;
+
+ return digit;
+}
+
+AtomicValue::Ptr HexBinary::fromLexical(const NamePool::Ptr &np, const QString &str)
+{
+ const QString lexical(str.trimmed());
+ const int len = lexical.length();
+
+ if(len == 0)
+ return AtomicValue::Ptr(new HexBinary(QByteArray()));
+
+ if((len & 1) != 0)
+ {
+ /* Catch a common case. */
+ return ValidationError::createError(QtXmlPatterns::tr(
+ "A value of type %1 must contain an even number of "
+ "digits. The value %2 does not.")
+ .arg(formatType(np, BuiltinTypes::xsHexBinary),
+ formatData(QString::number(len))));
+ }
+
+ QByteArray val;
+ val.resize(len / 2);
+
+ for(int i = 0; i < len / 2; ++i)
+ {
+ qint8 p1 = fromHex(lexical[i * 2]);
+ qint8 p2 = fromHex(lexical[i * 2 + 1]);
+
+ if(p1 == -1 || p2 == -1)
+ {
+ const QString hex(QString::fromLatin1("%1%2").arg(lexical[i * 2], lexical[i * 2 + 1]));
+
+ return ValidationError::createError(QtXmlPatterns::tr(
+ "%1 is not valid as a value of type %2.")
+ .arg(formatData(hex),
+ formatType(np, BuiltinTypes::xsHexBinary)));
+ }
+
+ val[i] = static_cast<char>(p1 * 16 + p2);
+ }
+ Q_ASSERT(!val.isEmpty());
+
+ return AtomicValue::Ptr(new HexBinary(val));
+}
+
+HexBinary::Ptr HexBinary::fromValue(const QByteArray &data)
+{
+ return HexBinary::Ptr(new HexBinary(data));
+}
+
+QString HexBinary::stringValue() const
+{
+ static const char s_toHex[] = "0123456789ABCDEF";
+ const int len = m_value.count();
+ QString result;
+ result.reserve(len * 2);
+
+ for(int i = 0; i < len; ++i)
+ {
+ // This cast is significant.
+ const unsigned char val = static_cast<unsigned char>(m_value.at(i));
+ result += QLatin1Char(s_toHex[val >> 4]);
+ result += QLatin1Char(s_toHex[val & 0x0F]);
+ }
+
+ return result;
+}
+
+ItemType::Ptr HexBinary::type() const
+{
+ return BuiltinTypes::xsHexBinary;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qhexbinary_p.h b/src/xmlpatterns/data/qhexbinary_p.h
new file mode 100644
index 0000000..e1a7639
--- /dev/null
+++ b/src/xmlpatterns/data/qhexbinary_p.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_HexBinary_H
+#define Patternist_HexBinary_H
+
+#include "qbase64binary_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+
+ /**
+ * @short Implements the value instance of the @c xs:hexBinary type.
+ *
+ * HexBinary inherits from Base64Binary for implementation reasons. The two
+ * classes are similar, and inheritance therefore save code.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing
+ */
+ class HexBinary : public Base64Binary
+ {
+ public:
+ friend class CommonValues;
+
+ typedef AtomicValue::Ptr Ptr;
+
+ virtual QString stringValue() const;
+ virtual ItemType::Ptr type() const;
+
+ /**
+ * Creates a @c xs:hexBinary from the lexical representation @p value.
+ */
+ static AtomicValue::Ptr fromLexical(const NamePool::Ptr &np, const QString &value);
+
+ /**
+ * Creates an instance representing @p value.
+ */
+ static HexBinary::Ptr fromValue(const QByteArray &data);
+
+ protected:
+ HexBinary(const QByteArray &val);
+
+ private:
+ /**
+ * @short Returns -1 on invalid input.
+ */
+ static inline qint8 fromHex(const QChar &c);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qinteger.cpp b/src/xmlpatterns/data/qinteger.cpp
new file mode 100644
index 0000000..0a8c9cc
--- /dev/null
+++ b/src/xmlpatterns/data/qinteger.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+#include "qitem_p.h"
+#include "qvalidationerror_p.h"
+
+#include "qinteger_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Item Integer::fromValue(const xsInteger num)
+{
+ return toItem(Integer::Ptr(new Integer(num)));
+}
+
+AtomicValue::Ptr Integer::fromLexical(const QString &strNumeric)
+{
+ bool conversionOk = false;
+ const xsInteger num = strNumeric.toLongLong(&conversionOk);
+
+ if(conversionOk)
+ return AtomicValue::Ptr(new Integer(num));
+ else
+ return ValidationError::createError();
+}
+
+Integer::Integer(const xsInteger num) : m_value(num)
+{
+}
+
+bool Integer::evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const
+{
+ return m_value != 0;
+}
+
+QString Integer::stringValue() const
+{
+ return QString::number(m_value);
+}
+
+ItemType::Ptr Integer::type() const
+{
+ return BuiltinTypes::xsInteger;
+}
+
+xsDouble Integer::toDouble() const
+{
+ return static_cast<xsDouble>(m_value);
+}
+
+xsInteger Integer::toInteger() const
+{
+ return m_value;
+}
+
+xsFloat Integer::toFloat() const
+{
+ return static_cast<xsFloat>(m_value);
+}
+
+xsDecimal Integer::toDecimal() const
+{
+ return static_cast<xsDecimal>(m_value);
+}
+
+Numeric::Ptr Integer::round() const
+{
+ /* xs:integerS never has a mantissa. */
+ return Numeric::Ptr(const_cast<Integer *>(this));
+}
+
+Numeric::Ptr Integer::roundHalfToEven(const xsInteger /*scale*/) const
+{
+ return Numeric::Ptr(const_cast<Integer *>(this));
+}
+
+Numeric::Ptr Integer::floor() const
+{
+ return Numeric::Ptr(const_cast<Integer *>(this));
+}
+
+Numeric::Ptr Integer::ceiling() const
+{
+ return Numeric::Ptr(const_cast<Integer *>(this));
+}
+
+Numeric::Ptr Integer::abs() const
+{
+ /* No reason to allocate an Integer if we're already absolute. */
+ if(m_value < 0)
+ return Numeric::Ptr(new Integer(qAbs(m_value)));
+ else
+ return Numeric::Ptr(const_cast<Integer *>(this));
+}
+
+bool Integer::isNaN() const
+{
+ return false;
+}
+
+bool Integer::isInf() const
+{
+ return false;
+}
+
+Item Integer::toNegated() const
+{
+ return fromValue(-m_value);
+}
+
+bool Integer::isSigned() const
+{
+ return true;
+}
+
+qulonglong Integer::toUnsignedInteger() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function, see Numeric::toUnsignedInteger().");
+ return 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qinteger_p.h b/src/xmlpatterns/data/qinteger_p.h
new file mode 100644
index 0000000..c70f04b
--- /dev/null
+++ b/src/xmlpatterns/data/qinteger_p.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Integer_H
+#define Patternist_Integer_H
+
+#include "qschemanumeric_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:integer type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo Documentation is missing
+ */
+ class Integer : public Numeric
+ {
+ public:
+
+ typedef Numeric::Ptr Ptr;
+
+ /**
+ * Constructs an instance from the lexical
+ * representation @p strNumeric.
+ *
+ * @todo Type error handling.
+ */
+ static AtomicValue::Ptr fromLexical(const QString &strNumeric);
+
+ static Item fromValue(const xsInteger num);
+
+ /**
+ * Determines the Effective %Boolean Value of this number.
+ *
+ * @returns @c false if the number is 0, otherwise @c true.
+ */
+ bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &) const;
+
+ virtual QString stringValue() const;
+
+ /**
+ * @returns always BuiltinTypes::xsInteger
+ */
+ virtual ItemType::Ptr type() const;
+
+ virtual xsDouble toDouble() const;
+ virtual xsInteger toInteger() const;
+ virtual xsFloat toFloat() const;
+ virtual xsDecimal toDecimal() const;
+
+ virtual Numeric::Ptr round() const;
+ virtual Numeric::Ptr roundHalfToEven(const xsInteger scale) const;
+ virtual Numeric::Ptr floor() const;
+ virtual Numeric::Ptr ceiling() const;
+ virtual Numeric::Ptr abs() const;
+ virtual qulonglong toUnsignedInteger() const;
+
+ /**
+ * @returns always @c false, @c xs:integer doesn't have
+ * not-a-number in its value space.
+ */
+ virtual bool isNaN() const;
+
+ /**
+ * @returns always @c false, @c xs:integer doesn't have
+ * infinity in its value space.
+ */
+ virtual bool isInf() const;
+ virtual Item toNegated() const;
+
+ /**
+ * @short Returns always @c true.
+ */
+ virtual bool isSigned() const;
+ protected:
+ Integer(const xsInteger num);
+
+ private:
+ const xsInteger m_value;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qitem.cpp b/src/xmlpatterns/data/qitem.cpp
new file mode 100644
index 0000000..eaf47ef
--- /dev/null
+++ b/src/xmlpatterns/data/qitem.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "qitem_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+Item::Iterator::Ptr Item::sequencedTypedValue() const
+{
+ if(isAtomicValue())
+ return makeSingletonIterator(Item(atomicValue));
+ else
+ return asNode().sequencedTypedValue();
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qitem_p.h b/src/xmlpatterns/data/qitem_p.h
new file mode 100644
index 0000000..987a1c2
--- /dev/null
+++ b/src/xmlpatterns/data/qitem_p.h
@@ -0,0 +1,542 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Item_H
+#define Patternist_Item_H
+
+#include <QtXmlPatterns/private/qcppcastinghelper_p.h>
+#include <QtXmlPatterns/private/qitemtype_p.h>
+#include <QtXmlPatterns/private/qsingletoniterator_p.h>
+#include <QtXmlPatterns/QAbstractXmlNodeModel>
+
+#include <QUrl>
+#include <QVariant>
+
+/**
+ * @file
+ * @short Due to strong interdependencies, this file contains the definitions for
+ * the classes Item, QXmlNodeModelIndex, QAbstractXmlNodeModel and AtomicValue. The implementations are
+ * in their respective source files.
+ */
+
+/**
+ * @class QSharedData
+ * @short Qt's base class for reference counting.
+ * @author Trolltech
+ */
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+template<typename T> class QList;
+template<typename T> class QVector;
+template<typename T> class QAbstractXmlForwardIterator;
+
+class QSourceLocation;
+class QAbstractXmlReceiver;
+
+namespace QPatternist
+{
+ class DynamicContext;
+ class Item;
+ class ItemType;
+ class QObjectNodeModel;
+ template<typename T> class EmptyIterator;
+ template<typename T, typename ListType> class ListIterator;
+
+ /**
+ * @short Base class for all classes representing atomic values.
+ *
+ * Instantiating AtomicValues sub classes from a value of somekind,
+ * for a certain type is done in three different ways:
+ *
+ * - The static factory fromLexical which available in most classes. This
+ * function attempts to create a value from a QString that is considered
+ * a lexical representation of the value. Thus, this function performs validation, takes
+ * care of whitespace facets, and everything else related to instantiating a value from
+ * a lexical representation.
+ * - The static factory function fromValue. This function exists for
+ * values where a C++ type exists which corresponds to the type's value space.
+ * - By using instances available in CommonValues. This is the preferred method
+ * since it uses existing singleton instances and thus saves memory. CommonValues
+ * should be used whenever possible, it can be thought as a collection of constant values.
+ *
+ * For types that does not distinguish the value space and lexical space, such as <tt>xs:string</tt>,
+ * only the fromValue() function exist, and fromLexical() is omitted.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class AtomicValue : public QSharedData
+ , public CppCastingHelper<AtomicValue>
+ {
+ public:
+ virtual ~AtomicValue();
+
+ /**
+ * A smart pointer wrapping AtomicValue instances.
+ */
+ typedef QExplicitlySharedDataPointer<AtomicValue> Ptr;
+
+ /**
+ * Determines whether this atomic value has an error. This is used
+ * for implementing casting.
+ *
+ * @returns always @c false
+ */
+ virtual bool hasError() const;
+
+ /**
+ * Always fails by issuing the type error ReportContext::FORG0006. Sub-classes
+ * whose represented type do allow EBV to be extracted from, must thus
+ * re-implement this function.
+ */
+ virtual bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &context) const;
+
+ virtual QString stringValue() const = 0;
+ virtual ItemType::Ptr type() const = 0;
+
+ /**
+ * Converts @p value to a QVariant.
+ */
+ static QVariant toQt(const AtomicValue *const value);
+
+ static inline QVariant toQt(const AtomicValue::Ptr &value)
+ {
+ return toQt(value.data());
+ }
+
+ static Item toXDM(const QVariant &value);
+
+ static ItemType::Ptr qtToXDMType(const QXmlItem &item);
+ protected:
+ inline AtomicValue()
+ {
+ }
+ };
+
+ /**
+ * @short Represents an item in the XPath 2.0 Data Model.
+ *
+ * There exists two types of items: nodes and atomic values.
+ *
+ * The XQuery 1.0 and XPath 2.0 Data Model and XML Path Language (XPath) 2.0 specification
+ * makes a very strong distinction between a sequence of items and an atomized sequence.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Item
+ {
+ friend class QT_PREPEND_NAMESPACE(QXmlItem);
+
+ public:
+ /**
+ * A smart pointer wrapping an Item instance.
+ */
+ typedef QAbstractXmlForwardIterator<Item> Iterator;
+
+ /**
+ * A list of Item instances, each wrapped in a smart pointer.
+ */
+ typedef QList<Item> List;
+
+ /**
+ * A vector of Item instances, each wrapped in a smart pointer.
+ */
+ typedef QVector<Item> Vector;
+
+ typedef QPatternist::SingletonIterator<Item> SingletonIterator;
+ typedef QPatternist::EmptyIterator<Item> EmptyIterator;
+
+ /**
+ * Default constructor.
+ */
+ inline Item()
+ {
+ /* Note that this function should be equal to reset(). */
+
+ /* This is the area which atomicValue uses. Becauase we want as()
+ * to return null on null-constructed objects, we initialize it. */
+ node.data = 0;
+
+ /* This signals that we're not an atomic value. */
+ node.model = 0;
+ }
+
+ inline Item(const QXmlNodeModelIndex &n) : node(n.m_storage)
+ {
+ }
+
+ inline Item(const Item &other) : node(other.node)
+ {
+ Q_ASSERT_X(sizeof(QXmlNodeModelIndex) >= sizeof(AtomicValue), Q_FUNC_INFO,
+ "Since we're only copying the node member, it must be the largest.");
+ if(isAtomicValue())
+ atomicValue->ref.ref();
+ }
+
+ inline Item(const AtomicValue::Ptr &a)
+ {
+ if(a)
+ {
+ atomicValue = a.data();
+ atomicValue->ref.ref();
+
+ /* Signal that we're housing an atomic value. */
+ node.model = reinterpret_cast<const QAbstractXmlNodeModel *>(~0);
+ }
+ else
+ node.model = 0; /* Like the default constructor. */
+ }
+
+ inline Item(const AtomicValue *const a)
+ {
+ /* Note, the implementation is a copy of the constructor above. */
+
+ if(a)
+ {
+ atomicValue = a;
+ atomicValue->ref.ref();
+
+ /* Signal that we're housing an atomic value. */
+ node.model = reinterpret_cast<const QAbstractXmlNodeModel *>(~0);
+ }
+ else
+ node.model = 0; /* Like the default constructor. */
+ }
+
+ inline ~Item()
+ {
+ if(isAtomicValue() && !atomicValue->ref.deref())
+ delete atomicValue;
+ }
+
+ inline Item &operator=(const Item &other)
+ {
+ Q_ASSERT_X(sizeof(QXmlNodeModelIndex) >= sizeof(AtomicValue *), Q_FUNC_INFO,
+ "If this doesn't hold, we won't copy all data.");
+
+ if(other.isAtomicValue())
+ other.atomicValue->ref.ref();
+
+ if(isAtomicValue())
+ {
+ if(!atomicValue->ref.deref())
+ delete atomicValue;
+ }
+
+ node = other.node;
+
+ return *this;
+ }
+
+ template<typename TCastTarget>
+ inline TCastTarget *as() const
+ {
+#if defined(Patternist_DEBUG) && !defined(Q_CC_XLC)
+/* At least on aix-xlc-64, the compiler cries when it sees dynamic_cast. */
+ Q_ASSERT_X(atomicValue == 0 || dynamic_cast<const TCastTarget *>(atomicValue),
+ Q_FUNC_INFO,
+ "The cast is invalid. This class does not inherit the cast target.");
+#endif
+ return const_cast<TCastTarget *>(static_cast<const TCastTarget *>(atomicValue));
+ }
+
+ /**
+ * @short Returns the string value of this Item.
+ *
+ * In the case of a node, it is the node value corresponding to
+ * the particular node type. For atomic values, it is equivalent
+ * to the value cast as <tt>xs:string</tt>.
+ *
+ * Conceptually, this functions corresponds to the <tt>dm:string-value</tt> accessor.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-datamodel/#dm-string-value">XQuery 1.0 and
+ * XPath 2.0 Data Model, 5.13 string-value Accessor</a>
+ * @returns the string value.
+ */
+ inline QString stringValue() const
+ {
+ if(isAtomicValue())
+ return atomicValue->stringValue();
+ else
+ return asNode().stringValue();
+ }
+
+ /**
+ * @short Returns the typed value of this item.
+ *
+ * Conceptually, this functions corresponds to the <tt>dm:typed-value</tt> accessor. Here are
+ * examples of what the typed value of an Item is:
+ *
+ * - The typed value of an atomic value is always the atomic value itself.
+ * - A comment node has always a typed value of type @c xs:string
+ * - For attribute and element nodes, the typed value can be arbitrary. For example, an
+ * element can have a sequence of @c xs:dateTime instances.
+ *
+ * @returns the typed value of this item
+ * @see <a href="http://www.w3.org/TR/xpath-datamodel/#dm-typed-value">XQuery 1.0 and
+ * XPath 2.0 Data Model, 5.15 typed-value Accessor</a>
+ */
+ Item::Iterator::Ptr sequencedTypedValue() const;
+
+ /**
+ * @short Determines whether this item is an atomic value, or a node.
+ *
+ * If this Item is @c null, @c false is returned.
+ *
+ * @see isNode()
+ * @returns @c true if it is an atomic value, otherwise @c false.
+ */
+ inline bool isAtomicValue() const
+ {
+ /* Setting node.model to ~0, signals that it's an atomic value. */
+ return node.model == reinterpret_cast<QAbstractXmlNodeModel *>(~0);
+ }
+
+ /**
+ * @short Determines whether this item is an atomic value, or a node.
+ *
+ * If this Item is @c null, false is returned.
+ *
+ * @see isAtomicValue()
+ * @returns @c true if this item is a node, otherwise @c false.
+ */
+ inline bool isNode() const
+ {
+ //return !isAtomicValue();
+ return node.model && node.model != reinterpret_cast<QAbstractXmlNodeModel *>(~0);
+ }
+
+ /**
+ * @short Returns the ItemType this Item is of.
+ *
+ * For example, if this Item is an XML node, more specifically a text node,
+ * <tt>text()</tt> is returned. That is, BuiltinTypes::text. However, if this
+ * Item is an atomic value of type <tt>xs:long</tt> that is what's returned,
+ * BuiltinTypes::xsLong.
+ *
+ * @returns the type of this Item.
+ */
+ inline QExplicitlySharedDataPointer<ItemType> type() const
+ {
+ if(isAtomicValue())
+ return atomicValue->type();
+ else
+ return asNode().type();
+ }
+
+ inline const AtomicValue *asAtomicValue() const
+ {
+ Q_ASSERT(isAtomicValue());
+ return atomicValue;
+ }
+
+ inline const QXmlNodeModelIndex &asNode() const
+ {
+ Q_ASSERT_X(isNode() || isNull(), Q_FUNC_INFO,
+ "This item isn't a valid QXmlNodeModelIndex.");
+ Q_ASSERT_X(sizeof(QXmlNodeModelIndex) == sizeof(QPatternist::NodeIndexStorage), Q_FUNC_INFO,
+ "If this doesn't hold, something is wrong.");
+
+ return reinterpret_cast<const QXmlNodeModelIndex &>(node);
+ }
+
+ inline operator bool() const
+ {
+ return node.model;
+ }
+
+ inline bool isNull() const
+ {
+ return !node.model;
+ }
+
+ inline void reset()
+ {
+ /* Note that this function should be equal to the default
+ * constructor. */
+ node.model = 0;
+ node.data = 0;
+ }
+
+ static inline Item fromPublic(const QXmlItem &i)
+ {
+ const Item it(i.m_node);
+ if(it.isAtomicValue())
+ it.asAtomicValue()->ref.ref();
+
+ return it;
+ }
+
+ static inline QXmlItem toPublic(const Item &i)
+ {
+ return QXmlItem(i);
+ }
+
+ private:
+ union
+ {
+ NodeIndexStorage node;
+ const AtomicValue *atomicValue;
+ };
+ };
+
+ template<typename T>
+ inline Item toItem(const QExplicitlySharedDataPointer<T> atomicValue)
+ {
+ return Item(atomicValue.data());
+ }
+
+ /**
+ * This is an overload, provided for convenience.
+ * @relates QXmlNodeModelIndex
+ */
+ static inline QString formatData(const QXmlNodeModelIndex node)
+ {
+ return node.stringValue(); // This can be improved a lot.
+ }
+}
+
+ inline QXmlName QXmlNodeModelIndex::name() const
+ {
+ return m_storage.model->name(*this);
+ }
+
+ inline QXmlNodeModelIndex QXmlNodeModelIndex::root() const
+ {
+ return m_storage.model->root(*this);
+ }
+
+ inline QXmlNodeModelIndex::Iterator::Ptr QXmlNodeModelIndex::iterate(const QXmlNodeModelIndex::Axis axis) const
+ {
+ return m_storage.model->iterate(*this, axis);
+ }
+
+ inline QUrl QXmlNodeModelIndex::documentUri() const
+ {
+ return m_storage.model->documentUri(*this);
+ }
+
+ inline QUrl QXmlNodeModelIndex::baseUri() const
+ {
+ return m_storage.model->baseUri(*this);
+ }
+
+ inline QXmlNodeModelIndex::NodeKind QXmlNodeModelIndex::kind() const
+ {
+ return m_storage.model->kind(*this);
+ }
+
+ inline bool QXmlNodeModelIndex::isDeepEqual(const QXmlNodeModelIndex &other) const
+ {
+ return m_storage.model->isDeepEqual(*this, other);
+ }
+
+ inline QXmlNodeModelIndex::DocumentOrder QXmlNodeModelIndex::compareOrder(const QXmlNodeModelIndex &other) const
+ {
+ Q_ASSERT_X(model() == other.model(), Q_FUNC_INFO, "The API docs guarantees the two nodes are from the same model");
+ return m_storage.model->compareOrder(*this, other);
+ }
+
+ inline bool QXmlNodeModelIndex::is(const QXmlNodeModelIndex &other) const
+ {
+ return m_storage.model == other.m_storage.model &&
+ m_storage.data == other.m_storage.data &&
+ m_storage.additionalData == other.m_storage.additionalData;
+ }
+
+ inline void QXmlNodeModelIndex::sendNamespaces(QAbstractXmlReceiver *const receiver) const
+ {
+ m_storage.model->sendNamespaces(*this, receiver);
+ }
+
+ inline QVector<QXmlName> QXmlNodeModelIndex::namespaceBindings() const
+ {
+ return m_storage.model->namespaceBindings(*this);
+ }
+
+ inline QXmlName::NamespaceCode QXmlNodeModelIndex::namespaceForPrefix(const QXmlName::PrefixCode prefix) const
+ {
+ return m_storage.model->namespaceForPrefix(*this, prefix);
+ }
+
+ inline QString QXmlNodeModelIndex::stringValue() const
+ {
+ return m_storage.model->stringValue(*this);
+ }
+
+ inline QPatternist::ItemType::Ptr QXmlNodeModelIndex::type() const
+ {
+ return m_storage.model->type(*this);
+ }
+
+ inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QPatternist::Item> > QXmlNodeModelIndex::sequencedTypedValue() const
+ {
+ return m_storage.model->sequencedTypedValue(*this);
+ }
+
+ inline QXmlItem::QXmlItem(const QPatternist::Item &i) : m_node(i.node)
+ {
+ if(isAtomicValue())
+ m_atomicValue->ref.ref();
+ }
+
+Q_DECLARE_TYPEINFO(QPatternist::Item::Iterator::Ptr, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QPatternist::AtomicValue, Q_MOVABLE_TYPE);
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qnodebuilder.cpp b/src/xmlpatterns/data/qnodebuilder.cpp
new file mode 100644
index 0000000..c848216
--- /dev/null
+++ b/src/xmlpatterns/data/qnodebuilder.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnodebuilder_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qnodebuilder_p.h b/src/xmlpatterns/data/qnodebuilder_p.h
new file mode 100644
index 0000000..4057e5e
--- /dev/null
+++ b/src/xmlpatterns/data/qnodebuilder_p.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_NodeBuilder_H
+#define Patternist_NodeBuilder_H
+
+#include "qitem_p.h"
+#include "qabstractxmlreceiver.h"
+#include "qautoptr_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Receives QAbstractXmlReceiver events and builds a node tree
+ * in memory that afterwards can be retrieved via builtNode()
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class NodeBuilder : public QAbstractXmlReceiver
+ {
+ public:
+ typedef AutoPtr<NodeBuilder> Ptr;
+
+ inline NodeBuilder()
+ {
+ }
+
+ /**
+ * @short Returns the document that has been built.
+ *
+ * If this function is called before any events have been received, the result is undefined.
+ *
+ * The top node that was constructed can be retrieved by calling
+ * NodeModel::root() on the returned NodeModel.
+ *
+ * This function is not @c const, because some implementations delay
+ * the node construction until the node is needed. Also, text nodes are
+ * difficult, at best, to construct until one knows that all text content
+ * has been received(which a call to this function in a natural way
+ * signals).
+ */
+ virtual QAbstractXmlNodeModel::Ptr builtDocument() = 0;
+
+ /**
+ * @short Creates a copy of this NodeBuilder, that operates independently of
+ * this NodeBuilder.
+ *
+ * The caller owns the returned instance.
+ */
+ virtual NodeBuilder::Ptr create(const QUrl &baseURI) const = 0;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qnodemodel.cpp b/src/xmlpatterns/data/qnodemodel.cpp
new file mode 100644
index 0000000..b44f58b
--- /dev/null
+++ b/src/xmlpatterns/data/qnodemodel.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QUrl>
+
+#include "qnamespaceresolver_p.h"
+
+#include "qitem_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qqnamevalue.cpp b/src/xmlpatterns/data/qqnamevalue.cpp
new file mode 100644
index 0000000..ae93cd2
--- /dev/null
+++ b/src/xmlpatterns/data/qqnamevalue.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qanyuri_p.h"
+#include "qbuiltintypes_p.h"
+#include "qxpathhelper_p.h"
+
+#include "qqnamevalue_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+QNameValue::QNameValue(const NamePool::Ptr &np, const QXmlName name) : m_qName(name)
+ , m_namePool(np)
+{
+ Q_ASSERT(!name.isNull());
+ Q_ASSERT(m_namePool);
+}
+
+QNameValue::Ptr QNameValue::fromValue(const NamePool::Ptr &np, const QXmlName name)
+{
+ Q_ASSERT(!name.isNull());
+ return QNameValue::Ptr(new QNameValue(np, name));
+}
+
+QString QNameValue::stringValue() const
+{
+ return m_namePool->toLexical(m_qName);
+}
+
+ItemType::Ptr QNameValue::type() const
+{
+ return BuiltinTypes::xsQName;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qqnamevalue_p.h b/src/xmlpatterns/data/qqnamevalue_p.h
new file mode 100644
index 0000000..d038f74
--- /dev/null
+++ b/src/xmlpatterns/data/qqnamevalue_p.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_QNameValue_H
+#define Patternist_QNameValue_H
+
+#include "qitem_p.h"
+#include "qxmlname.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:QName type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @see QNameConstructor::expandQName()
+ * @see XPathHelper::isQName()
+ * @see QXmlUtils
+ */
+ class QNameValue : public AtomicValue
+ {
+ public:
+ friend class CommonValues;
+ friend class QNameComparator;
+
+ typedef QExplicitlySharedDataPointer<QNameValue> Ptr;
+
+ /**
+ * Constructs a QNameValue that represents @p name.
+ *
+ * @param name the QName. May not be @c null.
+ * @param np the NamePool.
+ * @see QNameConstructor::expandQName()
+ * @see XPathHelper::isQName()
+ * @see QXmlUtils
+ */
+ static QNameValue::Ptr fromValue(const NamePool::Ptr &np, const QXmlName name);
+
+ virtual QString stringValue() const;
+
+ virtual ItemType::Ptr type() const;
+
+ inline QXmlName qName() const
+ {
+ return m_qName;
+ }
+
+ private:
+ QNameValue(const NamePool::Ptr &np, const QXmlName name);
+
+ const QXmlName m_qName;
+ const NamePool::Ptr m_namePool;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qresourceloader.cpp b/src/xmlpatterns/data/qresourceloader.cpp
new file mode 100644
index 0000000..8633381
--- /dev/null
+++ b/src/xmlpatterns/data/qresourceloader.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QUrl>
+
+
+#include "qresourceloader_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+ResourceLoader::~ResourceLoader()
+{
+}
+
+bool ResourceLoader::isUnparsedTextAvailable(const QUrl &uri,
+ const QString &encoding)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ Q_UNUSED(encoding);
+ return false;
+}
+
+ItemType::Ptr ResourceLoader::announceUnparsedText(const QUrl &uri)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ return ItemType::Ptr();
+}
+
+Item ResourceLoader::openUnparsedText(const QUrl &uri,
+ const QString &encoding,
+ const ReportContext::Ptr &context,
+ const SourceLocationReflection *const where)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ Q_UNUSED(encoding);
+ Q_UNUSED(context);
+ Q_UNUSED(where);
+ return Item();
+}
+
+Item ResourceLoader::openDocument(const QUrl &uri,
+ const ReportContext::Ptr &context)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ Q_UNUSED(context); /* Needed when compiling in release mode. */
+ return Item();
+}
+
+SequenceType::Ptr ResourceLoader::announceDocument(const QUrl &uri, const Usage)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ return SequenceType::Ptr();
+}
+
+bool ResourceLoader::isDocumentAvailable(const QUrl &uri)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ return false;
+}
+
+Item::Iterator::Ptr ResourceLoader::openCollection(const QUrl &uri)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ return Item::Iterator::Ptr();
+}
+
+SequenceType::Ptr ResourceLoader::announceCollection(const QUrl &uri)
+{
+ Q_ASSERT(uri.isValid());
+ Q_ASSERT(!uri.isRelative());
+ Q_UNUSED(uri); /* Needed when compiling in release mode. */
+ return SequenceType::Ptr();
+}
+
+void ResourceLoader::clear(const QUrl &uri)
+{
+ Q_UNUSED(uri);
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qresourceloader_p.h b/src/xmlpatterns/data/qresourceloader_p.h
new file mode 100644
index 0000000..c11304f
--- /dev/null
+++ b/src/xmlpatterns/data/qresourceloader_p.h
@@ -0,0 +1,320 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_ResourceLoader_H
+#define Patternist_ResourceLoader_H
+
+#include "qitem_p.h"
+#include "qreportcontext_p.h"
+#include "qsequencetype_p.h"
+#include "qsourcelocationreflection_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QUrl;
+
+namespace QPatternist
+{
+ /**
+ * @short Responsible for handling requests for opening files and node collections.
+ *
+ * ResourceLoader is a callback used for opening files, requested
+ * via the functions <tt>fn:document()</tt> and <tt>fn:unparsed-text()</tt>;
+ * and node collections, requested via <tt>fn:collection()</tt>. Patternist uses the
+ * ResourceLoader at compile time,
+ * via StaticContext::resourceLoader(), and at runtime, via DynamicContext::resourceLoader().
+ *
+ * The ResourceLoader takes care of loading "external resources" in a way specific to the data
+ * model Patternist is using. For example, perhaps the opening of documents should pass
+ * a security policy, or a collection should map to nodes in a virtual filesystem or a database.
+ *
+ * From Patternist's perspective, the ResourceLoader provides two things:
+ *
+ * - At compile time, it calls announceDocument(), announceCollection() and announceUnparsedText()
+ * if it knows the URIs at compile time in order to retrieve the static types of the data the URIs
+ * maps to. This is used for more efficiently compiling the query and to better report errors
+ * at compile time.
+ * - To open document and node collections at runtime.
+ *
+ * From the user's or the data model's perspective, the ResourceLoader most notably provides
+ * a hint to what resources a query will load at runtime, and therefore provides an opportunity
+ * to prepare in advance for that. For example, between the compile and runtime stage,
+ * the ResourceLoader sub-class can be asked to pre-load documents in an asynchronous
+ * and simultaneous way, such that the runtime stage is faster and doesn't
+ * freeze a graphical interface.
+ *
+ * The announce functions are not guaranteed to be called. The loading functions can be called
+ * with an URI that an announce function hasn't been called with.
+ *
+ * The default implementations of ResourceLoader's virtual functions all signals that no
+ * resources can be loaded. This means ResourceLoader must be sub-classed, in order to
+ * be able to load resources.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_AUTOTEST_EXPORT ResourceLoader : public QSharedData
+ {
+ public:
+ enum Usage
+ {
+ /**
+ * Communicates that the URI may be used during query evaluation.
+ * For example, zero times or very many times.
+ *
+ * Typically this hint is given when the URI is available at
+ * compile-time, but it is used inside a conditional statement
+ * whose branching can't be determined at compile time.
+ */
+ MayUse,
+
+ /**
+ * Communicates that the URI will always be used at query
+ * evaluation.
+ */
+ WillUse
+ };
+
+ typedef QExplicitlySharedDataPointer<ResourceLoader> Ptr;
+ inline ResourceLoader() {}
+ virtual ~ResourceLoader();
+
+ /**
+ * @short Calls to this function are generated by calls to the
+ * <tt>fn:unparsed-text-available()</tt> function.
+ *
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @returns @c true if calling openUnparsedText() while passing @p uri will successfully load
+ * the document.
+ * @see <a href="http://www.w3.org/TR/xslt20/#unparsed-text">XSL Transformations
+ * (XSLT) Version 2.0, 16.2 Reading Text Files</a>
+ */
+ virtual bool isUnparsedTextAvailable(const QUrl &uri,
+ const QString &encoding);
+
+ /**
+ * @short May be called by the compilation framework at compile time to report that an
+ * unparsed text(plain text) file referenced by @p uri will be loaded at runtime.
+ *
+ * This function can be called an arbitrary amount of times for the same URI. How many times
+ * it is called for a URI has no meaning(beyond the first call, that is). For what queries
+ * the compilation framework can determine what always will be loaded is generally undefined. It
+ * depends on factors such as how simple the query is what information that is statically
+ * available and subsequently what optimizations that can apply.
+ *
+ * Calls to this function are generated by calls to the <tt>fn:unparsed-text()</tt> function.
+ *
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @see <a href="http://www.w3.org/TR/xslt20/#unparsed-text">XSL Transformations
+ * (XSLT) Version 2.0, 16.2 Reading Text Files</a>
+ * @returns
+ * - @c null if no unparsed file can be loaded for @p uri
+ * - The item type that the value loaded by @p uri will be an instance of. This is
+ * typically @c xs:string
+ */
+ virtual ItemType::Ptr announceUnparsedText(const QUrl &uri);
+
+ /**
+ * @short Calls to this function are generated by calls to the <tt>fn:unparsed-text()</tt> function.
+ *
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @param encoding the encoding to use. If empty, the user hasn't
+ * expressed any encoding to use.
+ * @see <a href="http://www.w3.org/TR/xslt20/#unparsed-text">XSL Transformations
+ * (XSLT) Version 2.0, 16.2 Reading Text Files</a>
+ * @returns
+ * - @c null if no unparsed file can be loaded for @p uri
+ * - An @c xs:string value(or subtype) containing the content of the file identified
+ * by @p uri as text. Remember that its type must match the sequence type
+ * returned by announceUnparsedText()
+ */
+ virtual Item openUnparsedText(const QUrl &uri,
+ const QString &encoding,
+ const ReportContext::Ptr &context,
+ const SourceLocationReflection *const where);
+
+ /**
+ * @short Calls to this function are generated by calls to the <tt>fn:document()</tt>
+ * or <tt>fn:doc()</tt> function.
+ *
+ * @note This function is responsible for execution stability. Subsequent calls
+ * to this function with the same URI should result in QXmlNodeModelIndex instances that have
+ * the same identity. However, in some cases this stability is not of interest, see
+ * the specification for details.
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @see QXmlNodeModelIndex::identity()
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-doc">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 15.5.4 fn:doc</a>
+ * @see <a href="http://www.w3.org/TR/xslt20/#document">XSL Transformations
+ * (XSLT) Version 2.0, 16.1 Multiple Source Documents</a>
+ * @returns
+ * - @c null if no document can be loaded for @p uri
+ * - A QXmlNodeModelIndex representing the document identified by @p uri. Remember that the QXmlNodeModelIndex
+ * must match the sequence type returned by announceDocument()
+ */
+ virtual Item openDocument(const QUrl &uri,
+ const ReportContext::Ptr &context);
+
+ /**
+ * @short May be called by the compilation framework at compile time to report that an
+ * XML document referenced by @p uri will be loaded at runtime.
+ *
+ * This function can be called an arbitrary amount of times for the same URI, but different
+ * @p usageHint values. How many times it is called for a URI has no meaning(beyond the first call,
+ * that is). For what queries the compilation framework can determine what always will be
+ * loaded is generally undefined. It
+ * depends on factors such as the complexity of the query, what information that is statically
+ * available and subsequently what optimizations that can be applied.
+ *
+ * Calls to this function are generated by calls to the <tt>fn:document()</tt>
+ * or <tt>fn:doc()</tt> function.
+ *
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @param usageHint A hint to how the URI will be used.
+ * @returns
+ * - @c null if the ResourceLoader can determine at this stage that no document
+ * referenced by @p uri will ever be possible to load.
+ * - The appropriate sequence type if loading @p uri succeeds at runtime. This must be
+ * CommonSequenceTypes::zeroOrOneDocument, CommonSequenceTypes::exactlyOneDocument or
+ * a sequence type that is a sub type of it.
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-doc">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 15.5.4 fn:doc</a>
+ * @see <a href="http://www.w3.org/TR/xslt20/#document">XSL Transformations
+ * (XSLT) Version 2.0, 16.1 Multiple Source Documents</a>
+ */
+ virtual SequenceType::Ptr announceDocument(const QUrl &uri, const Usage usageHint);
+
+ /**
+ * @short Calls to this function are generated by calls to the <tt>fn:doc-available()</tt> function.
+ *
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @returns @c true if calling openDocument() while passing @p uri will successfully load
+ * the document.
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-doc-available">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 15.5.5 fn:doc-available</a>
+ * @see <a href="http://www.w3.org/TR/xslt20/#document">XSL Transformations
+ * (XSLT) Version 2.0, 16.1 Multiple Source Documents</a>
+ */
+ virtual bool isDocumentAvailable(const QUrl &uri);
+
+ /**
+ * @short Calls to this function are generated by calls to the <tt>fn:collection()</tt> function.
+ *
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-collection">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 15.5.6 fn:collection</a>
+ * @returns
+ * - @c null if no node collection can be loaded for @p uri
+ * - An QAbstractXmlForwardIterator representing the content identified by @p uri. Remember that the content
+ * of the QAbstractXmlForwardIterator must match the sequence type returned by announceCollection()
+ */
+ virtual Item::Iterator::Ptr openCollection(const QUrl &uri);
+
+ /**
+ * @short May be called by the compilation framework at compile time to report that an
+ * node collection referenced by @p uri will be loaded at runtime.
+ *
+ * This function can be called an arbitrary amount of times for the same URI. How many times
+ * it is called for a URI has no meaning(beyond the first call, that is). For what queries
+ * the compilation framework can determine what always will be loaded is generally undefined. It
+ * depends on factors such as how simple the query is what information that is statically
+ * available and subsequently what optimizations that can apply.
+ *
+ * Calls to this function are generated by calls to the <tt>fn:collection()</tt> function.
+ *
+ * @note This function is responsible for execution stability. Subsequent calls
+ * to this function with the same URI should result in QXmlNodeModelIndex instances that have
+ * the same identity. However, in some cases this stability is not of interest, see
+ * the specification for details.
+ * @param uri A URI identifying the resource to retrieve. The URI is guaranteed
+ * to be valid(QUrl::isValid() returns @c true) and to be absolute(QUrl::isRelative()
+ * returns @c false).
+ * @returns
+ * - @c null if the ResourceLoader can determine at this stage that no document
+ * referenced by @p uri will ever be possible to load.
+ * - The appropriate sequence type if loading @p uri succeeds at runtime. This must be
+ * CommonSequenceTypes::zeroOrMoreNodes or a sequence type that is a sub type of it.
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-collection">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 15.5.6 fn:collection</a>
+ */
+ virtual SequenceType::Ptr announceCollection(const QUrl &uri);
+
+ /**
+ * @short Asks to unload @p uri from its document pool, such that a
+ * subsequent request will require a new read.
+ *
+ * The default implementation does nothing.
+ */
+ virtual void clear(const QUrl &uri);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qschemadatetime.cpp b/src/xmlpatterns/data/qschemadatetime.cpp
new file mode 100644
index 0000000..425af7d
--- /dev/null
+++ b/src/xmlpatterns/data/qschemadatetime.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+#include "qitem_p.h"
+
+#include "qschemadatetime_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+DateTime::DateTime(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+DateTime::Ptr DateTime::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-?)" /* Any preceding minus. */
+ "(\\d{4,})" /* The year part. */
+ "-" /* Delimiter. */
+ "(\\d{2})" /* The month part. */
+ "-" /* Delimiter. */
+ "(\\d{2})" /* The day part. */
+ "T" /* Delimiter. */
+ "(\\d{2})" /* Hour part */
+ ":" /* Delimiter. */
+ "(\\d{2})" /* Minutes part */
+ ":" /* Delimiter. */
+ "(\\d{2,})" /* Seconds part. */
+ "(?:\\.(\\d+))?" /* Milli seconds part. */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
+ "\\s*$" /* Any whitespace at the end. */))),
+ /*zoneOffsetSignP*/ 9,
+ /*zoneOffsetHourP*/ 10,
+ /*zoneOffsetMinuteP*/ 11,
+ /*zoneOffsetUTCSymbolP*/ 12,
+ /*yearP*/ 2,
+ /*monthP*/ 3,
+ /*dayP*/ 4,
+ /*hourP*/ 5,
+ /*minutesP*/ 6,
+ /*secondsP*/ 7,
+ /*msecondsP*/ 8,
+ /*yearSignP*/ 1);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : DateTime::Ptr(new DateTime(retval));
+}
+
+DateTime::Ptr DateTime::fromDateTime(const QDateTime &dt)
+{
+ Q_ASSERT(dt.isValid());
+ return DateTime::Ptr(new DateTime(dt));
+}
+
+Item DateTime::fromValue(const QDateTime &dt) const
+{
+ Q_ASSERT(dt.isValid());
+ return fromDateTime(dt);
+}
+
+QString DateTime::stringValue() const
+{
+ return dateToString() + QLatin1Char('T') + timeToString() + zoneOffsetToString();
+}
+
+ItemType::Ptr DateTime::type() const
+{
+ return BuiltinTypes::xsDateTime;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qschemadatetime_p.h b/src/xmlpatterns/data/qschemadatetime_p.h
new file mode 100644
index 0000000..c974242
--- /dev/null
+++ b/src/xmlpatterns/data/qschemadatetime_p.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_DateTime_H
+#define Patternist_DateTime_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+/**
+ * @file
+ * @short Contains class DateTime. This file was originally called qdatetime_p.h,
+ * but various build systems cannot handle that that name happens to be
+ * identical to another one, the one in QtCore.
+ */
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:dateTime type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class DateTime : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static DateTime::Ptr fromLexical(const QString &string);
+ static DateTime::Ptr fromDateTime(const QDateTime &dt);
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+ virtual Item fromValue(const QDateTime &dt) const;
+
+ protected:
+ friend class CommonValues;
+
+ DateTime(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qschemanumeric.cpp b/src/xmlpatterns/data/qschemanumeric.cpp
new file mode 100644
index 0000000..4f42db9
--- /dev/null
+++ b/src/xmlpatterns/data/qschemanumeric.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <math.h>
+
+#include "qabstractfloat_p.h"
+#include "qboolean_p.h"
+#include "qbuiltintypes_p.h"
+#include "qcommonvalues_p.h"
+#include "qdecimal_p.h"
+#include "qinteger_p.h"
+
+#include "qschemanumeric_p.h"
+
+/**
+ * @file
+ * @short Contains class Numeric. This file was originally called qnumeric.cpp,
+ * but was renamed to stay consistent with qschemanumeric_p.h
+ */
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+AtomicValue::Ptr Numeric::fromLexical(const QString &number)
+{
+ Q_ASSERT(!number.isEmpty());
+ Q_ASSERT_X(!number.contains(QLatin1Char('e')) &&
+ !number.contains(QLatin1Char('E')),
+ Q_FUNC_INFO, "Should not contain any e/E");
+
+ if(number.contains(QLatin1Char('.'))) /* an xs:decimal. */
+ return Decimal::fromLexical(number);
+ else /* It's an integer, of some sort. E.g, -3, -2, -1, 0, 1, 2, 3 */
+ return Integer::fromLexical(number);
+}
+
+xsDouble Numeric::roundFloat(const xsDouble val)
+{
+ if(qIsInf(val) || AbstractFloat<true>::isEqual(val, 0.0))
+ return val;
+ else if(qIsNaN(val))
+ return val;
+ else
+ {
+ if(val >= -0.5 && val < 0)
+ return -0.0;
+ else
+ return ::floor(val + 0.5);
+
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qschemanumeric_p.h b/src/xmlpatterns/data/qschemanumeric_p.h
new file mode 100644
index 0000000..8654b57
--- /dev/null
+++ b/src/xmlpatterns/data/qschemanumeric_p.h
@@ -0,0 +1,235 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Numeric_H
+#define Patternist_Numeric_H
+
+#include "qitem_p.h"
+#include "qprimitives_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+/**
+ * @file
+ * @short Contains class Numeric. This file was originally called qnumeric_p.h,
+ * but various build systems cannot handle that that name happens to be
+ * identical to another one, the one in QtCore.
+ */
+
+namespace QPatternist
+{
+ /**
+ * @short Base class for all numeric values.
+ *
+ * @section creation Creating Instances
+ *
+ * @todo
+ * - Depending on what type of val
+ * - Numeric::createFromString
+ * - Various classes has ::Zero(), ::PosINF(), ::NaN(), NegINF()
+ * - Never use constructor, use createFromNative, or createFromString.
+ *
+ * @see <a href="http://www.w3.org/TR/xquery-operators/#numeric-functions">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6 Functions and Operators on Numerics</a>
+ * @see <a href="http://www.w3.org/TR/xquery-operators/#func-overloading">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 1.2 Function Overloading</a>
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ * @todo discuss data hierarchy the non existatnt number data type
+ */
+ class Numeric : public AtomicValue
+ {
+ public:
+
+ typedef QExplicitlySharedDataPointer<Numeric> Ptr;
+
+ /**
+ * Creates a Numeric sub-class that is appropriate for @p number.
+ *
+ * @note usages of e/E is not handled; Double::fromLexical should
+ * be used in that case. There is no function similar to fromLexical that also
+ * takes double values into account(because that distinction is done in the scanner).
+ *
+ * Currently used in the parser to create appropriate expressions.
+ */
+ static AtomicValue::Ptr fromLexical(const QString &number);
+
+ /**
+ * @returns the particular number's value as a native representation of
+ * the type xs:double. This can be considered that the value is cast to
+ * xs:double.
+ */
+ virtual xsDouble toDouble() const = 0;
+
+ /**
+ * @returns the particular number's value as a native representation of
+ * the type xs:integer. This can be considered that the value is cast to
+ * xs:integer.
+ */
+ virtual xsInteger toInteger() const = 0;
+
+ /**
+ * @returns the number as an unsigned integer. If the value is not
+ * unsigned, the code asserts and behavior is undefined.
+ */
+ virtual qulonglong toUnsignedInteger() const = 0;
+
+ /**
+ * @returns the particular number's value as a native representation of
+ * the type xs:float. This can be considered that the value is cast to
+ * xs:float.
+ */
+ virtual xsFloat toFloat() const = 0;
+
+ /**
+ * @returns the particular number's value as a native representation of
+ * the type xs:decimal. This can be considered that the value is cast to
+ * xs:decimal.
+ */
+ virtual xsFloat toDecimal() const = 0;
+
+ /**
+ * Performs the algorithm specified for the function fn:round on this Numeric,
+ * and whose result is returned.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-round">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.4.4 fn:round</a>
+ */
+ virtual Numeric::Ptr round() const = 0;
+
+ /**
+ * Performs rounding as defined for the fn:round-half-to-even on this Numeric,
+ * and whose result is returned.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-round-half-to-even">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.4.5 fn:round-half-to-even</a>
+ */
+ virtual Numeric::Ptr roundHalfToEven(const xsInteger scale) const = 0;
+
+ /**
+ * Performs the algorithm specified for the function fn:floor on this Numeric,
+ * and whose result is returned.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-floor">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.4.3 fn:floor</a>
+ */
+ virtual Numeric::Ptr floor() const = 0;
+
+ /**
+ * Performs the algorithm specified for the function fn:ceiling on this Numeric,
+ * and whose result is returned.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-ceiling">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.4.2 fn:ceiling</a>
+ */
+ virtual Numeric::Ptr ceiling() const = 0;
+
+ /**
+ * Performs the algorithm specified for the function fn:abs on this Numeric,
+ * and whose result is returned.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-ceiling">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 6.4.1 fn:abs</a>
+ */
+ virtual Numeric::Ptr abs() const = 0;
+
+ /**
+ * Determines whether this Numeric is not-a-number, @c NaN. For numeric types
+ * that cannot represent @c NaN, this function should return @c false.
+ *
+ * @returns @c true if this Numeric is @c NaN
+ */
+ virtual bool isNaN() const = 0;
+
+ /**
+ * Determines whether this Numeric is an infinite number. Signedness
+ * is irrelevant, -INF as well as INF is considered infinity.
+ *
+ * For numeric types that cannot represent infinity, such as xs:integer
+ * , this function should return @c false.
+ *
+ * @returns @c true if this Numeric is an infinite number
+ */
+ virtual bool isInf() const = 0;
+
+ /**
+ * Unary minus.
+ */
+ virtual Item toNegated() const = 0;
+
+ /**
+ * @short Returns @c true if this value is signed. If @c false is
+ * returned, the value is unsigned.
+ *
+ * For float and decimal values, @c xs:double, @c xs:float and @c
+ * xs:decimal, the code asserts and behavior is undefined.
+ */
+ virtual bool isSigned() const = 0;
+
+ protected:
+ /**
+ * @short Implements @c fn:round() for types implemented with floating
+ * point.
+ *
+ * MS Windows and at least IRIX does not have C99's nearbyint() function(see the man
+ * page), so we reinvent it.
+ */
+ static xsDouble roundFloat(const xsDouble val);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qschematime.cpp b/src/xmlpatterns/data/qschematime.cpp
new file mode 100644
index 0000000..cd6f17e
--- /dev/null
+++ b/src/xmlpatterns/data/qschematime.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+#include "qitem_p.h"
+
+#include "qschematime_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+SchemaTime::SchemaTime(const QDateTime &dateTime) : AbstractDateTime(dateTime)
+{
+}
+
+SchemaTime::Ptr SchemaTime::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable( // STATIC DATA
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(\\d{2})" /* Hour part */
+ ":" /* Delimiter. */
+ "(\\d{2})" /* Minutes part */
+ ":" /* Delimiter. */
+ "(\\d{2,})" /* Seconds part. */
+ "(?:\\.(\\d+))?" /* Milli seconds part. */
+ "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
+ "\\s*$" /* Any terminating whitespace. */))),
+ /*zoneOffsetSignP*/ 5,
+ /*zoneOffsetHourP*/ 6,
+ /*zoneOffsetMinuteP*/ 7,
+ /*zoneOffsetUTCSymbolP*/ 8,
+ /*yearP*/ -1,
+ /*monthP*/ -1,
+ /*dayP*/ -1,
+ /*hourP*/ 1,
+ /*minutesP*/ 2,
+ /*secondsP*/ 3,
+ /*msecondsP*/ 4);
+
+ AtomicValue::Ptr err;
+ const QDateTime retval(create(err, lexical, captureTable));
+
+ return err ? err : SchemaTime::Ptr(new SchemaTime(retval));
+}
+
+SchemaTime::Ptr SchemaTime::fromDateTime(const QDateTime &dt)
+{
+ Q_ASSERT(dt.isValid());
+ /* Singleton value, allocated once instead of each time it's needed. */
+ // STATIC DATA
+ static const QDate time_defaultDate(AbstractDateTime::DefaultYear,
+ AbstractDateTime::DefaultMonth,
+ AbstractDateTime::DefaultDay);
+
+ QDateTime result;
+ copyTimeSpec(dt, result);
+
+ result.setDate(time_defaultDate);
+ result.setTime(dt.time());
+
+ return SchemaTime::Ptr(new SchemaTime(result));
+}
+
+Item SchemaTime::fromValue(const QDateTime &dt) const
+{
+ Q_ASSERT(dt.isValid());
+ return fromDateTime(dt);
+}
+
+QString SchemaTime::stringValue() const
+{
+ return timeToString() + zoneOffsetToString();
+}
+
+ItemType::Ptr SchemaTime::type() const
+{
+ return BuiltinTypes::xsTime;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qschematime_p.h b/src/xmlpatterns/data/qschematime_p.h
new file mode 100644
index 0000000..a5a9549
--- /dev/null
+++ b/src/xmlpatterns/data/qschematime_p.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_Time_H
+#define Patternist_Time_H
+
+#include "qabstractdatetime_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:time type.
+ *
+ * The header file for this class was orignally called Time.h, but this
+ * clashed with a system header on MinGW.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class SchemaTime : public AbstractDateTime
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static SchemaTime::Ptr fromLexical(const QString &string);
+ static SchemaTime::Ptr fromDateTime(const QDateTime &dt);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+ virtual Item fromValue(const QDateTime &dt) const;
+
+ protected:
+ friend class CommonValues;
+
+ SchemaTime(const QDateTime &dateTime);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qsequencereceiver.cpp b/src/xmlpatterns/data/qsequencereceiver.cpp
new file mode 100644
index 0000000..4e9fdfe
--- /dev/null
+++ b/src/xmlpatterns/data/qsequencereceiver.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qitem_p.h"
+
+#include "qabstractxmlreceiver.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+QAbstractXmlReceiver::~QAbstractXmlReceiver()
+{
+}
+
+template<const QXmlNodeModelIndex::Axis axis>
+void QAbstractXmlReceiver::sendFromAxis(const QXmlNodeModelIndex &node)
+{
+ Q_ASSERT(!node.isNull());
+ const QXmlNodeModelIndex::Iterator::Ptr it(node.iterate(axis));
+ QXmlNodeModelIndex next(it->next());
+
+ while(!next.isNull())
+ {
+ sendAsNode(next);
+ next = it->next();
+ }
+}
+
+void QAbstractXmlReceiver::sendAsNode(const Item &outputItem)
+{
+ Q_ASSERT(outputItem);
+ Q_ASSERT(outputItem.isNode());
+ const QXmlNodeModelIndex asNode = outputItem.asNode();
+
+ switch(asNode.kind())
+ {
+ case QXmlNodeModelIndex::Attribute:
+ {
+ attribute(asNode.name(), outputItem.stringValue());
+ break;
+ }
+ case QXmlNodeModelIndex::Element:
+ {
+ startElement(asNode.name());
+
+ /* First the namespaces, then attributes, then the children. */
+ asNode.sendNamespaces(Ptr(const_cast<QAbstractXmlReceiver *>(this)));
+ sendFromAxis<QXmlNodeModelIndex::AxisAttribute>(asNode);
+ sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode);
+
+ endElement();
+
+ break;
+ }
+ case QXmlNodeModelIndex::Text:
+ {
+ characters(outputItem.stringValue());
+ break;
+ }
+ case QXmlNodeModelIndex::ProcessingInstruction:
+ {
+ processingInstruction(asNode.name(), outputItem.stringValue());
+ break;
+ }
+ case QXmlNodeModelIndex::Comment:
+ {
+ comment(outputItem.stringValue());
+ break;
+ }
+ case QXmlNodeModelIndex::Document:
+ {
+ sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode);
+ break;
+ }
+ case QXmlNodeModelIndex::Namespace:
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Not implemented");
+ }
+}
+
+void QAbstractXmlReceiver::whitespaceOnly(const QStringRef &value)
+{
+ Q_ASSERT_X(value.toString().trimmed().isEmpty(), Q_FUNC_INFO,
+ "The caller must guarantee only whitespace is passed. Use characters() in other cases.");
+ characters(value.toString());
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qsequencereceiver_p.h b/src/xmlpatterns/data/qsequencereceiver_p.h
new file mode 100644
index 0000000..e508acb
--- /dev/null
+++ b/src/xmlpatterns/data/qsequencereceiver_p.h
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_SequenceReceiver_H
+#define Patternist_SequenceReceiver_H
+
+#include <QSharedData>
+
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short A push interface for the XPath Data Model. Similar to SAX's
+ * ContentHandler.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class QAbstractXmlReceiver : public QSharedData
+ {
+ public:
+ typedef QExplicitlySharedDataPointer<QAbstractXmlReceiver> Ptr;
+
+ inline QAbstractXmlReceiver()
+ {
+ }
+
+ virtual ~QAbstractXmlReceiver();
+
+ /**
+ * @short Signals the start of an element by name @p name.
+ */
+ virtual void startElement(const QXmlName name) = 0;
+
+ /**
+ * @short Signals the presence of the namespace declaration @p nb.
+ *
+ * This event is received @c after startElement(), as opposed to
+ * SAX, and before any attribute() events.
+ */
+ virtual void namespaceBinding(const QXmlName &nb) = 0;
+
+ /**
+ * @short Signals the end of the current element.
+ */
+ virtual void endElement() = 0;
+
+ /**
+ * @short Signals the presence of an attribute node.
+ *
+ * This function is guaranteed by the caller to always be
+ * called after a call to startElement() or attribute().
+ *
+ * @param name the name of the attribute. Guaranteed to always be
+ * non-null.
+ * @param value the value of the attribute. Guaranteed to always be
+ * non-null.
+ */
+ virtual void attribute(const QXmlName name,
+ const QString &value) = 0;
+
+ virtual void processingInstruction(const QXmlName name,
+ const QString &value) = 0;
+ virtual void comment(const QString &value) = 0;
+
+ /**
+ * @short Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an
+ * AtomicValue.
+ */
+ virtual void item(const Item &item) = 0;
+
+ /**
+ * Sends a text node with value @p value. Adjascent text nodes
+ * may be sent. There's no restrictions on @p value, beyond that it
+ * must be valid XML characters. For instance, @p value may contain
+ * only whitespace.
+ *
+ * @see whitespaceOnly()
+ */
+ virtual void characters(const QString &value) = 0;
+
+ /**
+ * This function may be called instead of characters() if, and only if,
+ * @p value consists only of whitespace.
+ *
+ * The caller gurantees that @p value, is not empty.
+ *
+ * By whitespace is meant a sequence of characters that are either
+ * spaces, tabs, or the two new line characters, in any order. In
+ * other words, the whole of Unicode's whitespace category is not
+ * considered whitespace.
+ *
+ * However, there's no guarantee or requirement that whitespaceOnly()
+ * is called for text nodes containing whitespace only, characters()
+ * may be called just as well. This is why the default implementation
+ * for whitespaceOnly() calls characters().
+ *
+ * @see characters()
+ */
+ virtual void whitespaceOnly(const QStringRef &value);
+
+ /**
+ * Start of a document node.
+ */
+ virtual void startDocument() = 0;
+
+ /**
+ * End of a document node.
+ */
+ virtual void endDocument() = 0;
+
+ protected:
+ /**
+ * Treats @p outputItem as an node and calls the appropriate function,
+ * such as attribute() or comment(), depending on its QXmlNodeModelIndex::NodeKind.
+ *
+ * This a helper function sub-classes can use to multi-plex Nodes received
+ * via item().
+ *
+ * @param outputItem must be a QXmlNodeModelIndex.
+ */
+ void sendAsNode(const Item &outputItem);
+
+ private:
+ /**
+ * Call sendAsNode() for each child of @p node. As consistent with the
+ * XPath Data Model, this does not include attribute nodes.
+ */
+ template<const QXmlNodeModelIndex::Axis axis>
+ inline void sendFromAxis(const QXmlNodeModelIndex &node);
+ Q_DISABLE_COPY(QAbstractXmlReceiver)
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qsorttuple.cpp b/src/xmlpatterns/data/qsorttuple.cpp
new file mode 100644
index 0000000..93f9b30
--- /dev/null
+++ b/src/xmlpatterns/data/qsorttuple.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QString>
+
+#include "qbuiltintypes_p.h"
+#include "qsorttuple_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+bool SortTuple::isAtomicValue() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function.");
+ return false;
+}
+
+QString SortTuple::stringValue() const
+{
+ return QLatin1String("SortTuple");
+}
+
+bool SortTuple::isNode() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function.");
+ return false;
+}
+
+bool SortTuple::hasError() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function.");
+ return false;
+}
+
+Item::Iterator::Ptr SortTuple::typedValue() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "It makes no sense to call this function.");
+ return Item::Iterator::Ptr();
+}
+
+ItemType::Ptr SortTuple::type() const
+{
+ return BuiltinTypes::xsAnyAtomicType;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qsorttuple_p.h b/src/xmlpatterns/data/qsorttuple_p.h
new file mode 100644
index 0000000..fa4fa9c
--- /dev/null
+++ b/src/xmlpatterns/data/qsorttuple_p.h
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_SortTuple_H
+#define Patternist_SortTuple_H
+
+#include "qitem_p.h"
+#include "qitem_p.h"
+#include "qitemtype_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Represents a value and its sort keys
+ * in FLOWR's <tt>order by</tt> clause.
+ *
+ * SortTuple doesn't correspond to anything in the XPath Data Model and
+ * can therefore well be described as an exotic implementation detail.
+ * Most of its functions asserts because it makes no sense to
+ * call them.
+ *
+ * SortTuple exclusively exists for use with the expressions OrderBy and
+ * ReturnOrderBy, and acts as a carrier between those two for sort keys and
+ * source values.
+ *
+ * @ingroup Patternist_xdm
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class SortTuple : public AtomicValue
+ {
+ public:
+ /**
+ * @p aSortKeys may be empty.
+ */
+ inline SortTuple(const Item::Iterator::Ptr &aValue,
+ const Item::Vector &aSortKeys) : m_sortKeys(aSortKeys),
+ m_value(aValue)
+ {
+ Q_ASSERT(m_value);
+ Q_ASSERT(!m_sortKeys.isEmpty());
+ }
+
+ /**
+ * A smart pointer wrapping SortTuple instances.
+ */
+ typedef QExplicitlySharedDataPointer<SortTuple> Ptr;
+
+ /**
+ * This function is sometimes called by Literal::description().
+ * This function simply returns "SortTuple".
+ */
+ virtual QString stringValue() const;
+
+ /**
+ * @short Always asserts.
+ */
+ virtual Item::Iterator::Ptr typedValue() const;
+
+ /**
+ * @short Always asserts.
+ */
+ virtual bool isAtomicValue() const;
+
+ /**
+ * @short Always asserts.
+ */
+ virtual bool isNode() const;
+
+ /**
+ * @short Always asserts.
+ */
+ virtual bool hasError() const;
+
+ virtual ItemType::Ptr type() const;
+
+ inline const Item::Vector &sortKeys() const
+ {
+ return m_sortKeys;
+ }
+
+ inline const Item::Iterator::Ptr &value() const
+ {
+ return m_value;
+ }
+
+ private:
+ const Item::Vector m_sortKeys;
+ const Item::Iterator::Ptr m_value;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/quntypedatomic.cpp b/src/xmlpatterns/data/quntypedatomic.cpp
new file mode 100644
index 0000000..6b39827
--- /dev/null
+++ b/src/xmlpatterns/data/quntypedatomic.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+
+#include "quntypedatomic_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+UntypedAtomic::UntypedAtomic(const QString &s) : AtomicString(s)
+{
+}
+
+UntypedAtomic::Ptr UntypedAtomic::fromValue(const QString &value)
+{
+ return UntypedAtomic::Ptr(new UntypedAtomic(value));
+}
+
+ItemType::Ptr UntypedAtomic::type() const
+{
+ return BuiltinTypes::xsUntypedAtomic;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/quntypedatomic_p.h b/src/xmlpatterns/data/quntypedatomic_p.h
new file mode 100644
index 0000000..4f578e8
--- /dev/null
+++ b/src/xmlpatterns/data/quntypedatomic_p.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_UntypedAtomic_H
+#define Patternist_UntypedAtomic_H
+
+#include "qatomicstring_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+
+ /**
+ * @short Implements the value instance of the @c xs:untypedAtomic type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class UntypedAtomic : public AtomicString
+ {
+ public:
+ friend class CommonValues;
+
+ /**
+ * Creates an instance representing @p value.
+ *
+ * This fromValue function takes no context argument because it doesn't need it -- it
+ * casting to xs:untypedAtomic always succeeds.
+ *
+ * @note This function does not remove the string literal escaping allowed in XPath 2.0
+ */
+ static UntypedAtomic::Ptr fromValue(const QString &value);
+
+ virtual ItemType::Ptr type() const;
+
+ protected:
+
+ UntypedAtomic(const QString &value);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qvalidationerror.cpp b/src/xmlpatterns/data/qvalidationerror.cpp
new file mode 100644
index 0000000..1a6063b
--- /dev/null
+++ b/src/xmlpatterns/data/qvalidationerror.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "qvalidationerror_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+ValidationError::ValidationError(const QString &msg,
+ const ReportContext::ErrorCode code) : m_message(msg),
+ m_code(code)
+{
+}
+
+AtomicValue::Ptr ValidationError::createError(const QString &description,
+ const ReportContext::ErrorCode code)
+{
+ return ValidationError::Ptr(new ValidationError(description, code));
+}
+
+bool ValidationError::hasError() const
+{
+ return true;
+}
+
+QString ValidationError::stringValue() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO, "stringValue() asked for ValidationError -- it makes no sense.");
+ return QString();
+}
+
+QString ValidationError::message() const
+{
+ return m_message;
+}
+
+ItemType::Ptr ValidationError::type() const
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "This function should never be called, the caller "
+ "didn't check whether the AtomicValue was an ValidationError.");
+ return ItemType::Ptr();
+}
+
+ReportContext::ErrorCode ValidationError::errorCode() const
+{
+ return m_code;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qvalidationerror_p.h b/src/xmlpatterns/data/qvalidationerror_p.h
new file mode 100644
index 0000000..e525a54
--- /dev/null
+++ b/src/xmlpatterns/data/qvalidationerror_p.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_ValidationError_H
+#define Patternist_ValidationError_H
+
+#include "qitem_p.h"
+#include "qreportcontext_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Used for signalling casting errors.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class ValidationError : public AtomicValue
+ {
+ public:
+ typedef QExplicitlySharedDataPointer<ValidationError> Ptr;
+
+ /**
+ * Creates a ValidationError instance that represents a type error.
+ *
+ * @param description A detailed description of what that made the cast fail,
+ * if any. If @c null, which QString() creates, a generic message
+ * will be used.
+ */
+ static AtomicValue::Ptr createError(const QString &description = QString(),
+ const ReportContext::ErrorCode = ReportContext::FORG0001);
+
+ /**
+ * A human readable, translated message describing the error.
+ */
+ QString message() const;
+
+ /**
+ * @returns always @c true
+ */
+ virtual bool hasError() const;
+
+ /**
+ * Always results in an assert crash.
+ */
+ virtual ItemType::Ptr type() const;
+
+ /**
+ * Always results in an assert crash.
+ */
+ virtual QString stringValue() const;
+
+ /**
+ * @returns the error code this ValidationError represents. Typically, this
+ * is ReportContext::FORG0001.
+ */
+ ReportContext::ErrorCode errorCode() const;
+
+ protected:
+ ValidationError(const QString &msg, const ReportContext::ErrorCode code);
+
+ const QString m_message;
+ const ReportContext::ErrorCode m_code;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/data/qyearmonthduration.cpp b/src/xmlpatterns/data/qyearmonthduration.cpp
new file mode 100644
index 0000000..45bab3d
--- /dev/null
+++ b/src/xmlpatterns/data/qyearmonthduration.cpp
@@ -0,0 +1,186 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuiltintypes_p.h"
+#include "qcommonvalues_p.h"
+
+#include "qyearmonthduration_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+YearMonthDuration::YearMonthDuration(const bool isPositiveP,
+ const YearProperty yearsP,
+ const MonthProperty monthsP) : AbstractDuration(isPositiveP),
+ m_years(yearsP),
+ m_months(monthsP)
+{
+ Q_ASSERT(monthsP < 32 && monthsP > -32);
+}
+
+YearMonthDuration::Ptr YearMonthDuration::fromLexical(const QString &lexical)
+{
+ static const CaptureTable captureTable(
+ /* The extra paranthesis is a build fix for GCC 3.3. */
+ (QRegExp(QLatin1String(
+ "^\\s*" /* Any preceding whitespace. */
+ "(-)?" /* Sign, if any. */
+ "P" /* Delimiter. */
+ "(?:(\\d+)Y)?" /* The years part. */
+ "(?:(\\d+)M)?" /* The months part. */
+ "\\s*$" /* Any terminating whitespace. */))),
+ 2, /* yearP. */
+ 3 /* monthP. */);
+
+ YearProperty years = 0;
+ MonthProperty months = 0;
+ bool isPos;
+
+ const AtomicValue::Ptr err(create(captureTable, lexical, &isPos, &years,
+ &months, 0, 0, 0, 0, 0));
+
+ return err ? err : YearMonthDuration::Ptr(new YearMonthDuration(isPos, years, months));
+}
+
+YearMonthDuration::Ptr YearMonthDuration::fromComponents(const bool isPositive,
+ const YearProperty years,
+ const MonthProperty months)
+{
+ return YearMonthDuration::Ptr(new YearMonthDuration(isPositive, years, months));
+}
+
+QString YearMonthDuration::stringValue() const
+{
+ QString retval;
+
+ if(!m_isPositive)
+ retval.append(QLatin1Char('-'));
+
+ retval.append(QLatin1Char('P'));
+
+ /* When years == 0 and months == 0, we get "P0M", which
+ * is the correct canonical form. */
+ if(m_years)
+ {
+ retval.append(QString::number(m_years));
+ retval.append(QLatin1Char('Y'));
+
+ if(m_months)
+ {
+ retval.append(QString::number(m_months));
+ retval.append(QLatin1Char('M'));
+ }
+ }
+ else
+ {
+ if(m_months)
+ {
+ retval.append(QString::number(m_months));
+ retval.append(QLatin1Char('M'));
+ }
+ else
+ return QLatin1String("P0M"); /* Ensure the canonical form. */
+ }
+
+ return retval;
+}
+
+AbstractDuration::Value YearMonthDuration::value() const
+{
+ return (m_years * 12 + m_months) * (m_isPositive ? 1 : -1);
+}
+
+Item YearMonthDuration::fromValue(const Value val) const
+{
+ if(val == 0)
+ return toItem(CommonValues::YearMonthDurationZero);
+ else
+ {
+ const Value absValue = qAbs(val);
+ return toItem(YearMonthDuration::fromComponents(val >= 0,
+ absValue / 12,
+ absValue % 12));
+ }
+}
+
+ItemType::Ptr YearMonthDuration::type() const
+{
+ return BuiltinTypes::xsYearMonthDuration;
+}
+
+YearProperty YearMonthDuration::years() const
+{
+ return m_years;
+}
+
+MonthProperty YearMonthDuration::months() const
+{
+ return m_months;
+}
+
+DayCountProperty YearMonthDuration::days() const
+{
+ return 0;
+}
+
+HourProperty YearMonthDuration::hours() const
+{
+ return 0;
+}
+
+MinuteProperty YearMonthDuration::minutes() const
+{
+ return 0;
+}
+
+SecondProperty YearMonthDuration::seconds() const
+{
+ return 0;
+}
+
+MSecondProperty YearMonthDuration::mseconds() const
+{
+ return 0;
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/data/qyearmonthduration_p.h b/src/xmlpatterns/data/qyearmonthduration_p.h
new file mode 100644
index 0000000..59996f0
--- /dev/null
+++ b/src/xmlpatterns/data/qyearmonthduration_p.h
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef Patternist_YearMonthDuration_H
+#define Patternist_YearMonthDuration_H
+
+#include "qabstractduration_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ /**
+ * @short Implements the value instance of the @c xs:yearMonthDuration type.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup Patternist_xdm
+ */
+ class YearMonthDuration : public AbstractDuration
+ {
+ public:
+ typedef AtomicValue::Ptr Ptr;
+
+ /**
+ * Creates an instance from the lexical representation @p string.
+ */
+ static YearMonthDuration::Ptr fromLexical(const QString &string);
+
+ static YearMonthDuration::Ptr fromComponents(const bool isPositive,
+ const YearProperty years,
+ const MonthProperty months);
+
+ virtual ItemType::Ptr type() const;
+ virtual QString stringValue() const;
+
+ /**
+ * @returns the value of this @c xs:yearMonthDuration in months.
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#dt-yearMonthDuration">XQuery 1.0
+ * and XPath 2.0 Functions and Operators, 10.3.2.2 Calculating the value of a
+ * xs:dayTimeDuration from the lexical representation</a>
+ */
+ virtual Value value() const;
+
+ /**
+ * If @p val is zero, is CommonValues::YearMonthDurationZero returned.
+ */
+ virtual Item fromValue(const Value val) const;
+
+ /**
+ * @returns the years component. Always positive.
+ */
+ virtual YearProperty years() const;
+
+ /**
+ * @returns the months component. Always positive.
+ */
+ virtual MonthProperty months() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual DayCountProperty days() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual HourProperty hours() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual MinuteProperty minutes() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual SecondProperty seconds() const;
+
+ /**
+ * @returns always 0.
+ */
+ virtual MSecondProperty mseconds() const;
+
+ protected:
+ friend class CommonValues;
+
+ YearMonthDuration(const bool isPositive,
+ const YearProperty years,
+ const MonthProperty months);
+
+ private:
+ const YearProperty m_years;
+ const MonthProperty m_months;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif