From 600e9cbf52197467d3f02c945e85c6dba42a1185 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 8 Jul 2015 18:17:03 -0700 Subject: [PATCH] Fixing template specialization compilation error on gcc/clang --- libraries/shared/src/BufferParser.h | 91 +++++++++++++++-------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/libraries/shared/src/BufferParser.h b/libraries/shared/src/BufferParser.h index 622d59d125..5d388a6f5f 100644 --- a/libraries/shared/src/BufferParser.h +++ b/libraries/shared/src/BufferParser.h @@ -26,54 +26,13 @@ public: } template - void readValue(T& result) { + inline void readValue(T& result) { Q_ASSERT(remaining() >= sizeof(T)); memcpy(&result, _data + _offset, sizeof(T)); _offset += sizeof(T); } - template<> - void readValue(quat& result) { - size_t advance = unpackOrientationQuatFromBytes(_data + _offset, result); - _offset += advance; - } - - template<> - void readValue(QString& result) { - uint16_t length; readValue(length); - result = QString((const char*)_data + _offset); - } - - template<> - void readValue(QUuid& result) { - uint16_t length; readValue(length); - Q_ASSERT(16 == length); - readUuid(result); - } - - template<> - void readValue(xColor& result) { - readValue(result.red); - readValue(result.blue); - readValue(result.green); - } - - template<> - void readValue>(QVector& result) { - uint16_t length; readValue(length); - result.resize(length); - memcpy(result.data(), _data + _offset, sizeof(glm::vec3) * length); - _offset += sizeof(glm::vec3) * length; - } - - template<> - void readValue(QByteArray& result) { - uint16_t length; readValue(length); - result = QByteArray((char*)_data + _offset, (int)length); - _offset += length; - } - - void readUuid(QUuid& result) { + inline void readUuid(QUuid& result) { readValue(result.data1); readValue(result.data2); readValue(result.data3); @@ -84,7 +43,7 @@ public: } template - void readFlags(PropertyFlags& result) { + inline void readFlags(PropertyFlags& result) { // FIXME doing heap allocation QByteArray encoded((const char*)(_data + _offset), remaining()); result.decode(encoded); @@ -92,7 +51,7 @@ public: } template - void readCompressedCount(T& result) { + inline void readCompressedCount(T& result) { // FIXME switch to a heapless implementation as soon as Brad provides it. QByteArray encoded((const char*)(_data + _offset), std::min(sizeof(T) << 1, remaining())); ByteCountCoded codec = encoded; @@ -120,4 +79,46 @@ private: const size_t _size; }; + +template<> +inline void BufferParser::readValue(quat& result) { + size_t advance = unpackOrientationQuatFromBytes(_data + _offset, result); + _offset += advance; +} + +template<> +inline void BufferParser::readValue(QString& result) { + uint16_t length; readValue(length); + result = QString((const char*)_data + _offset); +} + +template<> +inline void BufferParser::readValue(QUuid& result) { + uint16_t length; readValue(length); + Q_ASSERT(16 == length); + readUuid(result); +} + +template<> +inline void BufferParser::readValue(xColor& result) { + readValue(result.red); + readValue(result.blue); + readValue(result.green); +} + +template<> +inline void BufferParser::readValue(QVector& result) { + uint16_t length; readValue(length); + result.resize(length); + memcpy(result.data(), _data + _offset, sizeof(glm::vec3) * length); + _offset += sizeof(glm::vec3) * length; +} + +template<> +inline void BufferParser::readValue(QByteArray& result) { + uint16_t length; readValue(length); + result = QByteArray((char*)_data + _offset, (int)length); + _offset += length; +} + #endif