diff options
| author | Philip Rauwolf <rauwolf@itestra.de> | 2013-01-16 15:01:29 +0100 |
|---|---|---|
| committer | Philip Rauwolf <rauwolf@itestra.de> | 2013-01-16 15:01:29 +0100 |
| commit | 7eeabc04d81f1c292f4ac8be7b0b9ee7ed779f44 (patch) | |
| tree | 4dec24e4e3baaa29edd481df3ba1b00b832bb753 /src | |
| parent | fe5723c2af7fe0f7063533a2cf201371098a837a (diff) | |
| download | genivi-common-api-runtime-7eeabc04d81f1c292f4ac8be7b0b9ee7ed779f44.tar.gz | |
Finished integration of SerializableVariant into InputStream
Diffstat (limited to 'src')
| -rw-r--r-- | src/CommonAPI/InputStream.h | 18 | ||||
| -rw-r--r-- | src/CommonAPI/SerializableVariant.h | 4 | ||||
| -rw-r--r-- | src/CommonAPI/SerializableVariant.hpp | 36 |
3 files changed, 48 insertions, 10 deletions
diff --git a/src/CommonAPI/InputStream.h b/src/CommonAPI/InputStream.h index 1afdb3b..1be52ec 100644 --- a/src/CommonAPI/InputStream.h +++ b/src/CommonAPI/InputStream.h @@ -80,6 +80,7 @@ class InputStream { virtual void beginReadByteBufferVector() = 0; virtual void beginReadVersionVector() = 0; virtual void beginReadVectorOfSerializableStructs() = 0; + virtual void beginReadVectorOfSerializableVariants() = 0; virtual void beginReadVectorOfVectors() = 0; virtual void beginReadVectorOfMaps() = 0; @@ -247,9 +248,22 @@ struct InputStreamSerializableStructVectorHelper<_VectorElementType, true> { }; +template <typename _VectorElementType, bool _IsSerializableVariant = false> +struct InputStreamSerializableVariantVectorHelper: InputStreamSerializableStructVectorHelper<_VectorElementType, + std::is_base_of<SerializableStruct, _VectorElementType>::value> { +}; + +template <typename _VectorElementType> +struct InputStreamSerializableVariantVectorHelper<_VectorElementType, true> { + static void beginReadVector(InputStream& inputStream, const std::vector<_VectorElementType>& vectorValue) { + inputStream.beginReadVectorOfSerializableVariants(); + } +}; + + template <typename _VectorElementType> -struct InputStreamVectorHelper: InputStreamSerializableStructVectorHelper<_VectorElementType, - std::is_base_of<SerializableStruct, _VectorElementType>::value> { +struct InputStreamVectorHelper: InputStreamSerializableVariantVectorHelper<_VectorElementType, + std::is_base_of<SerializableVariant, _VectorElementType>::value> { }; /** diff --git a/src/CommonAPI/SerializableVariant.h b/src/CommonAPI/SerializableVariant.h index b579041..381b032 100644 --- a/src/CommonAPI/SerializableVariant.h +++ b/src/CommonAPI/SerializableVariant.h @@ -32,7 +32,7 @@ public: virtual uint8_t getValueType() const = 0; - virtual void readFromInputStream(InputStream& inputStream) = 0; + virtual void readFromInputStream(const uint8_t typeIndex, InputStream& inputStream) = 0; virtual void writeToOutputStream(OutputStream& outputStream) const = 0; virtual void writeToTypeOutputStream(TypeOutputStream& typeOutputStream) const = 0; @@ -81,7 +81,7 @@ public: ~Variant(); - virtual void readFromInputStream(InputStream& inputStream); + virtual void readFromInputStream(const uint8_t typeIndex, InputStream& inputStream); virtual void writeToOutputStream(OutputStream& outputStream) const; diff --git a/src/CommonAPI/SerializableVariant.hpp b/src/CommonAPI/SerializableVariant.hpp index 8c393e6..6ce14c0 100644 --- a/src/CommonAPI/SerializableVariant.hpp +++ b/src/CommonAPI/SerializableVariant.hpp @@ -4,11 +4,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef __VAR_IMPL__ -#define __VAR_IMPL__ +#ifndef COMMONAPI_SERIALIZABLE_VARIANT_IMPL_ +#define COMMONAPI_SERIALIZABLE_VARIANT_IMPL_ #include "OutputStream.h" +#include "InputStream.h" namespace CommonAPI { @@ -146,6 +146,28 @@ private: OutputStream& outputStream_; }; + +template<typename ... _Types> +struct InputStreamReadVisitor { +public: + InputStreamReadVisitor(Variant<_Types...>& lhs, InputStream& inputStream) : + lhs_(lhs), + inputStream_(inputStream) { + } + + template<typename _Type> + void operator()(const _Type&) { + _Type value; + inputStream_ >> value; + lhs_.template set<_Type>(std::move(value), true); + } + +private: + Variant<_Types...>& lhs_; + InputStream& inputStream_; +}; + + template<typename _Type> struct TypeEqualsVisitor { @@ -327,8 +349,10 @@ Variant<_Types...>::~Variant() { } template<typename ... _Types> -void Variant<_Types...>::readFromInputStream(InputStream& inputStream) { - //TODO +void Variant<_Types...>::readFromInputStream(const uint8_t typeIndex, InputStream& inputStream) { + valueType_ = typeIndex; + InputStreamReadVisitor<_Types...> visitor(*this, inputStream); + ApplyVoidVisitor<InputStreamReadVisitor<_Types...>, Variant<_Types...>, _Types...>::visit(visitor, *this); } template<typename ... _Types> @@ -461,4 +485,4 @@ bool Variant<_Types...>::operator!=(const Variant<_Types...>& rhs) const } -#endif +#endif //COMMONAPI_SERIALIZABLE_VARIANT_IMPL_ |
