Bond
 
Loading...
Searching...
No Matches
apply.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 "bonded.h"
9#include "bonded_void.h"
10#include "detail/double_pass.h"
11#include "exception.h"
12#include "parser.h"
13
14#include <bond/core/bond_reflection.h>
15
16namespace bond
17{
18namespace detail
19{
20
22template <typename Protocols, typename Transform, typename T, typename Reader>
23typename boost::disable_if<need_double_pass<Transform>, bool>::type inline
24ApplyTransform(const Transform& transform, const bonded<T, Reader>& bonded)
25{
26 return bonded.template _Apply<Protocols>(transform);
27}
28
29
31template <typename Protocols, typename Transform, typename T, typename Reader>
32bool inline
33ApplyTransform(const Transform& transform, const value<T, Reader>& value)
34{
35 value.template _Apply<Protocols>(transform);
36 return true;
37}
38
39
41template <typename Protocols, typename Transform, typename T>
42typename boost::disable_if<need_double_pass<Transform>, bool>::type inline
43ApplyTransform(const Transform& transform, const T& value)
44{
45 return StaticParser<const T&>(value).Apply(transform, typename schema<T>::type());
46}
47
48
50template <typename Protocols, typename Transform, typename T>
51typename boost::enable_if<is_modifying_transform<Transform>, bool>::type inline
52ApplyTransform(const Transform& transform, T& value)
53{
54 return StaticParser<T&>(value).Apply(transform, typename schema<T>::type());
55}
56
57
58// Specializations for transform requiring double-pass
59template <typename Protocols, typename Transform, typename T, typename Reader>
60typename boost::enable_if<need_double_pass<Transform>, bool>::type inline
61ApplyTransform(const Transform& transform, const bonded<T, Reader>& bonded)
62{
63 if (transform.NeedPass0())
64 return DoublePassApply<Protocols>(transform, bonded);
65 else
66 return bonded.template _Apply<Protocols>(transform);
67}
68
69
70template <typename Protocols, typename Transform, typename T>
71typename boost::enable_if<need_double_pass<Transform>, bool>::type inline
72ApplyTransform(const Transform& transform, const T& value)
73{
74 if (transform.NeedPass0())
75 return DoublePassApply<Protocols>(transform, value);
76 else
77 return StaticParser<const T&>(value).Apply(transform, typename schema<T>::type());
78}
79
80} // namespace detail
81
82
83template <typename Protocols, typename Transform, typename T, typename boost::enable_if<is_modifying_transform<Transform> >::type*>
84bool Apply(const Transform& transform, T& value)
85{
86 return detail::ApplyTransform<Protocols>(transform, value);
87}
88
89template <typename Protocols, typename Transform, typename T>
90bool Apply(const Transform& transform, const T& value)
91{
92 return detail::ApplyTransform<Protocols>(transform, value);
93}
94
95
97template <typename T, typename Transform>
98bool Apply(const Transform& transform)
99{
100 SchemaReader input;
101 return SchemaReader::Parser{ input }.Apply(transform, typename schema<T>::type{});
102}
103
104
106template <typename Transform>
107bool Apply(const Transform& transform, const RuntimeSchema& schema)
108{
109 SchemaReader input;
110 return SchemaReader::Parser{ input }.Apply(transform, schema);
111}
112
113} // namespace bond
Represents runtime schema See User's Manual
Definition: runtime_schema.h:26
Represents data for a struct T known at compile-time.
Definition: bonded.h:63
namespace bond
Definition: apply.h:17