From 3ec127afde9eaf23fae65779f6c7633ae19623a9 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sun, 15 Jun 2014 16:46:43 -0700 Subject: [PATCH] Spoke a little too soon. --- libraries/metavoxels/src/Bitstream.h | 6 +++++- tools/mtc/src/main.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/metavoxels/src/Bitstream.h b/libraries/metavoxels/src/Bitstream.h index 23943444d9..e9599e9e87 100644 --- a/libraries/metavoxels/src/Bitstream.h +++ b/libraries/metavoxels/src/Bitstream.h @@ -1418,6 +1418,7 @@ public: Bitstream& operator>>(Bitstream& in, X& obj); \ template<> void Bitstream::writeRawDelta(const X& value, const X& reference); \ template<> void Bitstream::readRawDelta(X& value, const X& reference); \ + template<> QJsonValue JSONWriter::getData(const X& value); \ bool operator==(const X& first, const X& second); \ bool operator!=(const X& first, const X& second); \ static const int* _TypePtr##X = &X::Type; @@ -1427,6 +1428,7 @@ public: Bitstream& operator>>(Bitstream& in, X& obj); \ template<> void Bitstream::writeRawDelta(const X& value, const X& reference); \ template<> void Bitstream::readRawDelta(X& value, const X& reference); \ + template<> QJsonValue JSONWriter::getData(const X& value); \ bool operator==(const X& first, const X& second); \ bool operator!=(const X& first, const X& second); \ __attribute__((unused)) static const int* _TypePtr##X = &X::Type; @@ -1437,6 +1439,7 @@ public: Bitstream& operator>>(Bitstream& in, X& obj); \ template<> void Bitstream::writeRawDelta(const X& value, const X& reference); \ template<> void Bitstream::readRawDelta(X& value, const X& reference); \ + template<> QJsonValue JSONWriter::getData(const X& value); \ bool operator==(const X& first, const X& second); \ bool operator!=(const X& first, const X& second); \ static const int* _TypePtr##X = &X::Type; \ @@ -1447,7 +1450,8 @@ public: Bitstream& operator<<(Bitstream& out, const S::N& obj); \ Bitstream& operator>>(Bitstream& in, S::N& obj); \ template<> inline void Bitstream::writeRawDelta(const S::N& value, const S::N& reference) { *this << value; } \ - template<> inline void Bitstream::readRawDelta(S::N& value, const S::N& reference) { *this >> value; } + template<> inline void Bitstream::readRawDelta(S::N& value, const S::N& reference) { *this >> value; } \ + template<> inline QJsonValue JSONWriter::getData(const S::N& value) { return (int)value; } #define IMPLEMENT_ENUM_METATYPE(S, N) \ static int S##N##MetaTypeId = registerEnumMetaType(&S::staticMetaObject, #N); \ diff --git a/tools/mtc/src/main.cpp b/tools/mtc/src/main.cpp index 096ade4625..eadccdb310 100644 --- a/tools/mtc/src/main.cpp +++ b/tools/mtc/src/main.cpp @@ -217,6 +217,19 @@ void generateOutput (QTextStream& out, const QList& streamables) { } out << "}\n"; + out << "template<> QJsonValue JSONWriter::getData(const " << name << "& value) {\n"; + out << " QJsonArray array;\n"; + foreach (const QString& base, str.clazz.bases) { + out << " foreach (const QJsonValue& element, getData(static_cast(value)).toArray()) {\n"; + out << " array.append(element);\n"; + out << " }\n"; + } + foreach (const Field& field, str.fields) { + out << " array.append(getData(value." << field.name << "));\n"; + } + out << " return array;\n"; + out << "}\n"; + out << "bool operator==(const " << name << "& first, const " << name << "& second) {\n"; if (str.clazz.bases.isEmpty() && str.fields.isEmpty()) { out << " return true";