From c6fc2f0a17494f8b3c1ecd3543899fe4a20bdb68 2012-11-07 15:04:26 From: florianlink Date: 2012-11-07 15:04:26 Subject: [PATCH] added PySide/PyQt compatible read/write methods git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@236 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/generator/typesystem_core.xml b/generator/typesystem_core.xml index 0db002e..d3b82f4 100644 --- a/generator/typesystem_core.xml +++ b/generator/typesystem_core.xml @@ -1823,6 +1823,9 @@ + + + @@ -1880,185 +1883,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool __result; - bool & %out% = __result; - - - - - bool %out% = __result; - - - - - - - - - unsigned char __result; - unsigned char & %out% = __result; - - - - - int %out% = __result; - - - - - - - - - int __result; - int & %out% = __result; - - - - - int %out% = __result; - - - - - - - - - uint __result; - uint & %out% = __result; - - - - - uint %out% = __result; - - - - - - - - - qint64 __result; - qint64 & %out% = __result; - - - - - qint64 %out% = __result; - - - - - - - - - unsigned long long __result; - unsigned long long & %out% = __result; - - - - - unsigned long long %out% = __result; - - - - - - - - - float __result; - float & %out% = __result; - - - - - float %out% = __result; - - - - - - - - - double __result; - double & %out% = __result; - - - - - double %out% = __result; - - - - - - - - - short __result; - short & %out% = __result; - - - - - short %out% = __result; - - - - - - - - - unsigned short __result; - unsigned short & %out% = __result; - - - - - unsigned short %out% = __result; - - - + + + + + + + + + + + + + + + + + + + + + QString readQString(QDataStream* d) { QString r; (*d) >> r; return r; } + QString readString(QDataStream* d) { QString r; (*d) >> r; return r; } + QChar readQChar(QDataStream* d) { QChar r; (*d) >> r; return r; } + QStringList readQStringList(QDataStream* d) { QStringList r; (*d) >> r; return r; } + QVariant readQVariant(QDataStream* d) { QVariant r; (*d) >> r; return r; } + bool readBool(QDataStream* d) { bool r; (*d) >> r; return r; } + qint8 readInt8(QDataStream* d) { qint8 r; (*d) >> r; return r; } + quint8 readUInt8(QDataStream* d) { quint8 r; (*d) >> r; return r; } + qint16 readInt16(QDataStream* d) { qint16 r; (*d) >> r; return r; } + quint16 readUInt16(QDataStream* d) { quint16 r; (*d) >> r; return r; } + qint32 readInt32(QDataStream* d) { qint32 r; (*d) >> r; return r; } + quint32 readUInt32(QDataStream* d) { quint32 r; (*d) >> r; return r; } + qint64 readInt64(QDataStream* d) { qint64 r; (*d) >> r; return r; } + quint64 readUInt64(QDataStream* d) { quint64 r; (*d) >> r; return r; } + float readFloat(QDataStream* d) { float r; (*d) >> r; return r; } + double readDouble(QDataStream* d) { double r; (*d) >> r; return r; } + + void writeQString(QDataStream* d, const QString& v) { (*d) << v; } + void writeString(QDataStream* d, const QString& v) { (*d) << v; } + void writeQChar(QDataStream* d, const QChar& v) { (*d) << v; } + void writeQStringList(QDataStream* d, const QStringList& v) { (*d) << v; } + void writeQVariant(QDataStream* d, const QVariant& v) { (*d) << v; } + void writeBool(QDataStream* d, bool v) { (*d) << v; } + void writeInt8(QDataStream* d, qint8 v) { (*d) << v; } + void writeUInt8(QDataStream* d, quint8 v) { (*d) << v; } + void writeInt16(QDataStream* d, qint16 v) { (*d) << v; } + void writeUInt16(QDataStream* d, quint16 v) { (*d) << v; } + void writeInt32(QDataStream* d, qint32 v) { (*d) << v; } + void writeUInt32(QDataStream* d, quint32 v) { (*d) << v; } + void writeInt64(QDataStream* d, qint64 v) { (*d) << v; } + void writeUInt64(QDataStream* d, quint64 v) { (*d) << v; } + void writeFloat(QDataStream* d, float v) { (*d) << v; } + void writeDouble(QDataStream* d, double v) { (*d) << v; } + + int writeRawData(QDataStream* d, PyObject* o) { + bool ok; + QByteArray r = PythonQtConv::PyObjGetBytes(o, false, ok); + return (*d).writeRawData(r.constData(), r.size()); + } + + PyObject* readRawData(QDataStream* d, int len) { + QByteArray r; + r.resize(len); + int result = d->readRawData(r.data(), r.size()); + if (result>=0) { + return PyString_FromStringAndSize(r.data(), result); + } else { + Py_INCREF(Py_None); + return Py_None; + } + } +