27 #ifndef PDCOM5_DATADESERIALIZER_H 28 #define PDCOM5_DATADESERIALIZER_H 35 #include <type_traits> 49 template <
class Derived>
62 typename std::enable_if<!std::is_arithmetic<T>::value,
void>::type
63 getValue(T &dest,
size_t offset = 0)
const;
70 typename std::enable_if<std::is_arithmetic<T>::value,
void>::type
73 const auto var =
static_cast<const Derived &
>(*this).getVariable();
74 const auto total_elements = var.getSizeInfo().totalElements();
75 if (offset >= total_elements)
77 "offset too large, must be less than " 78 + std::to_string(total_elements));
81 static_cast<const Derived &>(*this).getData(),
82 var.getTypeInfo().type, 1, offset);
85 template <
typename T,
size_t M,
size_t N>
86 void getValue(T (&dest)[M][N])
const 88 const auto var =
static_cast<const Derived &
>(*this).getVariable();
89 if (var.getSizeInfo().totalElements() != M * N)
91 "Size mismatch between destination and source");
94 static_cast<const Derived &>(*this).getData(),
95 var.getTypeInfo().type, M * N);
97 template <
typename T,
size_t N>
98 void getValue(T (&dest)[N],
size_t offset = 0)
const 100 const auto var =
static_cast<const Derived &
>(*this).getVariable();
101 const auto total_elements = var.getSizeInfo().totalElements();
102 if (offset >= total_elements)
103 throw InvalidArgument(
104 "offset too large, must be less than " 105 + std::to_string(total_elements));
107 dest, details::TypeInfoTraits<T>::type_info.type,
108 static_cast<const Derived &>(*this).getData(),
109 var.getTypeInfo().type,
110 std::min<size_t>(N, total_elements - offset), offset);
112 template <
typename T>
121 template <
class Derived>
122 template <
typename T>
123 inline typename std::enable_if<!std::is_arithmetic<T>::value,
void>::type
126 const auto var =
static_cast<const Derived &
>(*this).getVariable();
127 const auto total_elements = var.getSizeInfo().totalElements();
131 typename std::add_lvalue_reference<
132 typename T::value_type>::type>::value,
133 "Index operator does not return a lvalue reference of an " 135 if (offset >= total_elements)
137 const auto count = std::min<size_t>(dest.size(), total_elements - offset);
138 const auto src_type = var.getTypeInfo();
139 const auto dst_type =
142 const auto src =
static_cast<const Derived &
>(*this).getData();
144 for (
unsigned int i = 0; i < count; ++i) {
146 &dest[i], dst_type, src, src_type.type, 1, offset + i);
151 &dest[0], dst_type, src, src_type.type, count, offset);
158 #endif // PDCOM5_DATADESERIALIZER_H
std::enable_if< std::is_arithmetic< T >::value, void >::type getValue(T &dest, size_t offset=0) const
Copy the values into a custom buffer.
Definition: DataDeserializer.h:71
Definition: details.h:183
std::enable_if<!std::is_arithmetic< T >::value, void >::type getValue(T &dest, size_t offset=0) const
Copy the values into a custom buffer.
Definition: DataDeserializer.h:124
Data Deserialisation helper.
Definition: DataDeserializer.h:50
Definition: ClientStatistics.h:31
Definition: Exception.h:46