6#include <bond/core/config.h>
9#include <bond/core/reflection.h>
11#include <boost/utility/enable_if.hpp>
16template <
typename Protocols,
typename X,
typename Key,
typename T>
17typename boost::enable_if<is_map_key_matching<Key, X> >::type
18inline DeserializeMapElements(X& var,
const Key& key,
const T& element, uint32_t size);
20template <
typename Protocols,
typename X,
typename Key,
typename T>
21typename boost::disable_if<is_map_key_matching<Key, X> >::type
22inline DeserializeMapElements(X&,
const Key& key,
const T& element, uint32_t size);
24template <
typename Protocols,
typename Transform,
typename Key,
typename T>
25inline void DeserializeMapElements(
const Transform& transform,
const Key& key,
const T& element, uint32_t size);
27template <
typename Protocols,
typename X,
typename T>
28typename boost::enable_if_c<is_list_container<X>::value
29 && is_element_matching<T, X>::value>::type
30inline DeserializeElements(X& var,
const T& element, uint32_t size);
32template <
typename Protocols,
typename X,
typename T>
33typename boost::enable_if<is_matching<T, X> >::type
34inline DeserializeElements(nullable<X>& var,
const T& element, uint32_t size);
36template <
typename Protocols,
typename Reader>
37inline void DeserializeElements(blob& var,
const value<blob::value_type, Reader&>& element, uint32_t size);
39template <
typename Protocols,
typename X,
typename T>
40typename boost::enable_if_c<is_set_container<X>::value
41 && is_element_matching<T, X>::value>::type
42inline DeserializeElements(X& var,
const T& element, uint32_t size);
44template <
typename Protocols,
typename X,
typename T>
45typename boost::disable_if<is_element_matching<T, X> >::type
46inline DeserializeElements(X&,
const T& element, uint32_t size);
48template <
typename Protocols,
typename Transform,
typename T>
49inline void DeserializeElements(
const Transform& transform,
const T& element, uint32_t size);
59bool IsMatching(BondDataType type)
64 return is_matching<bool, T>::value;
67 return is_matching<uint8_t, T>::value;
70 return is_matching<uint16_t, T>::value;
73 return is_matching<uint32_t, T>::value;
76 return is_matching<uint64_t, T>::value;
79 return is_matching<float, T>::value;
82 return is_matching<double, T>::value;
85 return is_matching<std::string, T>::value;
87 case bond::BT_WSTRING:
88 return is_matching<std::wstring, T>::value;
91 return is_matching<int8_t, T>::value;
94 return is_matching<int16_t, T>::value;
97 return is_matching<int32_t, T>::value;
100 return is_matching<int64_t, T>::value;
109template <
typename Transform,
typename Reader>
110inline bool BasicTypeField(uint16_t
id,
const Metadata& metadata, BondDataType type,
const Transform& transform, Reader& input)
115 return transform.Field(
id, metadata, value<bool, Reader&>(input));
118 return transform.Field(
id, metadata, value<uint8_t, Reader&>(input));
120 case bond::BT_UINT16:
121 return transform.Field(
id, metadata, value<uint16_t, Reader&>(input));
123 case bond::BT_UINT32:
124 return transform.Field(
id, metadata, value<uint32_t, Reader&>(input));
126 case bond::BT_UINT64:
127 return transform.Field(
id, metadata, value<uint64_t, Reader&>(input));
130 return transform.Field(
id, metadata, value<float, Reader&>(input));
132 case bond::BT_DOUBLE:
133 return transform.Field(
id, metadata, value<double, Reader&>(input));
135 case bond::BT_STRING:
136 return transform.Field(
id, metadata, value<std::string, Reader&>(input));
138 case bond::BT_WSTRING:
139 return transform.Field(
id, metadata, value<std::wstring, Reader&>(input));
142 return transform.Field(
id, metadata, value<int8_t, Reader&>(input));
145 return transform.Field(
id, metadata, value<int16_t, Reader&>(input));
148 return transform.Field(
id, metadata, value<int32_t, Reader&>(input));
151 return transform.Field(
id, metadata, value<int64_t, Reader&>(input));
160template <
typename Protocols,
typename T,
typename Reader>
161inline void BasicTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
163 BOOST_STATIC_ASSERT(!is_container<T>::value);
168 return DeserializeElements<Protocols>(var, value<bool, Reader&>(input,
false), size);
171 return DeserializeElements<Protocols>(var, value<uint8_t, Reader&>(input,
false), size);
173 case bond::BT_UINT16:
174 return DeserializeElements<Protocols>(var, value<uint16_t, Reader&>(input,
false), size);
176 case bond::BT_UINT32:
177 return DeserializeElements<Protocols>(var, value<uint32_t, Reader&>(input,
false), size);
179 case bond::BT_UINT64:
180 return DeserializeElements<Protocols>(var, value<uint64_t, Reader&>(input,
false), size);
183 return DeserializeElements<Protocols>(var, value<float, Reader&>(input,
false), size);
185 case bond::BT_DOUBLE:
186 return DeserializeElements<Protocols>(var, value<double, Reader&>(input,
false), size);
188 case bond::BT_STRING:
189 return DeserializeElements<Protocols>(var, value<std::string, Reader&>(input,
false), size);
191 case bond::BT_WSTRING:
192 return DeserializeElements<Protocols>(var, value<std::wstring, Reader&>(input,
false), size);
195 return DeserializeElements<Protocols>(var, value<int8_t, Reader&>(input,
false), size);
198 return DeserializeElements<Protocols>(var, value<int16_t, Reader&>(input,
false), size);
201 return DeserializeElements<Protocols>(var, value<int32_t, Reader&>(input,
false), size);
204 return DeserializeElements<Protocols>(var, value<int64_t, Reader&>(input,
false), size);
214inline void SkipElements(
const E& element, uint32_t size)
220template <
typename Reader>
221inline void SkipElements(BondDataType type, Reader& input, uint32_t size)
229template <
typename Protocols,
typename T,
typename Reader>
230typename boost::enable_if<is_type_alias<typename element_type<T>::type> >::type
231inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
233 if (type == get_type_id<
typename element_type<T>::type>::value)
235 DeserializeElements<Protocols>(var, value<
typename element_type<T>::type, Reader&>(input,
false), size);
239 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
241 SkipElements(type, input, size);
246template <
typename Protocols,
typename T,
typename Reader>
247typename boost::enable_if<std::is_same<bool, typename element_type<T>::type> >::type
248inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
253 return DeserializeElements<Protocols>(var, value<bool, Reader&>(input,
false), size);
256 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
258 SkipElements(type, input, size);
264template <
typename Protocols,
typename T,
typename Reader>
265typename boost::enable_if<is_string<typename element_type<T>::type> >::type
266inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
270 case bond::BT_STRING:
271 return DeserializeElements<Protocols>(var, value<std::string, Reader&>(input,
false), size);
274 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
276 SkipElements(type, input, size);
282template <
typename Protocols,
typename T,
typename Reader>
283typename boost::enable_if<is_wstring<typename element_type<T>::type> >::type
284inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
288 case bond::BT_WSTRING:
289 return DeserializeElements<Protocols>(var, value<std::wstring, Reader&>(input,
false), size);
292 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
294 SkipElements(type, input, size);
300template <
typename Protocols,
typename T,
typename Reader>
301typename boost::enable_if<std::is_floating_point<typename element_type<T>::type> >::type
302inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
307 return DeserializeElements<Protocols>(var, value<float, Reader&>(input,
false), size);
309 case bond::BT_DOUBLE:
310 return DeserializeElements<Protocols>(var, value<double, Reader&>(input,
false), size);
313 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
315 SkipElements(type, input, size);
321template <
typename Protocols,
typename T,
typename Reader>
322typename boost::enable_if<is_matching<uint8_t, typename element_type<T>::type> >::type
323inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
328 return DeserializeElements<Protocols>(var, value<uint8_t, Reader&>(input,
false), size);
330 case bond::BT_UINT16:
331 return DeserializeElements<Protocols>(var, value<uint16_t, Reader&>(input,
false), size);
333 case bond::BT_UINT32:
334 return DeserializeElements<Protocols>(var, value<uint32_t, Reader&>(input,
false), size);
336 case bond::BT_UINT64:
337 return DeserializeElements<Protocols>(var, value<uint64_t, Reader&>(input,
false), size);
340 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
342 SkipElements(type, input, size);
348template <
typename Protocols,
typename T,
typename Reader>
349typename boost::enable_if<is_matching<int8_t, typename element_type<T>::type> >::type
350inline MatchingTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
355 return DeserializeElements<Protocols>(var, value<int8_t, Reader&>(input,
false), size);
358 return DeserializeElements<Protocols>(var, value<int16_t, Reader&>(input,
false), size);
361 return DeserializeElements<Protocols>(var, value<int32_t, Reader&>(input,
false), size);
364 return DeserializeElements<Protocols>(var, value<int64_t, Reader&>(input,
false), size);
367 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type>(type));
369 SkipElements(type, input, size);
378template <
typename E,
typename Reader>
379inline void SkipElements(BondDataType keyType,
const E& element, Reader& input, uint32_t size)
388template <
typename Protocols,
typename T,
typename E,
typename Reader>
389typename boost::enable_if<is_type_alias<typename element_type<T>::type::first_type> >::type
390inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
392 if (keyType == get_type_id<
typename element_type<T>::type::first_type>::value)
394 return DeserializeMapElements<Protocols>(var, value<
typename element_type<T>::type::first_type, Reader&>(input,
false), element, size);
398 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
400 SkipElements(keyType, element, input, size);
405template <
typename Protocols,
typename T,
typename E,
typename Reader>
406typename boost::enable_if<std::is_same<bool, typename element_type<T>::type::first_type> >::type
407inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
412 return DeserializeMapElements<Protocols>(var, value<bool, Reader&>(input,
false), element, size);
415 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
417 SkipElements(keyType, element, input, size);
423template <
typename Protocols,
typename T,
typename E,
typename Reader>
424typename boost::enable_if<is_string<typename element_type<T>::type::first_type> >::type
425inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
429 case bond::BT_STRING:
430 return DeserializeMapElements<Protocols>(var, value<std::string, Reader&>(input,
false), element, size);
433 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
435 SkipElements(keyType, element, input, size);
441template <
typename Protocols,
typename T,
typename E,
typename Reader>
442typename boost::enable_if<is_wstring<typename element_type<T>::type::first_type> >::type
443inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
447 case bond::BT_WSTRING:
448 return DeserializeMapElements<Protocols>(var, value<std::wstring, Reader&>(input,
false), element, size);
451 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
453 SkipElements(keyType, element, input, size);
459template <
typename Protocols,
typename T,
typename E,
typename Reader>
460typename boost::enable_if<std::is_floating_point<typename element_type<T>::type::first_type> >::type
461inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
466 return DeserializeMapElements<Protocols>(var, value<float, Reader&>(input,
false), element, size);
468 case bond::BT_DOUBLE:
469 return DeserializeMapElements<Protocols>(var, value<double, Reader&>(input,
false), element, size);
472 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
474 SkipElements(keyType, element, input, size);
480template <
typename Protocols,
typename T,
typename E,
typename Reader>
481typename boost::enable_if<is_matching<uint8_t, typename element_type<T>::type::first_type> >::type
482inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
487 return DeserializeMapElements<Protocols>(var, value<uint8_t, Reader&>(input,
false), element, size);
489 case bond::BT_UINT16:
490 return DeserializeMapElements<Protocols>(var, value<uint16_t, Reader&>(input,
false), element, size);
492 case bond::BT_UINT32:
493 return DeserializeMapElements<Protocols>(var, value<uint32_t, Reader&>(input,
false), element, size);
495 case bond::BT_UINT64:
496 return DeserializeMapElements<Protocols>(var, value<uint64_t, Reader&>(input,
false), element, size);
499 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
501 SkipElements(keyType, element, input, size);
507template <
typename Protocols,
typename T,
typename E,
typename Reader>
508typename boost::enable_if<is_matching<int8_t, typename element_type<T>::type::first_type> >::type
509inline MatchingMapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
514 return DeserializeMapElements<Protocols>(var, value<int8_t, Reader&>(input,
false), element, size);
517 return DeserializeMapElements<Protocols>(var, value<int16_t, Reader&>(input,
false), element, size);
520 return DeserializeMapElements<Protocols>(var, value<int32_t, Reader&>(input,
false), element, size);
523 return DeserializeMapElements<Protocols>(var, value<int64_t, Reader&>(input,
false), element, size);
526 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::first_type>(keyType));
528 SkipElements(keyType, element, input, size);
535template <
typename Protocols,
typename T,
typename E,
typename Reader>
536typename boost::disable_if<is_map_container<T> >::type
537inline MapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
542 return DeserializeMapElements<Protocols>(var, value<bool, Reader&>(input,
false), element, size);
545 return DeserializeMapElements<Protocols>(var, value<uint8_t, Reader&>(input,
false), element, size);
547 case bond::BT_UINT16:
548 return DeserializeMapElements<Protocols>(var, value<uint16_t, Reader&>(input,
false), element, size);
550 case bond::BT_UINT32:
551 return DeserializeMapElements<Protocols>(var, value<uint32_t, Reader&>(input,
false), element, size);
553 case bond::BT_UINT64:
554 return DeserializeMapElements<Protocols>(var, value<uint64_t, Reader&>(input,
false), element, size);
557 return DeserializeMapElements<Protocols>(var, value<float, Reader&>(input,
false), element, size);
559 case bond::BT_DOUBLE:
560 return DeserializeMapElements<Protocols>(var, value<double, Reader&>(input,
false), element, size);
562 case bond::BT_STRING:
563 return DeserializeMapElements<Protocols>(var, value<std::string, Reader&>(input,
false), element, size);
565 case bond::BT_WSTRING:
566 return DeserializeMapElements<Protocols>(var, value<std::wstring, Reader&>(input,
false), element, size);
569 return DeserializeMapElements<Protocols>(var, value<int8_t, Reader&>(input,
false), element, size);
572 return DeserializeMapElements<Protocols>(var, value<int16_t, Reader&>(input,
false), element, size);
575 return DeserializeMapElements<Protocols>(var, value<int32_t, Reader&>(input,
false), element, size);
578 return DeserializeMapElements<Protocols>(var, value<int64_t, Reader&>(input,
false), element, size);
587template <
typename Protocols,
typename T,
typename E,
typename Reader>
588typename boost::enable_if<is_map_element_matching<E, T> >::type
589inline MapByKey(T& var, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
591 return MatchingMapByKey<Protocols>(var, keyType, element, input, size);
595template <
typename Protocols,
typename T,
typename E,
typename Reader>
596typename boost::disable_if_c<!is_map_container<T>::value || is_map_element_matching<E, T>::value>::type
597inline MapByKey(T&, BondDataType keyType,
const E& element, Reader& input, uint32_t size)
607template <
typename Protocols,
typename T,
typename Reader>
608inline void MapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
613 return MapByKey<Protocols>(var, keyType, value<bool, Reader&>(input,
false), input, size);
616 return MapByKey<Protocols>(var, keyType, value<uint8_t, Reader&>(input,
false), input, size);
618 case bond::BT_UINT16:
619 return MapByKey<Protocols>(var, keyType, value<uint16_t, Reader&>(input,
false), input, size);
621 case bond::BT_UINT32:
622 return MapByKey<Protocols>(var, keyType, value<uint32_t, Reader&>(input,
false), input, size);
624 case bond::BT_UINT64:
625 return MapByKey<Protocols>(var, keyType, value<uint64_t, Reader&>(input,
false), input, size);
628 return MapByKey<Protocols>(var, keyType, value<float, Reader&>(input,
false), input, size);
630 case bond::BT_DOUBLE:
631 return MapByKey<Protocols>(var, keyType, value<double, Reader&>(input,
false), input, size);
633 case bond::BT_STRING:
634 return MapByKey<Protocols>(var, keyType, value<std::string, Reader&>(input,
false), input, size);
636 case bond::BT_WSTRING:
637 return MapByKey<Protocols>(var, keyType, value<std::wstring, Reader&>(input,
false), input, size);
640 return MapByKey<Protocols>(var, keyType, value<int8_t, Reader&>(input,
false), input, size);
643 return MapByKey<Protocols>(var, keyType, value<int16_t, Reader&>(input,
false), input, size);
646 return MapByKey<Protocols>(var, keyType, value<int32_t, Reader&>(input,
false), input, size);
649 return MapByKey<Protocols>(var, keyType, value<int64_t, Reader&>(input,
false), input, size);
661template <
typename Reader>
662inline void SkipElements(BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
667 input.Skip(elementType);
671template <
typename Protocols,
typename T,
typename Reader>
672typename boost::enable_if<is_type_alias<typename element_type<T>::type::second_type> >::type
673inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
675 if (elementType == get_type_id<
typename element_type<T>::type::second_type>::value)
677 MapByKey<Protocols>(var, keyType, value<
typename element_type<T>::type::second_type, Reader&>(input,
false), input, size);
681 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
683 SkipElements(keyType, elementType, input, size);
688template <
typename Protocols,
typename T,
typename Reader>
689typename boost::enable_if<std::is_same<bool, typename element_type<T>::type::second_type> >::type
690inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
695 return MapByKey<Protocols>(var, keyType, value<bool, Reader&>(input,
false), input, size);
698 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
700 SkipElements(keyType, elementType, input, size);
706template <
typename Protocols,
typename T,
typename Reader>
707typename boost::enable_if<is_string<typename element_type<T>::type::second_type> >::type
708inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
712 case bond::BT_STRING:
713 return MapByKey<Protocols>(var, keyType, value<std::string, Reader&>(input,
false), input, size);
716 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
718 SkipElements(keyType, elementType, input, size);
724template <
typename Protocols,
typename T,
typename Reader>
725typename boost::enable_if<is_wstring<typename element_type<T>::type::second_type> >::type
726inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
730 case bond::BT_WSTRING:
731 return MapByKey<Protocols>(var, keyType, value<std::wstring, Reader&>(input,
false), input, size);
734 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
736 SkipElements(keyType, elementType, input, size);
742template <
typename Protocols,
typename T,
typename Reader>
743typename boost::enable_if<std::is_floating_point<typename element_type<T>::type::second_type> >::type
744inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
749 return MapByKey<Protocols>(var, keyType, value<float, Reader&>(input,
false), input, size);
751 case bond::BT_DOUBLE:
752 return MapByKey<Protocols>(var, keyType, value<double, Reader&>(input,
false), input, size);
755 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
757 SkipElements(keyType, elementType, input, size);
763template <
typename Protocols,
typename T,
typename Reader>
764typename boost::enable_if<is_matching<uint8_t, typename element_type<T>::type::second_type> >::type
765inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
770 return MapByKey<Protocols>(var, keyType, value<uint8_t, Reader&>(input,
false), input, size);
772 case bond::BT_UINT16:
773 return MapByKey<Protocols>(var, keyType, value<uint16_t, Reader&>(input,
false), input, size);
775 case bond::BT_UINT32:
776 return MapByKey<Protocols>(var, keyType, value<uint32_t, Reader&>(input,
false), input, size);
778 case bond::BT_UINT64:
779 return MapByKey<Protocols>(var, keyType, value<uint64_t, Reader&>(input,
false), input, size);
782 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
784 SkipElements(keyType, elementType, input, size);
790template <
typename Protocols,
typename T,
typename Reader>
791typename boost::enable_if<is_matching<int8_t, typename element_type<T>::type::second_type> >::type
792inline MatchingMapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
797 return MapByKey<Protocols>(var, keyType, value<int8_t, Reader&>(input,
false), input, size);
800 return MapByKey<Protocols>(var, keyType, value<int16_t, Reader&>(input,
false), input, size);
803 return MapByKey<Protocols>(var, keyType, value<int32_t, Reader&>(input,
false), input, size);
806 return MapByKey<Protocols>(var, keyType, value<int64_t, Reader&>(input,
false), input, size);
809 BOOST_ASSERT(!IsMatching<
typename element_type<T>::type::second_type>(elementType));
811 SkipElements(keyType, elementType, input, size);
823#if BOND_LIB_TYPE != BOND_LIB_TYPE_HEADER
824#include "typeid_value_extern.h"
827#error BOND_LIB_TYPE is undefined
namespace bond
Definition: apply.h:17