summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-06-10 08:48:04 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-06-10 09:57:56 +1000
commit8e32f7966f95c5ce3f7932fd7c410162f2794a84 (patch)
treeb1bf1ad237776fc0dd69aebb6c627561ef4183f7
parente0f8e1a59b55f57363fad3c4d1386505a38351a5 (diff)
Add data stream and debug operators to QCLWorkSize
-rw-r--r--src/opencl/qclworksize.cpp60
-rw-r--r--src/opencl/qclworksize.h11
-rw-r--r--tests/auto/qcl/tst_qcl.cpp17
3 files changed, 88 insertions, 0 deletions
diff --git a/src/opencl/qclworksize.cpp b/src/opencl/qclworksize.cpp
index 8a7c0fa..840dc39 100644
--- a/src/opencl/qclworksize.cpp
+++ b/src/opencl/qclworksize.cpp
@@ -41,6 +41,8 @@
#include "qclworksize.h"
#include "qcldevice.h"
+#include <QtCore/qdatastream.h>
+#include <QtCore/qdebug.h>
QT_BEGIN_NAMESPACE
@@ -271,4 +273,62 @@ QCLWorkSize QCLWorkSize::fromString(const QString &str)
}
}
+#ifndef QT_NO_DATASTREAM
+
+/*!
+ \fn QDataStream &operator<<(QDataStream &stream, const QCLWorkSize &size)
+ \relates QCLWorkSize
+
+ Writes the given \a size to the given \a stream, and returns a
+ reference to the stream.
+*/
+QDataStream &operator<<(QDataStream &stream, const QCLWorkSize &size)
+{
+ stream << int(size.dimensions());
+ stream << quint64(size.width());
+ stream << quint64(size.height());
+ stream << quint64(size.depth());
+ return stream;
+}
+
+/*!
+ \fn QDataStream &operator>>(QDataStream &stream, QCLWorkSize &size)
+ \relates QCLWorkSize
+
+ Reads a size from the given \a stream into the given \a size, and
+ returns a reference to the stream.
+*/
+QDataStream &operator>>(QDataStream &stream, QCLWorkSize &size)
+{
+ int dims;
+ quint64 width, height, depth;
+ stream >> dims;
+ stream >> width;
+ stream >> height;
+ stream >> depth;
+ if (dims >= 3)
+ size = QCLWorkSize(size_t(width), size_t(height), size_t(depth));
+ else if (dims >= 2)
+ size = QCLWorkSize(size_t(width), size_t(height));
+ else
+ size = QCLWorkSize(size_t(width));
+ return stream;
+}
+
+#endif // QT_NO_DATASTREAM
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, const QCLWorkSize &s) {
+ if (s.dimensions() == 1)
+ dbg.nospace() << "QCLWorkSize(" << s.width() << ')';
+ else if (s.dimensions() == 2)
+ dbg.nospace() << "QCLWorkSize(" << s.width() << ", " << s.height() << ')';
+ else
+ dbg.nospace() << "QCLWorkSize(" << s.width() << ", " << s.height() << ", " << s.depth() << ')';
+ return dbg.space();
+}
+
+#endif
+
QT_END_NAMESPACE
diff --git a/src/opencl/qclworksize.h b/src/opencl/qclworksize.h
index e0c5b7f..290197c 100644
--- a/src/opencl/qclworksize.h
+++ b/src/opencl/qclworksize.h
@@ -90,6 +90,8 @@ private:
size_t m_sizes[3];
};
+Q_DECLARE_TYPEINFO(QCLWorkSize, Q_MOVABLE_TYPE);
+
inline bool QCLWorkSize::operator==(const QCLWorkSize &other) const
{
return m_dim == other.m_dim &&
@@ -106,6 +108,15 @@ inline bool QCLWorkSize::operator!=(const QCLWorkSize &other) const
m_sizes[2] != other.m_sizes[2];
}
+#ifndef QT_NO_DATASTREAM
+Q_CL_EXPORT QDataStream &operator<<(QDataStream &, const QCLWorkSize &);
+Q_CL_EXPORT QDataStream &operator>>(QDataStream &, QCLWorkSize &);
+#endif
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_CL_EXPORT QDebug operator<<(QDebug, const QCLWorkSize &);
+#endif
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/tests/auto/qcl/tst_qcl.cpp b/tests/auto/qcl/tst_qcl.cpp
index 04d6df7..44b8c34 100644
--- a/tests/auto/qcl/tst_qcl.cpp
+++ b/tests/auto/qcl/tst_qcl.cpp
@@ -608,6 +608,23 @@ void tst_QCL::workSize()
QVERIFY(size5.height() == 6);
QVERIFY(size5.depth() == 43);
QCOMPARE(size5.toString(), QLatin1String("23x6x43"));
+
+ QByteArray array;
+ QDataStream stream(&array, QIODevice::WriteOnly);
+ stream << QCLWorkSize(23);
+ stream << QCLWorkSize(42, 12);
+ stream << QCLWorkSize(2, 3, 1);
+ stream << QCLWorkSize();
+
+ QDataStream stream2(array);
+ stream2 >> size1;
+ stream2 >> size2;
+ stream2 >> size3;
+ stream2 >> size4;
+ QVERIFY(size1 == QCLWorkSize(23));
+ QVERIFY(size2 == QCLWorkSize(42, 12));
+ QVERIFY(size3 == QCLWorkSize(2, 3, 1));
+ QVERIFY(size4 == QCLWorkSize());
}
// Test QCLImageFormat.