6#include <bond/core/config.h>
8#include "omit_default.h"
14template <
typename Input>
17 BOOST_STATIC_ASSERT(std::is_reference<Input>::value);
19 static type from(type input)
29template <
typename T,
typename Enable =
void>
struct
31 : std::integral_constant<uint16_t, 1> {};
34template <
typename T>
struct
35hierarchy_depth<T, typename boost::enable_if<std::is_class<typename schema<typename T::base>::type> >::type>
36 : std::integral_constant<uint16_t, 1 + hierarchy_depth<typename schema<typename T::base>::type>::value> {};
39template <
typename T>
struct
41 : std::integral_constant<uint16_t, 0xffff> {};
44template <
typename T,
typename Protocols,
typename Val
idator>
struct
45expected_depth<bond::To<T, Protocols, Validator> >
46 : hierarchy_depth<typename schema<T>::type> {};
49template <
typename Base,
typename T>
50inline Base& base_cast(T& obj)
52 return static_cast<Base&
>(obj);
56template <
typename Base,
typename T>
57inline const Base& base_cast(
const T& obj)
59 return static_cast<const Base&
>(obj);
63template <
typename Input,
typename Parser>
64class ParserInheritance
68 ParserInheritance(Input input,
bool base)
74 template <
typename T,
typename Transform>
75 typename boost::enable_if_c<(hierarchy_depth<T>::value > expected_depth<Transform>::value),
bool>::type
76 Read(
const T&,
const Transform& transform)
78 typename base_input<Input>::type base(base_input<Input>::from(_input));
84 detail::StructBegin(_input,
true);
86 bool result = Parser(base, _base).Read(
typename schema<typename T::base>::type(), transform);
88 detail::StructEnd(_input,
true);
90 static_cast<Parser*
>(
this)->SkipFields(
typename boost::mpl::begin<typename T::fields>::type());
96 template <
typename T,
typename Transform>
97 typename boost::disable_if_c<(hierarchy_depth<T>::value > expected_depth<Transform>::value),
bool>::type
98 Read(
const T&,
const Transform& transform)
103 transform.Begin(T::metadata);
105 bool done = ReadBase(base_class<T>(), transform);
109 done =
static_cast<Parser*
>(
this)->ReadFields(
typename boost::mpl::begin<typename T::fields>::type(), transform);
118 template <
typename Base,
typename Transform>
119 typename boost::enable_if<is_reader<Input, Base>,
bool>::type
120 ReadBase(
const Base*,
const Transform& transform)
122 typename base_input<Input>::type base(base_input<Input>::from(_input));
124 return transform.Base(bonded<Base, Input>(base,
true));
128 template <
typename Base,
typename Transform>
129 typename boost::disable_if<is_reader<Input, Base>,
bool>::type
130 ReadBase(
const Base*,
const Transform& transform)
132 return transform.Base(base_cast<Base>(_input));
136 template <
typename Transform>
137 bool ReadBase(
const no_base*,
const Transform&)
144 template <
typename Transform>
145 bool Read(
const RuntimeSchema& schema,
const Transform& transform)
150 typename base_input<Input>::type base(base_input<Input>::from(_input));
152 if (schema_depth(schema) > expected_depth<Transform>::value)
154 BOOST_ASSERT(schema.HasBase());
156 detail::StructBegin(_input,
true);
158 done = Parser(base, _base).Read(schema.GetBaseSchema(), transform);
160 detail::StructEnd(_input,
true);
162 static_cast<Parser*
>(
this)->SkipFields(schema);
166 transform.Begin(schema.GetStruct().metadata);
168 done = schema.HasBase() && transform.Base(bonded<void, Input>(base, schema.GetBaseSchema(),
true));
172 done =
static_cast<Parser*
>(
this)->ReadFields(schema, transform);
namespace bond
Definition: apply.h:17