6#include <bond/core/config.h>
10#include "detail/mpl.h"
11#include "detail/odr.h"
12#include "detail/visit_any.h"
15#include <bond/protocol/compact_binary.h>
16#include <bond/protocol/fast_binary.h>
17#include <bond/protocol/simple_binary.h>
18#include <bond/protocol/simple_json_reader.h>
19#include <bond/stream/input_buffer.h>
21#include <boost/make_shared.hpp>
22#include <boost/optional.hpp>
23#include <boost/ref.hpp>
29#ifdef BOND_COMPACT_BINARY_PROTOCOL
30template <
typename Buffer>
struct
31is_protocol_enabled<CompactBinaryReader<Buffer> >
35#ifdef BOND_SIMPLE_BINARY_PROTOCOL
36template <
typename Buffer,
typename MarshaledBondedProtocols>
struct
37is_protocol_enabled<SimpleBinaryReader<Buffer, MarshaledBondedProtocols> >
41#ifdef BOND_SIMPLE_JSON_PROTOCOL
42template <
typename Buffer>
struct
43is_protocol_enabled<SimpleJsonReader<Buffer> >
47#ifdef BOND_FAST_BINARY_PROTOCOL
48template <
typename Buffer>
struct
49is_protocol_enabled<FastBinaryReader<Buffer> >
54template <
typename Reader,
typename Enable =
void>
struct
58template <
typename Reader>
struct
59uses_dynamic_parser<Reader,
typename boost::enable_if<
60 std::is_same<typename Reader::Parser, DynamicParser<Reader&> > >::type>
63template <
typename Reader>
struct
64uses_dynamic_parser<Reader&>
65 : uses_dynamic_parser<Reader> {};
68template <
typename Reader,
typename Enable =
void>
struct
72template <
typename Reader>
struct
73uses_dom_parser<Reader,
typename boost::enable_if<
74 std::is_same<typename Reader::Parser, DOMParser<Reader&> > >::type>
77template <
typename Reader>
struct
78uses_dom_parser<Reader&>
79 : uses_dom_parser<Reader> {};
82template <
typename Reader,
typename Unused>
struct
84 : uses_static_parser<Reader> {};
87template <
typename... T>
91 template <
typename Buffer>
92 struct FilterBufferHelper;
95 using type = detail::mpl::list<T...>;
97 template <
typename... U>
98 using Append =
typename Protocols<detail::mpl::append_t<type, U...> >::type;
100 using FilterEnabled =
typename Protocols<detail::mpl::filter_t<type, is_protocol_enabled> >::type;
102 template <
typename Buffer>
103 using FilterBuffer =
typename FilterBufferHelper<Buffer>::type;
106 template <
typename Buffer>
107 struct FilterBufferHelper
109 template <
typename U>
110 using check_buffer = std::is_same<typename std::remove_reference<typename U::Buffer>::type, Buffer>;
112 using type =
typename Protocols<detail::mpl::filter_t<typename FilterEnabled::type, check_buffer> >::type;
117template <
typename... T>
118struct Protocols<detail::mpl::list<T...> >
120 using type = Protocols<T...>;
126struct BuiltInProtocols
128 CompactBinaryReader<InputBuffer>,
129 SimpleBinaryReader<InputBuffer>,
130 FastBinaryReader<InputBuffer>,
131 SimpleJsonReader<InputBuffer> > {};
136 BOOST_STATIC_CONSTEXPR uint16_t magic = 0x5256 ;
139 ValueReader() BOND_NOEXCEPT
143 template <
typename U>
144 ValueReader(boost::reference_wrapper<U> value) BOND_NOEXCEPT
145 : pointer(&
static_cast<const U&
>(value))
148 template <
typename U>
149 ValueReader(
const U& value)
150 : instance(boost::make_shared<U>(value)),
151 pointer(instance.get())
154 template <
typename U>
155 ValueReader(boost::shared_ptr<U> value) BOND_NOEXCEPT
156 : instance(boost::static_pointer_cast<const void>(value)),
157 pointer(instance.get())
160 ValueReader(
const ValueReader& value) BOND_NOEXCEPT
161 : instance(value.instance),
162 pointer(value.pointer)
167 return instance == rhs.instance
168 && pointer == rhs.pointer;
171 boost::shared_ptr<const void> instance;
176BOND_DEFINE_BUFFER_MAGIC(ValueReader::Buffer, 0);
183#pragma warning(disable: 4296)
187 template <std::
size_t V0, std::
size_t V1>
189 : std::integral_constant<std::size_t, (V0 < V1 ? V1 : V0)> {};
195 template <typename List> struct
199 max_size<detail::mpl::list<> >
200 : std::integral_constant<std::size_t, 0> {};
202 template <typename T, typename... U> struct
203 max_size<detail::mpl::list<T, U...> >
204 : max_of<sizeof(T), max_size<detail::mpl::list<U...> >::value> {};
206 using protocol_max_size = max_size<BuiltInProtocols::Append<ValueReader>::type>;
217 ProtocolReader(const ValueReader& reader = {})
221 template <typename Reader, typename boost::enable_if<is_reader<Reader> >::type* = nullptr>
222 ProtocolReader(const Reader& reader)
226 bool operator==(const ProtocolReader& rhs) const
228 return _value == rhs._value;
231#if !defined(BOND_NO_CXX14_RETURN_TYPE_DEDUCTION) && !defined(BOND_NO_CXX14_GENERIC_LAMBDAS)
232 template <typename Protocols, typename Visitor>
233 auto Visit(Visitor&& visitor)
235 template <typename Protocols, typename Result, typename Visitor>
236 typename detail::visitor_result<Result>::type Visit(Visitor&& visitor)
239 return detail::visit_any<typename Protocols::template Append<ValueReader>::type
240#if defined(BOND_NO_CXX14_RETURN_TYPE_DEDUCTION) || defined(BOND_NO_CXX14_GENERIC_LAMBDAS)
243 >(std::forward<Visitor>(visitor), _value);
247 template <typename Reader> struct
249 : std::integral_constant<uint32_t, Reader::magic | (buffer_magic<typename Reader::Buffer>::value << 16)> {};
252 detail::any<reader_id, detail::protocol_max_size::value> _value;
namespace bond
Definition: apply.h:17
boost::enable_if< is_signed_int_or_enum< SignedT >, bool >::type operator==(const Variant &variant, SignedT value)
Compares variant for equality against the provided signed integer or enum value.
Definition: metadata.h:24