mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -05:00
SimpleSerializer: Add read/write QList and QHash
This commit is contained in:
parent
38120a7ce3
commit
ee3b41b5e2
@ -26,9 +26,29 @@ public:
|
||||
void writeString(quint32 id, const QString& value);
|
||||
void writeBlob(quint32 id, const QByteArray& value);
|
||||
|
||||
template<typename T>
|
||||
void writeList(quint32 id, const QList<T>& value)
|
||||
{
|
||||
QByteArray data;
|
||||
QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
|
||||
(*stream) << value;
|
||||
delete stream;
|
||||
writeBlob(id, data);
|
||||
}
|
||||
template<typename TK, typename TV>
|
||||
void writeHash(quint32 id, const QHash<TK,TV>& 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<typename T>
|
||||
bool readList(quint32 id, QList<T>* result)
|
||||
{
|
||||
QByteArray data;
|
||||
bool ok = readBlob(id, &data);
|
||||
if (ok)
|
||||
{
|
||||
QDataStream *stream = new QDataStream(data);
|
||||
(*stream) >> *result;
|
||||
delete stream;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
template<typename TK, typename TV>
|
||||
bool readHash(quint32 id, QHash<TK,TV>* 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;
|
||||
|
Loading…
Reference in New Issue
Block a user