Bond
 
Loading...
Searching...
No Matches
typeid_value.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8#include <bond/core/blob.h>
9#include <bond/core/reflection.h>
10
11#include <boost/utility/enable_if.hpp>
12
13namespace bond
14{
15
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);
19
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);
23
24template <typename Protocols, typename Transform, typename Key, typename T>
25inline void DeserializeMapElements(const Transform& transform, const Key& key, const T& element, uint32_t size);
26
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);
31
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);
35
36template <typename Protocols, typename Reader>
37inline void DeserializeElements(blob& var, const value<blob::value_type, Reader&>& element, uint32_t size);
38
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);
43
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);
47
48template <typename Protocols, typename Transform, typename T>
49inline void DeserializeElements(const Transform& transform, const T& element, uint32_t size);
50
51namespace detail
52{
53
54
55// Sanity check to assert that manually expended switch statement are consistent
56// with the canonical definition of type promotion in is_matching metafunction.
57
58template <typename T>
59bool IsMatching(BondDataType type)
60{
61 switch (type)
62 {
63 case bond::BT_BOOL:
64 return is_matching<bool, T>::value;
65
66 case bond::BT_UINT8:
67 return is_matching<uint8_t, T>::value;
68
69 case bond::BT_UINT16:
70 return is_matching<uint16_t, T>::value;
71
72 case bond::BT_UINT32:
73 return is_matching<uint32_t, T>::value;
74
75 case bond::BT_UINT64:
76 return is_matching<uint64_t, T>::value;
77
78 case bond::BT_FLOAT:
79 return is_matching<float, T>::value;
80
81 case bond::BT_DOUBLE:
82 return is_matching<double, T>::value;
83
84 case bond::BT_STRING:
85 return is_matching<std::string, T>::value;
86
87 case bond::BT_WSTRING:
88 return is_matching<std::wstring, T>::value;
89
90 case bond::BT_INT8:
91 return is_matching<int8_t, T>::value;
92
93 case bond::BT_INT16:
94 return is_matching<int16_t, T>::value;
95
96 case bond::BT_INT32:
97 return is_matching<int32_t, T>::value;
98
99 case bond::BT_INT64:
100 return is_matching<int64_t, T>::value;
101
102 default:
103 BOOST_ASSERT(false);
104 return false;
105 }
106}
107
108
109template <typename Transform, typename Reader>
110inline bool BasicTypeField(uint16_t id, const Metadata& metadata, BondDataType type, const Transform& transform, Reader& input)
111{
112 switch (type)
113 {
114 case bond::BT_BOOL:
115 return transform.Field(id, metadata, value<bool, Reader&>(input));
116
117 case bond::BT_UINT8:
118 return transform.Field(id, metadata, value<uint8_t, Reader&>(input));
119
120 case bond::BT_UINT16:
121 return transform.Field(id, metadata, value<uint16_t, Reader&>(input));
122
123 case bond::BT_UINT32:
124 return transform.Field(id, metadata, value<uint32_t, Reader&>(input));
125
126 case bond::BT_UINT64:
127 return transform.Field(id, metadata, value<uint64_t, Reader&>(input));
128
129 case bond::BT_FLOAT:
130 return transform.Field(id, metadata, value<float, Reader&>(input));
131
132 case bond::BT_DOUBLE:
133 return transform.Field(id, metadata, value<double, Reader&>(input));
134
135 case bond::BT_STRING:
136 return transform.Field(id, metadata, value<std::string, Reader&>(input));
137
138 case bond::BT_WSTRING:
139 return transform.Field(id, metadata, value<std::wstring, Reader&>(input));
140
141 case bond::BT_INT8:
142 return transform.Field(id, metadata, value<int8_t, Reader&>(input));
143
144 case bond::BT_INT16:
145 return transform.Field(id, metadata, value<int16_t, Reader&>(input));
146
147 case bond::BT_INT32:
148 return transform.Field(id, metadata, value<int32_t, Reader&>(input));
149
150 case bond::BT_INT64:
151 return transform.Field(id, metadata, value<int64_t, Reader&>(input));
152
153 default:
154 BOOST_ASSERT(false);
155 return false;
156 }
157}
158
159
160template <typename Protocols, typename T, typename Reader>
161inline void BasicTypeContainer(T& var, BondDataType type, Reader& input, uint32_t size)
162{
163 BOOST_STATIC_ASSERT(!is_container<T>::value);
164
165 switch (type)
166 {
167 case bond::BT_BOOL:
168 return DeserializeElements<Protocols>(var, value<bool, Reader&>(input, false), size);
169
170 case bond::BT_UINT8:
171 return DeserializeElements<Protocols>(var, value<uint8_t, Reader&>(input, false), size);
172
173 case bond::BT_UINT16:
174 return DeserializeElements<Protocols>(var, value<uint16_t, Reader&>(input, false), size);
175
176 case bond::BT_UINT32:
177 return DeserializeElements<Protocols>(var, value<uint32_t, Reader&>(input, false), size);
178
179 case bond::BT_UINT64:
180 return DeserializeElements<Protocols>(var, value<uint64_t, Reader&>(input, false), size);
181
182 case bond::BT_FLOAT:
183 return DeserializeElements<Protocols>(var, value<float, Reader&>(input, false), size);
184
185 case bond::BT_DOUBLE:
186 return DeserializeElements<Protocols>(var, value<double, Reader&>(input, false), size);
187
188 case bond::BT_STRING:
189 return DeserializeElements<Protocols>(var, value<std::string, Reader&>(input, false), size);
190
191 case bond::BT_WSTRING:
192 return DeserializeElements<Protocols>(var, value<std::wstring, Reader&>(input, false), size);
193
194 case bond::BT_INT8:
195 return DeserializeElements<Protocols>(var, value<int8_t, Reader&>(input, false), size);
196
197 case bond::BT_INT16:
198 return DeserializeElements<Protocols>(var, value<int16_t, Reader&>(input, false), size);
199
200 case bond::BT_INT32:
201 return DeserializeElements<Protocols>(var, value<int32_t, Reader&>(input, false), size);
202
203 case bond::BT_INT64:
204 return DeserializeElements<Protocols>(var, value<int64_t, Reader&>(input, false), size);
205
206 default:
207 BOOST_ASSERT(false);
208 return;
209 }
210}
211
212
213template <typename E>
214inline void SkipElements(const E& element, uint32_t size)
215{
216 while (size--)
217 element.Skip();
218}
219
220template <typename Reader>
221inline void SkipElements(BondDataType type, Reader& input, uint32_t size)
222{
223 while (size--)
224 input.Skip(type);
225}
226
227// MatchingTypeContainer function are manually expended versions of BasicTypeContainer
228// using the type information about destination container. This helps with compilation speed.
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)
232{
233 if (type == get_type_id<typename element_type<T>::type>::value)
234 {
235 DeserializeElements<Protocols>(var, value<typename element_type<T>::type, Reader&>(input, false), size);
236 }
237 else
238 {
239 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
240
241 SkipElements(type, input, size);
242 }
243}
244
245
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)
249{
250 switch (type)
251 {
252 case bond::BT_BOOL:
253 return DeserializeElements<Protocols>(var, value<bool, Reader&>(input, false), size);
254
255 default:
256 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
257
258 SkipElements(type, input, size);
259 break;
260 }
261}
262
263
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)
267{
268 switch (type)
269 {
270 case bond::BT_STRING:
271 return DeserializeElements<Protocols>(var, value<std::string, Reader&>(input, false), size);
272
273 default:
274 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
275
276 SkipElements(type, input, size);
277 break;
278 }
279}
280
281
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)
285{
286 switch (type)
287 {
288 case bond::BT_WSTRING:
289 return DeserializeElements<Protocols>(var, value<std::wstring, Reader&>(input, false), size);
290
291 default:
292 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
293
294 SkipElements(type, input, size);
295 break;
296 }
297}
298
299
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)
303{
304 switch (type)
305 {
306 case bond::BT_FLOAT:
307 return DeserializeElements<Protocols>(var, value<float, Reader&>(input, false), size);
308
309 case bond::BT_DOUBLE:
310 return DeserializeElements<Protocols>(var, value<double, Reader&>(input, false), size);
311
312 default:
313 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
314
315 SkipElements(type, input, size);
316 break;
317 }
318}
319
320
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)
324{
325 switch (type)
326 {
327 case bond::BT_UINT8:
328 return DeserializeElements<Protocols>(var, value<uint8_t, Reader&>(input, false), size);
329
330 case bond::BT_UINT16:
331 return DeserializeElements<Protocols>(var, value<uint16_t, Reader&>(input, false), size);
332
333 case bond::BT_UINT32:
334 return DeserializeElements<Protocols>(var, value<uint32_t, Reader&>(input, false), size);
335
336 case bond::BT_UINT64:
337 return DeserializeElements<Protocols>(var, value<uint64_t, Reader&>(input, false), size);
338
339 default:
340 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
341
342 SkipElements(type, input, size);
343 break;
344 }
345}
346
347
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)
351{
352 switch (type)
353 {
354 case bond::BT_INT8:
355 return DeserializeElements<Protocols>(var, value<int8_t, Reader&>(input, false), size);
356
357 case bond::BT_INT16:
358 return DeserializeElements<Protocols>(var, value<int16_t, Reader&>(input, false), size);
359
360 case bond::BT_INT32:
361 return DeserializeElements<Protocols>(var, value<int32_t, Reader&>(input, false), size);
362
363 case bond::BT_INT64:
364 return DeserializeElements<Protocols>(var, value<int64_t, Reader&>(input, false), size);
365
366 default:
367 BOOST_ASSERT(!IsMatching<typename element_type<T>::type>(type));
368
369 SkipElements(type, input, size);
370 break;
371 }
372}
373
374
375// MatchingMapByKey function are manually expended versions of MapByKey using the type
376// information about destination container. This helps with compilation speed.
377
378template <typename E, typename Reader>
379inline void SkipElements(BondDataType keyType, const E& element, Reader& input, uint32_t size)
380{
381 while (size--)
382 {
383 input.Skip(keyType);
384 element.Skip();
385 }
386}
387
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)
391{
392 if (keyType == get_type_id<typename element_type<T>::type::first_type>::value)
393 {
394 return DeserializeMapElements<Protocols>(var, value<typename element_type<T>::type::first_type, Reader&>(input, false), element, size);
395 }
396 else
397 {
398 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
399
400 SkipElements(keyType, element, input, size);
401 }
402}
403
404
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)
408{
409 switch (keyType)
410 {
411 case bond::BT_BOOL:
412 return DeserializeMapElements<Protocols>(var, value<bool, Reader&>(input, false), element, size);
413
414 default:
415 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
416
417 SkipElements(keyType, element, input, size);
418 break;
419 }
420}
421
422
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)
426{
427 switch (keyType)
428 {
429 case bond::BT_STRING:
430 return DeserializeMapElements<Protocols>(var, value<std::string, Reader&>(input, false), element, size);
431
432 default:
433 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
434
435 SkipElements(keyType, element, input, size);
436 break;
437 }
438}
439
440
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)
444{
445 switch (keyType)
446 {
447 case bond::BT_WSTRING:
448 return DeserializeMapElements<Protocols>(var, value<std::wstring, Reader&>(input, false), element, size);
449
450 default:
451 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
452
453 SkipElements(keyType, element, input, size);
454 break;
455 }
456}
457
458
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)
462{
463 switch (keyType)
464 {
465 case bond::BT_FLOAT:
466 return DeserializeMapElements<Protocols>(var, value<float, Reader&>(input, false), element, size);
467
468 case bond::BT_DOUBLE:
469 return DeserializeMapElements<Protocols>(var, value<double, Reader&>(input, false), element, size);
470
471 default:
472 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
473
474 SkipElements(keyType, element, input, size);
475 break;
476 }
477}
478
479
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)
483{
484 switch (keyType)
485 {
486 case bond::BT_UINT8:
487 return DeserializeMapElements<Protocols>(var, value<uint8_t, Reader&>(input, false), element, size);
488
489 case bond::BT_UINT16:
490 return DeserializeMapElements<Protocols>(var, value<uint16_t, Reader&>(input, false), element, size);
491
492 case bond::BT_UINT32:
493 return DeserializeMapElements<Protocols>(var, value<uint32_t, Reader&>(input, false), element, size);
494
495 case bond::BT_UINT64:
496 return DeserializeMapElements<Protocols>(var, value<uint64_t, Reader&>(input, false), element, size);
497
498 default:
499 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
500
501 SkipElements(keyType, element, input, size);
502 break;
503 }
504}
505
506
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)
510{
511 switch (keyType)
512 {
513 case bond::BT_INT8:
514 return DeserializeMapElements<Protocols>(var, value<int8_t, Reader&>(input, false), element, size);
515
516 case bond::BT_INT16:
517 return DeserializeMapElements<Protocols>(var, value<int16_t, Reader&>(input, false), element, size);
518
519 case bond::BT_INT32:
520 return DeserializeMapElements<Protocols>(var, value<int32_t, Reader&>(input, false), element, size);
521
522 case bond::BT_INT64:
523 return DeserializeMapElements<Protocols>(var, value<int64_t, Reader&>(input, false), element, size);
524
525 default:
526 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::first_type>(keyType));
527
528 SkipElements(keyType, element, input, size);
529 break;
530 }
531}
532
533
534
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)
538{
539 switch (keyType)
540 {
541 case bond::BT_BOOL:
542 return DeserializeMapElements<Protocols>(var, value<bool, Reader&>(input, false), element, size);
543
544 case bond::BT_UINT8:
545 return DeserializeMapElements<Protocols>(var, value<uint8_t, Reader&>(input, false), element, size);
546
547 case bond::BT_UINT16:
548 return DeserializeMapElements<Protocols>(var, value<uint16_t, Reader&>(input, false), element, size);
549
550 case bond::BT_UINT32:
551 return DeserializeMapElements<Protocols>(var, value<uint32_t, Reader&>(input, false), element, size);
552
553 case bond::BT_UINT64:
554 return DeserializeMapElements<Protocols>(var, value<uint64_t, Reader&>(input, false), element, size);
555
556 case bond::BT_FLOAT:
557 return DeserializeMapElements<Protocols>(var, value<float, Reader&>(input, false), element, size);
558
559 case bond::BT_DOUBLE:
560 return DeserializeMapElements<Protocols>(var, value<double, Reader&>(input, false), element, size);
561
562 case bond::BT_STRING:
563 return DeserializeMapElements<Protocols>(var, value<std::string, Reader&>(input, false), element, size);
564
565 case bond::BT_WSTRING:
566 return DeserializeMapElements<Protocols>(var, value<std::wstring, Reader&>(input, false), element, size);
567
568 case bond::BT_INT8:
569 return DeserializeMapElements<Protocols>(var, value<int8_t, Reader&>(input, false), element, size);
570
571 case bond::BT_INT16:
572 return DeserializeMapElements<Protocols>(var, value<int16_t, Reader&>(input, false), element, size);
573
574 case bond::BT_INT32:
575 return DeserializeMapElements<Protocols>(var, value<int32_t, Reader&>(input, false), element, size);
576
577 case bond::BT_INT64:
578 return DeserializeMapElements<Protocols>(var, value<int64_t, Reader&>(input, false), element, size);
579
580 default:
581 BOOST_ASSERT(false);
582 return;
583 }
584}
585
586
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)
590{
591 return MatchingMapByKey<Protocols>(var, keyType, element, input, size);
592}
593
594
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)
598{
599 while (size--)
600 {
601 input.Skip(keyType);
602 element.Skip();
603 }
604}
605
606
607template <typename Protocols, typename T, typename Reader>
608inline void MapByElement(T& var, BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
609{
610 switch (elementType)
611 {
612 case bond::BT_BOOL:
613 return MapByKey<Protocols>(var, keyType, value<bool, Reader&>(input, false), input, size);
614
615 case bond::BT_UINT8:
616 return MapByKey<Protocols>(var, keyType, value<uint8_t, Reader&>(input, false), input, size);
617
618 case bond::BT_UINT16:
619 return MapByKey<Protocols>(var, keyType, value<uint16_t, Reader&>(input, false), input, size);
620
621 case bond::BT_UINT32:
622 return MapByKey<Protocols>(var, keyType, value<uint32_t, Reader&>(input, false), input, size);
623
624 case bond::BT_UINT64:
625 return MapByKey<Protocols>(var, keyType, value<uint64_t, Reader&>(input, false), input, size);
626
627 case bond::BT_FLOAT:
628 return MapByKey<Protocols>(var, keyType, value<float, Reader&>(input, false), input, size);
629
630 case bond::BT_DOUBLE:
631 return MapByKey<Protocols>(var, keyType, value<double, Reader&>(input, false), input, size);
632
633 case bond::BT_STRING:
634 return MapByKey<Protocols>(var, keyType, value<std::string, Reader&>(input, false), input, size);
635
636 case bond::BT_WSTRING:
637 return MapByKey<Protocols>(var, keyType, value<std::wstring, Reader&>(input, false), input, size);
638
639 case bond::BT_INT8:
640 return MapByKey<Protocols>(var, keyType, value<int8_t, Reader&>(input, false), input, size);
641
642 case bond::BT_INT16:
643 return MapByKey<Protocols>(var, keyType, value<int16_t, Reader&>(input, false), input, size);
644
645 case bond::BT_INT32:
646 return MapByKey<Protocols>(var, keyType, value<int32_t, Reader&>(input, false), input, size);
647
648 case bond::BT_INT64:
649 return MapByKey<Protocols>(var, keyType, value<int64_t, Reader&>(input, false), input, size);
650
651 default:
652 BOOST_ASSERT(false);
653 break;
654 }
655}
656
657
658// MatchingMapByElement function are manually expended versions of MapByElement using
659// the type information about destination container. This helps with compilation speed.
660
661template <typename Reader>
662inline void SkipElements(BondDataType keyType, BondDataType elementType, Reader& input, uint32_t size)
663{
664 while (size--)
665 {
666 input.Skip(keyType);
667 input.Skip(elementType);
668 }
669}
670
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)
674{
675 if (elementType == get_type_id<typename element_type<T>::type::second_type>::value)
676 {
677 MapByKey<Protocols>(var, keyType, value<typename element_type<T>::type::second_type, Reader&>(input, false), input, size);
678 }
679 else
680 {
681 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
682
683 SkipElements(keyType, elementType, input, size);
684 }
685}
686
687
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)
691{
692 switch (elementType)
693 {
694 case bond::BT_BOOL:
695 return MapByKey<Protocols>(var, keyType, value<bool, Reader&>(input, false), input, size);
696
697 default:
698 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
699
700 SkipElements(keyType, elementType, input, size);
701 break;
702 }
703}
704
705
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)
709{
710 switch (elementType)
711 {
712 case bond::BT_STRING:
713 return MapByKey<Protocols>(var, keyType, value<std::string, Reader&>(input, false), input, size);
714
715 default:
716 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
717
718 SkipElements(keyType, elementType, input, size);
719 break;
720 }
721}
722
723
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)
727{
728 switch (elementType)
729 {
730 case bond::BT_WSTRING:
731 return MapByKey<Protocols>(var, keyType, value<std::wstring, Reader&>(input, false), input, size);
732
733 default:
734 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
735
736 SkipElements(keyType, elementType, input, size);
737 break;
738 }
739}
740
741
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)
745{
746 switch (elementType)
747 {
748 case bond::BT_FLOAT:
749 return MapByKey<Protocols>(var, keyType, value<float, Reader&>(input, false), input, size);
750
751 case bond::BT_DOUBLE:
752 return MapByKey<Protocols>(var, keyType, value<double, Reader&>(input, false), input, size);
753
754 default:
755 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
756
757 SkipElements(keyType, elementType, input, size);
758 break;
759 }
760}
761
762
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)
766{
767 switch (elementType)
768 {
769 case bond::BT_UINT8:
770 return MapByKey<Protocols>(var, keyType, value<uint8_t, Reader&>(input, false), input, size);
771
772 case bond::BT_UINT16:
773 return MapByKey<Protocols>(var, keyType, value<uint16_t, Reader&>(input, false), input, size);
774
775 case bond::BT_UINT32:
776 return MapByKey<Protocols>(var, keyType, value<uint32_t, Reader&>(input, false), input, size);
777
778 case bond::BT_UINT64:
779 return MapByKey<Protocols>(var, keyType, value<uint64_t, Reader&>(input, false), input, size);
780
781 default:
782 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
783
784 SkipElements(keyType, elementType, input, size);
785 break;
786 }
787}
788
789
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)
793{
794 switch (elementType)
795 {
796 case bond::BT_INT8:
797 return MapByKey<Protocols>(var, keyType, value<int8_t, Reader&>(input, false), input, size);
798
799 case bond::BT_INT16:
800 return MapByKey<Protocols>(var, keyType, value<int16_t, Reader&>(input, false), input, size);
801
802 case bond::BT_INT32:
803 return MapByKey<Protocols>(var, keyType, value<int32_t, Reader&>(input, false), input, size);
804
805 case bond::BT_INT64:
806 return MapByKey<Protocols>(var, keyType, value<int64_t, Reader&>(input, false), input, size);
807
808 default:
809 BOOST_ASSERT(!IsMatching<typename element_type<T>::type::second_type>(elementType));
810
811 SkipElements(keyType, elementType, input, size);
812 break;
813 }
814}
815
816
817} // namespace detail
818
819} // namespace bond
820
821
822#ifdef BOND_LIB_TYPE
823#if BOND_LIB_TYPE != BOND_LIB_TYPE_HEADER
824#include "typeid_value_extern.h"
825#endif
826#else
827#error BOND_LIB_TYPE is undefined
828#endif
namespace bond
Definition: apply.h:17