src/gui/math3d/qgenericmatrix.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/gui/math3d/qgenericmatrix.h	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/math3d/qgenericmatrix.h	Tue Feb 02 00:43:10 2010 +0200
@@ -44,6 +44,7 @@
 
 #include <QtCore/qmetatype.h>
 #include <QtCore/qdebug.h>
+#include <QtCore/qdatastream.h>
 
 QT_BEGIN_HEADER
 
@@ -63,7 +64,7 @@
     T& operator()(int row, int column);
 
     bool isIdentity() const;
-    void setIdentity();
+    void setToIdentity();
 
     void fill(T value);
 
@@ -76,7 +77,7 @@
     bool operator==(const QGenericMatrix<N, M, T>& other) const;
     bool operator!=(const QGenericMatrix<N, M, T>& other) const;
 
-    void toValueArray(T *values);
+    void copyDataTo(T *values) const;
 
     T *data() { return m[0]; }
     const T *data() const { return m[0]; }
@@ -113,7 +114,7 @@
 template <int N, int M, typename T>
 Q_INLINE_TEMPLATE QGenericMatrix<N, M, T>::QGenericMatrix()
 {
-    setIdentity();
+    setToIdentity();
 }
 
 template <int N, int M, typename T>
@@ -164,7 +165,7 @@
 }
 
 template <int N, int M, typename T>
-Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::setIdentity()
+Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::setToIdentity()
 {
     for (int col = 0; col < N; ++col) {
         for (int row = 0; row < M; ++row) {
@@ -316,7 +317,7 @@
 }
 
 template <int N, int M, typename T>
-Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::toValueArray(T *values)
+Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::copyDataTo(T *values) const
 {
     for (int col = 0; col < N; ++col)
         for (int row = 0; row < M; ++row)
@@ -352,6 +353,32 @@
 
 #endif
 
+#ifndef QT_NO_DATASTREAM
+
+template <int N, int M, typename T>
+QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix)
+{
+    for (int row = 0; row < M; ++row)
+        for (int col = 0; col < N; ++col)
+            stream << double(matrix(row, col));
+    return stream;
+}
+
+template <int N, int M, typename T>
+QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix)
+{
+    double x;
+    for (int row = 0; row < M; ++row) {
+        for (int col = 0; col < N; ++col) {
+            stream >> x;
+            matrix(row, col) = T(x);
+        }
+    }
+    return stream;
+}
+
+#endif
+
 QT_END_NAMESPACE
 
 Q_DECLARE_METATYPE(QMatrix2x2)