diff --git a/sdrbase/util/simpleserializer.h b/sdrbase/util/simpleserializer.h index c2b328e8e..2920cf4e7 100644 --- a/sdrbase/util/simpleserializer.h +++ b/sdrbase/util/simpleserializer.h @@ -26,9 +26,29 @@ public: void writeString(quint32 id, const QString& value); void writeBlob(quint32 id, const QByteArray& value); + template + void writeList(quint32 id, const QList& value) + { + QByteArray data; + QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly); + (*stream) << value; + delete stream; + writeBlob(id, data); + } + template + void writeHash(quint32 id, const QHash& value) + { + QByteArray data; + QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly); + (*stream) << value; + delete stream; + writeBlob(id, data); + } + const QByteArray& final(); protected: + // Lists and hashes are written as TBlob enum Type { TSigned32 = 0, TUnsigned32 = 1, @@ -63,6 +83,33 @@ public: bool readString(quint32 id, QString* result, const QString& def = QString()) const; bool readBlob(quint32 id, QByteArray* result, const QByteArray& def = QByteArray()) const; + template + bool readList(quint32 id, QList* result) + { + QByteArray data; + bool ok = readBlob(id, &data); + if (ok) + { + QDataStream *stream = new QDataStream(data); + (*stream) >> *result; + delete stream; + } + return ok; + } + template + bool readHash(quint32 id, QHash* result) + { + QByteArray data; + bool ok = readBlob(id, &data); + if (ok) + { + QDataStream *stream = new QDataStream(data); + (*stream) >> *result; + delete stream; + } + return ok; + } + bool isValid() const { return m_valid; } quint32 getVersion() const { return m_version; } void dump() const;