Dev Essential  1.6.3
Loading...
Searching...
No Matches
value_access.h
Go to the documentation of this file.
1
11
12#ifndef DDL_PREVIEW_VALUE_ACCESS_PRIVATE_CLASS_HEADER
13#define DDL_PREVIEW_VALUE_ACCESS_PRIVATE_CLASS_HEADER
14
15#include <a_util/result.h>
17
18#include <vector>
19
20namespace ddl {
21namespace codec {
22
23#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
24#pragma GCC diagnostic ignored \
25 "-Wattributes" // standard type attributes are ignored when used in templates
26#endif // defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
27
28namespace detail {
29
30template <typename ValueType>
32 : public std::is_convertible<a_util::variant::Variant,
33 a_util::underlying_type_or_type_t<ValueType>> {
34};
35
36template <typename ValueType>
38 : public std::is_convertible<a_util::underlying_type_or_type_t<ValueType>,
39 a_util::variant::Variant> {
40};
41
42} // namespace detail
43
44#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
45#pragma GCC diagnostic warning \
46 "-Wattributes" // standard type attributes are ignored when used in templates
47#endif // defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
48
56template <typename DecoderType, typename ValueType>
65 static void getValue(const DecoderType& decoder,
66 const CodecIndex& codec_index,
67 ValueType& value)
68 {
70 "Unsupported type for decode. "
71 "By default bool, all int types, float, double, std::string is supported. "
72 "To support your own data type, create a specialization of this template");
73 a_util::variant::Variant variant_value;
74 decoder.getElementVariantValue(codec_index, variant_value);
75 value = static_cast<ValueType>(
76 static_cast<a_util::underlying_type_or_type_t<ValueType>>(variant_value));
77 }
78};
79
84template <typename DecoderType>
85struct ValueGetter<DecoderType, std::string> {
93 static void getValue(const DecoderType& decoder,
94 const CodecIndex& codec_index,
95 std::string& value)
96 {
97 value = decoder.getElementStringValue(codec_index);
98 }
99};
100
108template <typename CodecType, typename ValueType>
117 static void setValue(CodecType& codec, const CodecIndex& codec_index, const ValueType& value)
118 {
120 "Unsupported type for decode. "
121 "By default bool, all int types, float, double, std::string is supported. "
122 "To support your own data type, create a specialization of this template");
123 codec.setElementVariantValue(
124 codec_index,
127 }
128};
129
134template <typename CodecType>
135struct ValueSetter<CodecType, std::string> {
143 static void setValue(CodecType& codec, const CodecIndex& codec_index, const std::string& value)
144 {
145 codec.setElementStringValue(codec_index, value);
146 }
147};
148
157template <typename DecoderType,
158 typename ValueType,
159 bool is_supported_leaf_type = detail::SupportedLeafValueTypeExplicit<ValueType>::value>
168 static ValueType getValue(const DecoderType& decoder, const CodecIndex& codec_index)
169 {
170 ValueType value;
171 ValueGetter<DecoderType, ValueType>::getValue(decoder, codec_index, value);
172 return value;
173 }
174};
175
184template <typename DecoderType, typename ValueType>
185struct ValueGetterSelect<DecoderType, ValueType, true> {
193 static ValueType getValue(const DecoderType& decoder, const CodecIndex& codec_index)
194 {
195 LeafLayout leaf_layout;
197 codec_index, leaf_layout, decoder.getRepresentation())) {
199 decoder.getData(), decoder.getDataSize(), leaf_layout);
200 }
201 else {
202 ValueType value;
203 ValueGetter<DecoderType, ValueType>::getValue(decoder, codec_index, value);
204 return value;
205 }
206 }
207};
208
216template <typename CodecType,
217 typename ValueType,
218 bool is_supported_leaf_type = detail::SupportedLeafValueTypeExplicit<ValueType>::value>
227 static void setValue(CodecType& codec, const CodecIndex& codec_index, const ValueType& value)
228 {
230 }
231};
232
240template <typename CodecType, typename ValueType>
241struct ValueSetterSelect<CodecType, ValueType, true> {
249 static void setValue(CodecType& codec, const CodecIndex& codec_index, const ValueType& value)
250 {
251 LeafLayout leaf_layout;
253 codec_index, leaf_layout, codec.getRepresentation())) {
255 codec.getData(), codec.getDataSize(), leaf_layout, value);
256 }
257 else {
259 }
260 }
261};
262
263} // namespace codec
264} // namespace ddl
265
266#endif // DDL_VALUE_ACCESS_PRIVATE_CLASS_HEADER
Definition variant.h:46
Definition codec_index.h:276
static bool convertToLeafLayout(const CodecIndex &codec_index, LeafLayout &leaf_layout, ddl::DataRepresentation rep)
Retrieves a valid, small, 8-bytes LeafLayout from a CodecIndex.
Definition leaf_value_access.h:83
typename underlying_type_or_type< T, is_enum >::type underlying_type_or_type_t
Retrieves the underlying type if T is an enum, otherwise the type itself.
Definition type_traits.h:89
Namespace for the new faster CodecFactory/Decoder/Codec implementation.
Definition codec.h:22
definition of the ddl namespace
Definition codec.h:21
small leaf layout information to access codec data very fast.
Definition leaf_layout.h:76
static ValueType getValue(const void *data, const size_t data_size, const LeafLayout &leaf_layout)
Definition leaf_value_access.h:789
static void setValue(void *data, const size_t data_size, const LeafLayout &leaf_layout, const ValueType &value)
Definition leaf_value_access.h:820
static ValueType getValue(const DecoderType &decoder, const CodecIndex &codec_index)
Definition value_access.h:193
Definition value_access.h:160
static ValueType getValue(const DecoderType &decoder, const CodecIndex &codec_index)
Definition value_access.h:168
static void getValue(const DecoderType &decoder, const CodecIndex &codec_index, std::string &value)
Definition value_access.h:93
Definition value_access.h:57
static void getValue(const DecoderType &decoder, const CodecIndex &codec_index, ValueType &value)
Definition value_access.h:65
static void setValue(CodecType &codec, const CodecIndex &codec_index, const ValueType &value)
Definition value_access.h:249
Definition value_access.h:219
static void setValue(CodecType &codec, const CodecIndex &codec_index, const ValueType &value)
Definition value_access.h:227
static void setValue(CodecType &codec, const CodecIndex &codec_index, const std::string &value)
Definition value_access.h:143
Definition value_access.h:109
static void setValue(CodecType &codec, const CodecIndex &codec_index, const ValueType &value)
Definition value_access.h:117