summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilip Rauwolf <rauwolf@itestra.de>2013-01-17 17:09:01 +0100
committerPhilip Rauwolf <rauwolf@itestra.de>2013-01-17 17:09:01 +0100
commit7464d194bd83de555ad77eb6b5633aab2f9f1bf8 (patch)
tree6139de73dea39b54047ca5b0bb0ff056616a464c /src
parent2e3b3ca28136c51d6e8bf0a243d11e02c609857b (diff)
downloadgenivi-common-api-runtime-7464d194bd83de555ad77eb6b5633aab2f9f1bf8.tar.gz
Variants fully integrated into inputStream, Bugfixing Variants and
datatype "ByteBuffer"
Diffstat (limited to 'src')
-rw-r--r--src/CommonAPI/InputStream.h4
-rw-r--r--src/CommonAPI/SerializableStruct.h1
-rw-r--r--src/CommonAPI/SerializableVariant.h22
-rw-r--r--src/CommonAPI/SerializableVariant.hpp55
4 files changed, 34 insertions, 48 deletions
diff --git a/src/CommonAPI/InputStream.h b/src/CommonAPI/InputStream.h
index 1be52ec..b31411a 100644
--- a/src/CommonAPI/InputStream.h
+++ b/src/CommonAPI/InputStream.h
@@ -151,10 +151,6 @@ inline InputStream& operator>>(InputStream& inputStream, std::string& stringValu
return inputStream.readValue(stringValue);
}
-inline InputStream& operator>>(InputStream& inputStream, ByteBuffer& byteBufferValue) {
- return inputStream.readValue(byteBufferValue);
-}
-
inline InputStream& operator>>(InputStream& inputStream, Version& versionValue) {
return inputStream.readVersionValue(versionValue);
}
diff --git a/src/CommonAPI/SerializableStruct.h b/src/CommonAPI/SerializableStruct.h
index 828479b..d3749b1 100644
--- a/src/CommonAPI/SerializableStruct.h
+++ b/src/CommonAPI/SerializableStruct.h
@@ -15,6 +15,7 @@ namespace CommonAPI {
class InputStream;
class OutputStream;
+class TypeOutputStream;
struct SerializableStruct {
virtual ~SerializableStruct() { }
diff --git a/src/CommonAPI/SerializableVariant.h b/src/CommonAPI/SerializableVariant.h
index 1aae1d2..d7af954 100644
--- a/src/CommonAPI/SerializableVariant.h
+++ b/src/CommonAPI/SerializableVariant.h
@@ -115,26 +115,36 @@ public:
typename std::enable_if<!std::is_same<_Type, Variant>::value>::type* = 0);
template <typename _Type>
- const typename VariantTypeSelector<_Type, _Types...>::type & get(bool& success) const;
+ const typename VariantTypeSelector<_Type, _Types...>::type& get() const;
inline uint8_t getValueType() const {
return valueType_;
}
+private:
+ inline bool hasValue() const {
+ return valueType_ < TypesTupleSize::value;
+ }
+
template<typename _U>
void set( const _U& value, const bool clear);
template<typename _U>
void set( _U&& value, const bool clear);
-private:
- inline bool hasValue() const {
- return valueType_ < TypesTupleSize::value;
- }
+ template<typename _FriendType>
+ friend struct TypeWriter;
+ template<typename ... _FriendTypes>
+ friend struct AssignmentVisitor;
+ template<typename _FriendType>
+ friend struct TypeEqualsVisitor;
+ template<typename ... _FriendTypes>
+ friend struct PartialEqualsVisitor;
+ template<typename ... _FriendTypes>
+ friend struct InputStreamReadVisitor;
uint8_t valueType_;
typename std::aligned_storage<maxSize>::type valueStorage_;
-
};
} // namespace CommonAPI
diff --git a/src/CommonAPI/SerializableVariant.hpp b/src/CommonAPI/SerializableVariant.hpp
index 19b09e8..b42e4de 100644
--- a/src/CommonAPI/SerializableVariant.hpp
+++ b/src/CommonAPI/SerializableVariant.hpp
@@ -9,21 +9,11 @@
#include "OutputStream.h"
#include "InputStream.h"
-#include <iostream>
-namespace CommonAPI {
+#include <exception>
-template<typename _Type>
-struct TypeWriter;
-template<typename ... _Types>
-struct AssignmentVisitor;
-
-template<typename _Type>
-struct TypeEqualsVisitor;
-
-template<typename ... _Types>
-struct PartialEqualsVisitor;
+namespace CommonAPI {
template<class Visitor, class Variant, typename ... _Types>
struct ApplyVoidVisitor;
@@ -50,21 +40,17 @@ struct ApplyVoidVisitor<Visitor, Variant, _Type, _Types...> {
static const uint8_t index = ApplyVoidVisitor<Visitor, Variant,
_Types...>::index + 1;
- static
- void visit(Visitor& visitor, Variant& var) {
+ static void visit(Visitor& visitor, Variant& var) {
if (var.getValueType() == index) {
- bool b;
- visitor(var.template get<_Type>(b));
+ visitor(var.template get<_Type>());
} else {
ApplyVoidVisitor<Visitor, Variant, _Types...>::visit(visitor, var);
}
}
- static
- void visit(Visitor& visitor, const Variant& var) {
+ static void visit(Visitor& visitor, const Variant& var) {
if (var.getValueType() == index) {
- bool b;
- visitor(var.template get<_Type>(b));
+ visitor(var.template get<_Type>());
} else {
ApplyVoidVisitor<Visitor, Variant, _Types...>::visit(visitor, var);
}
@@ -92,8 +78,7 @@ struct ApplyBoolVisitor<Visitor, Variant, _Type, _Types...> {
static bool visit(Visitor& visitor, Variant& var) {
if (var.getValueType() == index) {
- bool b;
- return visitor(var.template get<_Type>(b));
+ return visitor(var.template get<_Type>());
} else {
return ApplyBoolVisitor<Visitor, Variant, _Types...>::visit(visitor,
var);
@@ -173,21 +158,15 @@ template<typename _Type>
struct TypeEqualsVisitor
{
public:
- TypeEqualsVisitor(const _Type& rhs) :
- rhs_(rhs)
- {
+ TypeEqualsVisitor(const _Type& rhs): rhs_(rhs) {
}
- bool
- operator()(const _Type& lhs) const
- {
+ bool operator()(const _Type& lhs) const {
return lhs == rhs_;
}
template<typename _U>
- bool
- operator()(const _U&) const
- {
+ bool operator()(const _U&) const {
return false;
}
@@ -391,9 +370,8 @@ Variant<_Types...>& Variant<_Types...>::operator=(Variant<_Types...>&& rhs) {
template<typename ... _Types>
template<typename _Type>
typename std::enable_if<!std::is_same<_Type, Variant<_Types...>>::value, Variant<_Types...>&>::type
-Variant<_Types...>::operator=(const _Type& value)
- {
- set<typename TypeSelector<_Type, _Types...>::type>(value);
+Variant<_Types...>::operator=(const _Type& value) {
+ set<typename TypeSelector<_Type, _Types...>::type>(value, hasValue());
return *this;
}
@@ -427,20 +405,21 @@ typename std::enable_if<!std::is_same<_Type, Variant<_Types...>>::value>::type*)
set<typename TypeSelector<_Type, _Types...>::type>(std::move(value), false);
}
+
template<typename ... _Types>
template<typename _Type>
-const typename VariantTypeSelector<_Type, _Types...>::type & Variant<_Types...>::get(bool& success) const {
+const typename VariantTypeSelector<_Type, _Types...>::type & Variant<_Types...>::get() const {
typedef typename TypeSelector<_Type, _Types...>::type selected_type_t;
uint8_t cType = TypeIndex<_Types...>::template get<selected_type_t>();
if (cType == valueType_) {
- success = true;
return *(reinterpret_cast<const _Type *>(&valueStorage_));
} else {
- success = false;
- return *(reinterpret_cast<const _Type *>(&valueStorage_));
+ std::bad_cast toThrow;
+ throw toThrow;
}
}
+
template<typename ... _Types>
template<typename _U>
void Variant<_Types...>::set(const _U& value, const bool clear) {