Bond
 
Loading...
Searching...
No Matches
parser_utils.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/reflection.h>
9
10
11namespace bond
12{
13namespace detail
14{
15 template <typename T, typename Transform>
16 typename boost::enable_if<is_fast_path_field<T, Transform>, bool>::type
17 inline OmittedField(const T& field, const Transform& transform)
18 {
19 return transform.OmittedField(field);
20 }
21
22
23 template <typename T, typename Transform>
24 typename boost::disable_if<is_fast_path_field<T, Transform>, bool>::type
25 inline OmittedField(const T&, const Transform& transform)
26 {
27 return transform.OmittedField(T::id, T::metadata, get_type_id<typename T::field_type>::value);
28 }
29
30
31 template <typename T, typename Reader>
32 typename boost::enable_if_c<is_reader<Reader>::value && is_nested_field<T>::value,
33 bonded<typename T::field_type, Reader&> >::type
34 inline GetFieldValue(Reader& input)
35 {
36 return bonded<typename T::field_type, Reader&>(input);
37 }
38
39
40 template <typename T, typename Reader>
41 typename boost::enable_if_c<is_reader<Reader>::value && !is_nested_field<T>::value,
42 value<typename T::field_type, Reader&> >::type
43 inline GetFieldValue(Reader& input)
44 {
45 return value<typename T::field_type, Reader&>(input);
46 }
47
48
49 template <typename T, typename X>
50 typename boost::disable_if<is_reader<X>,
51 typename std::conditional<std::is_const<X>::value,
52 const typename T::value_type&,
53 typename T::value_type&>::type>::type
54 inline GetFieldValue(X& value)
55 {
56 return T::GetVariable(value);
57 }
58
59
60 template <typename T, typename Transform, typename X>
61 typename boost::enable_if_c<is_reader<X>::value && is_fast_path_field<T, Transform>::value, bool>::type
62 inline NonBasicTypeField(const T& field, const Transform& transform, X&& value)
63 {
64 return transform.Field(field, GetFieldValue<T>(std::forward<X>(value)));
65 }
66
67
68 template <typename T, typename Transform, typename X>
69 typename boost::disable_if_c<is_reader<X>::value && is_fast_path_field<T, Transform>::value, bool>::type
70 inline NonBasicTypeField(const T&, const Transform& transform, X&& value)
71 {
72 return transform.Field(T::id, T::metadata, GetFieldValue<T>(std::forward<X>(value)));
73 }
74
75
76 template <typename Reader, typename Transform>
77 inline bool NonBasicTypeField(const FieldDef& field, const RuntimeSchema& schema, const Transform& transform, Reader& input)
78 {
79 if (field.type.id == BT_STRUCT)
80 {
81 return transform.Field(field.id, field.metadata, bonded<void, Reader&>(input, RuntimeSchema(schema, field)));
82 }
83 else
84 {
85 BOOST_ASSERT(field.type.id == BT_LIST || field.type.id == BT_SET || field.type.id == BT_MAP);
86 return transform.Field(field.id, field.metadata, value<void, Reader&>(input, RuntimeSchema(schema, field)));
87 }
88 }
89
90} // namespace detail
91} // namespace bond
namespace bond
Definition: apply.h:17