6#include <bond/core/bond_fwd.h>
7#include <bond/core/maybe.h>
8#include <bond/core/reflection.h>
9#include <bond/core/stl_containers.h>
10#include <bond/core/traits.h>
13#include <boost/utility/enable_if.hpp>
26bool is_default(
const maybe<T>& value,
const Metadata& )
28 return value.is_nothing();
35typename boost::enable_if_c<is_basic_type<T>::value
36 && !is_string_type<T>::value
37 && !is_type_alias<T>::value,
bool>::type
38is_default(
const T& value,
const Metadata& metadata)
40 return (metadata.default_value == value);
47typename boost::enable_if<is_type_alias<T>,
bool>::type
48is_default(
const T& value,
const Metadata& metadata)
50 return (metadata.default_value == get_aliased_value(value));
57typename boost::enable_if<is_string<typename std::remove_const<T>::type>,
bool>::type
58is_default(
const T& value,
const Metadata& metadata)
60 BOOST_ASSERT(!metadata.default_value.nothing);
61 return !metadata.default_value.string_value.compare(0, std::string::npos, string_data(value), string_length(value));
67typename boost::enable_if<is_wstring<typename std::remove_const<T>::type>,
bool>::type
68is_default(
const T& value,
const Metadata& metadata)
70 BOOST_ASSERT(!metadata.default_value.nothing);
71 return !metadata.default_value.wstring_value.compare(0, std::wstring::npos, string_data(value), string_length(value));
78typename boost::enable_if<is_container<T>,
bool>::type
79is_default(
const T& value,
const Metadata& )
81 return (container_size(value) == 0);
88typename boost::enable_if<is_bond_type<T>,
bool>::type
89is_default(
const T& ,
const Metadata& )
96template <
typename Writer,
typename T>
98typename boost::enable_if<may_omit_fields<Writer>,
bool>::type
99omit_field(
const Metadata& metadata,
const T& value)
103 (void)one_definition<may_omit_fields<Writer>, std::true_type>::value;
106 return metadata.modifier == Optional
107 && is_default(value, metadata);
111template <
typename Writer,
typename T>
113typename boost::disable_if<may_omit_fields<Writer>,
bool>::type
114omit_field(
const Metadata& ,
const T& )
118 (void)one_definition<may_omit_fields<Writer>, std::false_type>::value;
126template <
typename Writer,
typename Reader,
typename T>
128bool omit_field(
const Metadata& ,
const value<T, Reader>& )
134template <
typename T,
typename Enable =
void>
struct
135implements_field_omitting
136 : std::false_type {};
139#ifdef BOND_NO_SFINAE_EXPR
140template <
typename T>
struct
141implements_field_omitting<T&>
142 : implements_field_omitting<T> {};
149template <
typename Writer>
struct
150implements_field_omitting<Writer,
151#ifdef BOND_NO_SFINAE_EXPR
152 typename boost::enable_if<check_method<void (Writer::*)(BondDataType, uint16_t,
const Metadata&), &Writer::WriteFieldOmitted> >::type>
154 detail::mpl::void_t<
decltype(std::declval<Writer>().WriteFieldOmitted(
155 std::declval<BondDataType>(),
156 std::declval<uint16_t>(),
157 std::declval<Metadata>()))>>
164template <
typename Input>
struct
165implements_field_omitting<Input,
166#ifdef BOND_NO_SFINAE_EXPR
167 typename boost::enable_if<check_method<bool (Input::*)(), &Input::ReadFieldOmitted> >::type>
169 typename boost::enable_if<std::is_same<
171 decltype(std::declval<Input>().ReadFieldOmitted())>>::type>
177template <
typename Writer>
178typename boost::enable_if<implements_field_omitting<Writer> >::type
179WriteFieldOmitted(Writer& output, BondDataType type, uint16_t
id,
const Metadata& metadata)
181 output.WriteFieldOmitted(type,
id, metadata);
185template <
typename Writer>
186typename boost::disable_if<implements_field_omitting<Writer> >::type
187WriteFieldOmitted(Writer& , BondDataType , uint16_t ,
const Metadata& )
192template <
typename Input>
193typename boost::enable_if<implements_field_omitting<Input>,
bool>::type
194ReadFieldOmitted(Input& input)
196 return input.ReadFieldOmitted();
200template <
typename Input>
201typename boost::disable_if<implements_field_omitting<Input>,
bool>::type
202ReadFieldOmitted(Input& )
209template <
typename T,
typename Enable =
void>
struct
210implements_struct_begin
211 : std::false_type {};
216template <
typename T,
typename Enable =
void>
struct
217implements_struct_begin_with_base
218 : std::false_type {};
221template <
typename Input>
struct
222implements_struct_begin<Input,
223#ifdef BOND_NO_SFINAE_EXPR
224 typename boost::enable_if<check_method<void (Input::*)(), &Input::ReadStructBegin> >::type>
226 detail::mpl::void_t<
decltype(std::declval<Input>().ReadStructBegin())>>
231template <
typename Input>
struct
232implements_struct_begin_with_base<Input,
233#ifdef BOND_NO_SFINAE_EXPR
234 typename boost::enable_if<check_method<void (Input::*)(bool), &Input::ReadStructBegin> >::type>
236 detail::mpl::void_t<
decltype(std::declval<Input>().ReadStructBegin(std::declval<bool>()))>>
242template <
typename Input>
243typename boost::enable_if_c<implements_struct_begin<Input>::value
244 && !implements_struct_begin_with_base<Input>::value>::type
245StructBegin(Input& input,
bool )
247 return input.ReadStructBegin();
251template <
typename Input>
252typename boost::enable_if<implements_struct_begin_with_base<Input> >::type
253StructBegin(Input& input,
bool base)
255 return input.ReadStructBegin(base);
259template <
typename Input>
260typename boost::disable_if_c<implements_struct_begin<Input>::value
261 || implements_struct_begin_with_base<Input>::value>::type
262StructBegin(Input& ,
bool )
267template <
typename Input>
268typename boost::enable_if_c<implements_struct_begin<Input>::value
269 && !implements_struct_begin_with_base<Input>::value>::type
270StructEnd(Input& input,
bool )
272 return input.ReadStructEnd();
276template <
typename Input>
277typename boost::enable_if<implements_struct_begin_with_base<Input> >::type
278StructEnd(Input& input,
bool base)
280 return input.ReadStructEnd(base);
284template <
typename Input>
285typename boost::disable_if_c<implements_struct_begin<Input>::value
286 || implements_struct_begin_with_base<Input>::value>::type
287StructEnd(Input& ,
bool )
296template <
typename T>
struct
298 : std::integral_constant<bool,
299 !uses_static_parser<typename T::Reader>::value
300 || detail::implements_field_omitting<T>::value> {};
namespace bond
Definition: apply.h:17