From 72b002ddc462761ade30efa963ac98859743aad8 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 31 Dec 2013 17:30:41 -0800 Subject: [PATCH] Allow streaming QVariantLists. --- libraries/metavoxels/src/Bitstream.cpp | 21 +++++++++++++++++++++ libraries/metavoxels/src/Bitstream.h | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libraries/metavoxels/src/Bitstream.cpp b/libraries/metavoxels/src/Bitstream.cpp index 819373b733..258ef1ca29 100644 --- a/libraries/metavoxels/src/Bitstream.cpp +++ b/libraries/metavoxels/src/Bitstream.cpp @@ -236,6 +236,27 @@ Bitstream& Bitstream::operator>>(QVariant& value) { return *this; } +Bitstream& Bitstream::operator<<(const QVariantList& value) { + *this << value.size(); + foreach (const QVariant& entry, value) { + *this << entry; + } + return *this; +} + +Bitstream& Bitstream::operator>>(QVariantList& value) { + int size; + *this >> size; + value.clear(); + value.reserve(size); + for (int i = 0; i < size; i++) { + QVariant entry; + *this >> entry; + value.append(entry); + } + return *this; +} + Bitstream& Bitstream::operator<<(const QObject* object) { if (!object) { _metaObjectStreamer << NULL; diff --git a/libraries/metavoxels/src/Bitstream.h b/libraries/metavoxels/src/Bitstream.h index 36bcafd80d..066da71b34 100644 --- a/libraries/metavoxels/src/Bitstream.h +++ b/libraries/metavoxels/src/Bitstream.h @@ -231,6 +231,9 @@ public: Bitstream& operator<<(const QVariant& value); Bitstream& operator>>(QVariant& value); + Bitstream& operator<<(const QVariantList& value); + Bitstream& operator>>(QVariantList& value); + Bitstream& operator<<(const QObject* object); Bitstream& operator>>(QObject*& object); @@ -287,8 +290,8 @@ public: #define REGISTER_SIMPLE_TYPE_STREAMER(x) static int x##Streamer = \ Bitstream::registerTypeStreamer(QMetaType::type(#x), new SimpleTypeStreamer()); -/// Declares the metatype and the streaming operators. The last line -/// ensures that the generated file will be included in the link phase. +/// Declares the metatype and the streaming operators. The last lines +/// ensure that the generated file will be included in the link phase. #define STRINGIFY(x) #x #define DECLARE_STREAMABLE_METATYPE(X) Q_DECLARE_METATYPE(X) \ Bitstream& operator<<(Bitstream& out, const X& obj); \