1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
3  
// Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/boostorg/json
8  
// Official repository: https://github.com/boostorg/json
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_JSON_DETAIL_PARSE_INTO_HPP
11  
#ifndef BOOST_JSON_DETAIL_PARSE_INTO_HPP
12  
#define BOOST_JSON_DETAIL_PARSE_INTO_HPP
12  
#define BOOST_JSON_DETAIL_PARSE_INTO_HPP
13  

13  

14  
#include <boost/json/detail/config.hpp>
14  
#include <boost/json/detail/config.hpp>
15  

15  

16  
#include <boost/json/error.hpp>
16  
#include <boost/json/error.hpp>
17  
#include <boost/json/conversion.hpp>
17  
#include <boost/json/conversion.hpp>
18  
#include <boost/describe/enum_from_string.hpp>
18  
#include <boost/describe/enum_from_string.hpp>
19  

19  

20  
#include <vector>
20  
#include <vector>
21  

21  

22  
/*
22  
/*
23  
 * This file contains the majority of parse_into functionality, specifically
23  
 * This file contains the majority of parse_into functionality, specifically
24  
 * the implementation of dedicated handlers for different generic categories of
24  
 * the implementation of dedicated handlers for different generic categories of
25  
 * types.
25  
 * types.
26  
 *
26  
 *
27  
 * At the core of parse_into is the specialisation basic_parser<
27  
 * At the core of parse_into is the specialisation basic_parser<
28  
 * detail::into_handler<T> >. detail::into_handler<T> is a handler for
28  
 * detail::into_handler<T> >. detail::into_handler<T> is a handler for
29  
 * basic_parser. It directly handles events on_comment_part and on_comment (by
29  
 * basic_parser. It directly handles events on_comment_part and on_comment (by
30  
 * ignoring them), on_document_begin (by enabling the nested dedicated
30  
 * ignoring them), on_document_begin (by enabling the nested dedicated
31  
 * handler), and on_document_end (by disabling the nested handler).
31  
 * handler), and on_document_end (by disabling the nested handler).
32  
 *
32  
 *
33  
 * Every other event is handled by the nested handler, which has the type
33  
 * Every other event is handled by the nested handler, which has the type
34 -
 * get_handler< T, into_handler<T> >. The second parameter is the parent
34 +
 * get_handler<T, P, Ctx>. The second parameter is the parent
35  
 * handler (in this case, it's the top handler, into_handler<T>). The type is
35  
 * handler (in this case, it's the top handler, into_handler<T>). The type is
36  
 * actually an alias to class template converting_handler, which has a separate
36  
 * actually an alias to class template converting_handler, which has a separate
37  
 * specialisation for every conversion category from the list of generic
37  
 * specialisation for every conversion category from the list of generic
38  
 * conversion categories (e.g. sequence_conversion_tag, tuple_conversion_tag,
38  
 * conversion categories (e.g. sequence_conversion_tag, tuple_conversion_tag,
39  
 * etc.) Instantiations of the template store a pointer to the parent handler
39  
 * etc.) Instantiations of the template store a pointer to the parent handler
40  
 * and a pointer to the value T.
40  
 * and a pointer to the value T.
41  
 *
41  
 *
42  
 * The nested handler handles specific parser events by setting error_code to
42  
 * The nested handler handles specific parser events by setting error_code to
43  
 * an appropriate value, if it receives an event it isn't supposed to handle
43  
 * an appropriate value, if it receives an event it isn't supposed to handle
44  
 * (e.g. a number handler getting an on_string event), and also updates the
44  
 * (e.g. a number handler getting an on_string event), and also updates the
45  
 * value when appropriate. Note that they never need to handle on_comment_part,
45  
 * value when appropriate. Note that they never need to handle on_comment_part,
46  
 * on_comment, on_document_begin, and on_document_end events, as those are
46  
 * on_comment, on_document_begin, and on_document_end events, as those are
47  
 * always handled by the top handler into_handler<T>.
47  
 * always handled by the top handler into_handler<T>.
48  
 *
48  
 *
49  
 * When the nested handler receives an event that completes the current value,
49  
 * When the nested handler receives an event that completes the current value,
50  
 * it is supposed to call its parent's signal_value member function. This is
50  
 * it is supposed to call its parent's signal_value member function. This is
51  
 * necessary for correct handling of composite types (e.g. sequences).
51  
 * necessary for correct handling of composite types (e.g. sequences).
52  
 *
52  
 *
53  
 * Finally, nested handlers should always call parent's signal_end member
53  
 * Finally, nested handlers should always call parent's signal_end member
54  
 * function if they don't handle on_array_end themselves. This is necessary
54  
 * function if they don't handle on_array_end themselves. This is necessary
55  
 * to correctly handle nested composites (e.g. sequences inside sequences).
55  
 * to correctly handle nested composites (e.g. sequences inside sequences).
56  
 * signal_end can return false and set error state when the containing parser
56  
 * signal_end can return false and set error state when the containing parser
57  
 * requires more elements.
57  
 * requires more elements.
58  
 *
58  
 *
59  
 * converting_handler instantiations for composite categories of types have
59  
 * converting_handler instantiations for composite categories of types have
60  
 * their own nested handlers, to which they themselves delegate events. For
60  
 * their own nested handlers, to which they themselves delegate events. For
61  
 * complex types you will get a tree of handlers with into_handler<T> as the
61  
 * complex types you will get a tree of handlers with into_handler<T> as the
62  
 * root and handlers for scalars as leaves.
62  
 * root and handlers for scalars as leaves.
63  
 *
63  
 *
64  
 * To reiterate, only into_handler has to handle on_comment_part, on_comment,
64  
 * To reiterate, only into_handler has to handle on_comment_part, on_comment,
65  
 * on_document_begin, and on_document_end; only handlers for composites and
65  
 * on_document_begin, and on_document_end; only handlers for composites and
66  
 * into_handler has to provide signal_value and signal_end; all handlers
66  
 * into_handler has to provide signal_value and signal_end; all handlers
67  
 * except for into_handler have to call their parent's signal_end from
67  
 * except for into_handler have to call their parent's signal_end from
68  
 * their on_array_begin, if they don't handle it themselves; once a handler
68  
 * their on_array_begin, if they don't handle it themselves; once a handler
69  
 * receives an event that finishes its current value, it should call its
69  
 * receives an event that finishes its current value, it should call its
70  
 * parent's signal_value.
70  
 * parent's signal_value.
71  
 */
71  
 */
72  

72  

73  
namespace boost {
73  
namespace boost {
74  
namespace json {
74  
namespace json {
75  
namespace detail {
75  
namespace detail {
76  

76  

77 -
template< class Impl, class T, class Parent >
77 +
template< class Impl, class T, class Parent, class Ctx >
78  
class converting_handler;
78  
class converting_handler;
79  

79  

80  
// get_handler
80  
// get_handler
81 -
template< class V, class P >
81 +
template<class V, class P, class Ctx>
82 -
using get_handler = converting_handler< generic_conversion_category<V>, V, P >;
82 +
using get_handler = converting_handler<
 
83 +
    generic_conversion_category<V, Ctx>, V, P, Ctx>;
83  

84  

84  
template<error E> class handler_error_base
85  
template<error E> class handler_error_base
85  
{
86  
{
86  
public:
87  
public:
87  

88  

88  
    handler_error_base() = default;
89  
    handler_error_base() = default;
89  

90  

90  
    handler_error_base( handler_error_base const& ) = delete;
91  
    handler_error_base( handler_error_base const& ) = delete;
91  
    handler_error_base& operator=( handler_error_base const& ) = delete;
92  
    handler_error_base& operator=( handler_error_base const& ) = delete;
92  

93  

93  
public:
94  
public:
94  

95  

95  
    bool on_object_begin( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
96  
    bool on_object_begin( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
96  
    bool on_array_begin( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
97  
    bool on_array_begin( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
97  
    bool on_array_end( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
98  
    bool on_array_end( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
98  
    bool on_string_part( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
99  
    bool on_string_part( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
99  
    bool on_string( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
100  
    bool on_string( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
100  
    bool on_number_part( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
101  
    bool on_number_part( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
101  
    bool on_int64( system::error_code& ec, std::int64_t ) { BOOST_JSON_FAIL( ec, E ); return false; }
102  
    bool on_int64( system::error_code& ec, std::int64_t ) { BOOST_JSON_FAIL( ec, E ); return false; }
102  
    bool on_uint64( system::error_code& ec, std::uint64_t ) { BOOST_JSON_FAIL( ec, E ); return false; }
103  
    bool on_uint64( system::error_code& ec, std::uint64_t ) { BOOST_JSON_FAIL( ec, E ); return false; }
103  
    bool on_double( system::error_code& ec, double ) { BOOST_JSON_FAIL( ec, E ); return false; }
104  
    bool on_double( system::error_code& ec, double ) { BOOST_JSON_FAIL( ec, E ); return false; }
104  
    bool on_bool( system::error_code& ec, bool ) { BOOST_JSON_FAIL( ec, E ); return false; }
105  
    bool on_bool( system::error_code& ec, bool ) { BOOST_JSON_FAIL( ec, E ); return false; }
105  
    bool on_null( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
106  
    bool on_null( system::error_code& ec ) { BOOST_JSON_FAIL( ec, E ); return false; }
106  

107  

107  
    // LCOV_EXCL_START
108  
    // LCOV_EXCL_START
108  
    // parses that can't handle this would fail at on_object_begin
109  
    // parses that can't handle this would fail at on_object_begin
109  
    bool on_object_end( system::error_code& ) { BOOST_ASSERT( false ); return false; }
110  
    bool on_object_end( system::error_code& ) { BOOST_ASSERT( false ); return false; }
110  
    bool on_key_part( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
111  
    bool on_key_part( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
111  
    bool on_key( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
112  
    bool on_key( system::error_code& ec, string_view ) { BOOST_JSON_FAIL( ec, E ); return false; }
112  
    // LCOV_EXCL_STOP
113  
    // LCOV_EXCL_STOP
113  
};
114  
};
114  

115  

115  
template< class P, error E >
116  
template< class P, error E >
116  
class scalar_handler
117  
class scalar_handler
117  
    : public handler_error_base<E>
118  
    : public handler_error_base<E>
118  
{
119  
{
119  
protected:
120  
protected:
120  
    P* parent_;
121  
    P* parent_;
121  

122  

122  
public:
123  
public:
123  
    scalar_handler(scalar_handler const&) = delete;
124  
    scalar_handler(scalar_handler const&) = delete;
124  
    scalar_handler& operator=(scalar_handler const&) = delete;
125  
    scalar_handler& operator=(scalar_handler const&) = delete;
125  

126  

126  
    scalar_handler(P* p): parent_( p )
127  
    scalar_handler(P* p): parent_( p )
127  
    {}
128  
    {}
128  

129  

129  
    bool on_array_end( system::error_code& ec )
130  
    bool on_array_end( system::error_code& ec )
130  
    {
131  
    {
131  
        return parent_->signal_end(ec);
132  
        return parent_->signal_end(ec);
132  
    }
133  
    }
133  
};
134  
};
134  

135  

135 -
template< class D, class V, class P, error E >
136 +
template<class D, class V, class P, class Ctx, error E>
136  
class composite_handler
137  
class composite_handler
137  
{
138  
{
138  
protected:
139  
protected:
139 -
    using inner_handler_type = get_handler<V, D>;
140 +
    using representation = conversion_representation<V, Ctx>;
 
141 +
    using inner_handler_type = get_handler<representation, D, Ctx>;
140  

142  

141  
    P* parent_;
143  
    P* parent_;
142  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
144  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
143  
# pragma GCC diagnostic push
145  
# pragma GCC diagnostic push
144  
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
146  
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
145  
#endif
147  
#endif
146 -
    V next_value_ = {};
148 +
    representation next_value_ = {};
147  
    inner_handler_type inner_;
149  
    inner_handler_type inner_;
148  
    bool inner_active_ = false;
150  
    bool inner_active_ = false;
149  

151  

150  
public:
152  
public:
151 -
    composite_handler( composite_handler const& ) = delete;
153 +
    composite_handler(composite_handler const&) = delete;
152 -
    composite_handler& operator=( composite_handler const& ) = delete;
154 +
    composite_handler& operator=(composite_handler const&) = delete;
153  

155  

154 -
    composite_handler( P* p )
156 +
    composite_handler(P* p)
155  
        : parent_(p), inner_( &next_value_, static_cast<D*>(this) )
157  
        : parent_(p), inner_( &next_value_, static_cast<D*>(this) )
156  
    {}
158  
    {}
157  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
159  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
158  
# pragma GCC diagnostic pop
160  
# pragma GCC diagnostic pop
159  
#endif
161  
#endif
160  

162  

161  
    bool signal_end(system::error_code& ec)
163  
    bool signal_end(system::error_code& ec)
162  
    {
164  
    {
163  
        inner_active_ = false;
165  
        inner_active_ = false;
164  
        return parent_->signal_value(ec);
166  
        return parent_->signal_value(ec);
165  
    }
167  
    }
166  

168  

167  
#define BOOST_JSON_INVOKE_INNER(f) \
169  
#define BOOST_JSON_INVOKE_INNER(f) \
168  
    if( !inner_active_ ) { \
170  
    if( !inner_active_ ) { \
169  
        BOOST_JSON_FAIL(ec, E); \
171  
        BOOST_JSON_FAIL(ec, E); \
170  
        return false; \
172  
        return false; \
171  
    } \
173  
    } \
172  
    else \
174  
    else \
173  
        return inner_.f
175  
        return inner_.f
174  

176  

175  
    bool on_object_begin( system::error_code& ec )
177  
    bool on_object_begin( system::error_code& ec )
176  
    {
178  
    {
177  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
179  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
178  
    }
180  
    }
179  

181  

180  
    bool on_object_end( system::error_code& ec )
182  
    bool on_object_end( system::error_code& ec )
181  
    {
183  
    {
182  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
184  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
183  
    }
185  
    }
184  

186  

185  
    bool on_array_begin( system::error_code& ec )
187  
    bool on_array_begin( system::error_code& ec )
186  
    {
188  
    {
187  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
189  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
188  
    }
190  
    }
189  

191  

190  
    bool on_array_end( system::error_code& ec )
192  
    bool on_array_end( system::error_code& ec )
191  
    {
193  
    {
192  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
194  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
193  
    }
195  
    }
194  

196  

195  
    bool on_key_part( system::error_code& ec, string_view sv )
197  
    bool on_key_part( system::error_code& ec, string_view sv )
196  
    {
198  
    {
197  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
199  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
198  
    }
200  
    }
199  

201  

200  
    bool on_key( system::error_code& ec, string_view sv )
202  
    bool on_key( system::error_code& ec, string_view sv )
201  
    {
203  
    {
202  
        BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
204  
        BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
203  
    }
205  
    }
204  

206  

205  
    bool on_string_part( system::error_code& ec, string_view sv )
207  
    bool on_string_part( system::error_code& ec, string_view sv )
206  
    {
208  
    {
207  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
209  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
208  
    }
210  
    }
209  

211  

210  
    bool on_string( system::error_code& ec, string_view sv )
212  
    bool on_string( system::error_code& ec, string_view sv )
211  
    {
213  
    {
212  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
214  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
213  
    }
215  
    }
214  

216  

215  
    bool on_number_part( system::error_code& ec )
217  
    bool on_number_part( system::error_code& ec )
216  
    {
218  
    {
217  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
219  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
218  
    }
220  
    }
219  

221  

220  
    bool on_int64( system::error_code& ec, std::int64_t v )
222  
    bool on_int64( system::error_code& ec, std::int64_t v )
221  
    {
223  
    {
222  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
224  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
223  
    }
225  
    }
224  

226  

225  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
227  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
226  
    {
228  
    {
227  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
229  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
228  
    }
230  
    }
229  

231  

230  
    bool on_double( system::error_code& ec, double v )
232  
    bool on_double( system::error_code& ec, double v )
231  
    {
233  
    {
232  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
234  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
233  
    }
235  
    }
234  

236  

235  
    bool on_bool( system::error_code& ec, bool v )
237  
    bool on_bool( system::error_code& ec, bool v )
236  
    {
238  
    {
237  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
239  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
238  
    }
240  
    }
239  

241  

240  
    bool on_null( system::error_code& ec )
242  
    bool on_null( system::error_code& ec )
241  
    {
243  
    {
242  
        BOOST_JSON_INVOKE_INNER( on_null(ec) );
244  
        BOOST_JSON_INVOKE_INNER( on_null(ec) );
243  
    }
245  
    }
244  

246  

245  
#undef BOOST_JSON_INVOKE_INNER
247  
#undef BOOST_JSON_INVOKE_INNER
246  
};
248  
};
247  

249  

248  
// integral handler
250  
// integral handler
249  
template<class V,
251  
template<class V,
250  
typename std::enable_if<std::is_signed<V>::value, int>::type = 0>
252  
typename std::enable_if<std::is_signed<V>::value, int>::type = 0>
251  
bool integral_in_range( std::int64_t v )
253  
bool integral_in_range( std::int64_t v )
252  
{
254  
{
253  
    return v >= (std::numeric_limits<V>::min)() && v <= (std::numeric_limits<V>::max)();
255  
    return v >= (std::numeric_limits<V>::min)() && v <= (std::numeric_limits<V>::max)();
254  
}
256  
}
255  

257  

256  
template<class V,
258  
template<class V,
257  
typename std::enable_if<!std::is_signed<V>::value, int>::type = 0>
259  
typename std::enable_if<!std::is_signed<V>::value, int>::type = 0>
258  
bool integral_in_range( std::int64_t v )
260  
bool integral_in_range( std::int64_t v )
259  
{
261  
{
260  
    return v >= 0 && static_cast<std::uint64_t>( v ) <= (std::numeric_limits<V>::max)();
262  
    return v >= 0 && static_cast<std::uint64_t>( v ) <= (std::numeric_limits<V>::max)();
261  
}
263  
}
262  

264  

263  
template<class V>
265  
template<class V>
264  
bool integral_in_range( std::uint64_t v )
266  
bool integral_in_range( std::uint64_t v )
265  
{
267  
{
266  
    return v <= static_cast<typename std::make_unsigned<V>::type>( (std::numeric_limits<V>::max)() );
268  
    return v <= static_cast<typename std::make_unsigned<V>::type>( (std::numeric_limits<V>::max)() );
267  
}
269  
}
268  

270  

269 -
template< class V, class P >
271 +
template< class V, class P, class Ctx >
270 -
class converting_handler<integral_conversion_tag, V, P>
272 +
class converting_handler<integral_conversion_tag, V, P, Ctx>
271  
    : public scalar_handler<P, error::not_integer>
273  
    : public scalar_handler<P, error::not_integer>
272  
{
274  
{
273  
private:
275  
private:
274  
    V* value_;
276  
    V* value_;
275  

277  

276  
public:
278  
public:
277  
    converting_handler( V* v, P* p )
279  
    converting_handler( V* v, P* p )
278  
        : converting_handler::scalar_handler(p)
280  
        : converting_handler::scalar_handler(p)
279  
        , value_(v)
281  
        , value_(v)
280  
    {}
282  
    {}
281  

283  

282  
    bool on_number_part( system::error_code& )
284  
    bool on_number_part( system::error_code& )
283  
    {
285  
    {
284  
        return true;
286  
        return true;
285  
    }
287  
    }
286  

288  

287  
    bool on_int64(system::error_code& ec, std::int64_t v)
289  
    bool on_int64(system::error_code& ec, std::int64_t v)
288  
    {
290  
    {
289  
        if( !integral_in_range<V>( v ) )
291  
        if( !integral_in_range<V>( v ) )
290  
        {
292  
        {
291  
            BOOST_JSON_FAIL( ec, error::not_exact );
293  
            BOOST_JSON_FAIL( ec, error::not_exact );
292  
            return false;
294  
            return false;
293  
        }
295  
        }
294  

296  

295  
        *value_ = static_cast<V>( v );
297  
        *value_ = static_cast<V>( v );
296  
        return this->parent_->signal_value(ec);
298  
        return this->parent_->signal_value(ec);
297  
    }
299  
    }
298  

300  

299  
    bool on_uint64(system::error_code& ec, std::uint64_t v)
301  
    bool on_uint64(system::error_code& ec, std::uint64_t v)
300  
    {
302  
    {
301  
        if( !integral_in_range<V>(v) )
303  
        if( !integral_in_range<V>(v) )
302  
        {
304  
        {
303  
            BOOST_JSON_FAIL( ec, error::not_exact );
305  
            BOOST_JSON_FAIL( ec, error::not_exact );
304  
            return false;
306  
            return false;
305  
        }
307  
        }
306  

308  

307  
        *value_ = static_cast<V>(v);
309  
        *value_ = static_cast<V>(v);
308  
        return this->parent_->signal_value(ec);
310  
        return this->parent_->signal_value(ec);
309  
    }
311  
    }
310  
};
312  
};
311  

313  

312  
// floating point handler
314  
// floating point handler
313 -
template< class V, class P>
315 +
template< class V, class P, class Ctx>
314 -
class converting_handler<floating_point_conversion_tag, V, P>
316 +
class converting_handler<floating_point_conversion_tag, V, P, Ctx>
315  
    : public scalar_handler<P, error::not_double>
317  
    : public scalar_handler<P, error::not_double>
316  
{
318  
{
317  
private:
319  
private:
318  
    V* value_;
320  
    V* value_;
319  

321  

320  
public:
322  
public:
321  
    converting_handler( V* v, P* p )
323  
    converting_handler( V* v, P* p )
322  
        : converting_handler::scalar_handler(p)
324  
        : converting_handler::scalar_handler(p)
323  
        , value_(v)
325  
        , value_(v)
324  
    {}
326  
    {}
325  

327  

326  
    bool on_number_part( system::error_code& )
328  
    bool on_number_part( system::error_code& )
327  
    {
329  
    {
328  
        return true;
330  
        return true;
329  
    }
331  
    }
330  

332  

331  
    bool on_int64(system::error_code& ec, std::int64_t v)
333  
    bool on_int64(system::error_code& ec, std::int64_t v)
332  
    {
334  
    {
333  
        *value_ = static_cast<V>(v);
335  
        *value_ = static_cast<V>(v);
334  
        return this->parent_->signal_value(ec);
336  
        return this->parent_->signal_value(ec);
335  
    }
337  
    }
336  

338  

337  
    bool on_uint64(system::error_code& ec, std::uint64_t v)
339  
    bool on_uint64(system::error_code& ec, std::uint64_t v)
338  
    {
340  
    {
339  
        *value_ = static_cast<V>(v);
341  
        *value_ = static_cast<V>(v);
340  
        return this->parent_->signal_value(ec);
342  
        return this->parent_->signal_value(ec);
341  
    }
343  
    }
342  

344  

343  
    bool on_double(system::error_code& ec, double v)
345  
    bool on_double(system::error_code& ec, double v)
344  
    {
346  
    {
345  
        *value_ = static_cast<V>(v);
347  
        *value_ = static_cast<V>(v);
346  
        return this->parent_->signal_value(ec);
348  
        return this->parent_->signal_value(ec);
347  
    }
349  
    }
348  
};
350  
};
349  

351  

350  
// string handler
352  
// string handler
351 -
template< class V, class P >
353 +
template<class V, class P, class Ctx>
352 -
class converting_handler<string_like_conversion_tag, V, P>
354 +
class converting_handler<string_like_conversion_tag, V, P, Ctx>
353  
    : public scalar_handler<P, error::not_string>
355  
    : public scalar_handler<P, error::not_string>
354  
{
356  
{
355  
private:
357  
private:
356  
    V* value_;
358  
    V* value_;
357  
    bool cleared_ = false;
359  
    bool cleared_ = false;
358  

360  

359  
public:
361  
public:
360  
    converting_handler( V* v, P* p )
362  
    converting_handler( V* v, P* p )
361  
        : converting_handler::scalar_handler(p)
363  
        : converting_handler::scalar_handler(p)
362  
        , value_(v)
364  
        , value_(v)
363  
    {}
365  
    {}
364  

366  

365  
    bool on_string_part( system::error_code&, string_view sv )
367  
    bool on_string_part( system::error_code&, string_view sv )
366  
    {
368  
    {
367  
        if( !cleared_ )
369  
        if( !cleared_ )
368  
        {
370  
        {
369  
            cleared_ = true;
371  
            cleared_ = true;
370  
            value_->clear();
372  
            value_->clear();
371  
        }
373  
        }
372  

374  

373  
        value_->append( sv.begin(), sv.end() );
375  
        value_->append( sv.begin(), sv.end() );
374  
        return true;
376  
        return true;
375  
    }
377  
    }
376  

378  

377  
    bool on_string(system::error_code& ec, string_view sv)
379  
    bool on_string(system::error_code& ec, string_view sv)
378  
    {
380  
    {
379  
        if( !cleared_ )
381  
        if( !cleared_ )
380  
            value_->clear();
382  
            value_->clear();
381  
        else
383  
        else
382  
            cleared_ = false;
384  
            cleared_ = false;
383  

385  

384  
        value_->append( sv.begin(), sv.end() );
386  
        value_->append( sv.begin(), sv.end() );
385  
        return this->parent_->signal_value(ec);
387  
        return this->parent_->signal_value(ec);
386  
    }
388  
    }
387  
};
389  
};
388  

390  

389  
// bool handler
391  
// bool handler
390 -
template< class V, class P >
392 +
template<class V, class P, class Ctx>
391 -
class converting_handler<bool_conversion_tag, V, P>
393 +
class converting_handler<bool_conversion_tag, V, P, Ctx>
392  
    : public scalar_handler<P, error::not_bool>
394  
    : public scalar_handler<P, error::not_bool>
393  
{
395  
{
394  
private:
396  
private:
395  
    V* value_;
397  
    V* value_;
396  

398  

397  
public:
399  
public:
398  
    converting_handler( V* v, P* p )
400  
    converting_handler( V* v, P* p )
399  
        : converting_handler::scalar_handler(p)
401  
        : converting_handler::scalar_handler(p)
400  
        , value_(v)
402  
        , value_(v)
401  
    {}
403  
    {}
402  

404  

403  
    bool on_bool(system::error_code& ec, bool v)
405  
    bool on_bool(system::error_code& ec, bool v)
404  
    {
406  
    {
405  
        *value_ = v;
407  
        *value_ = v;
406  
        return this->parent_->signal_value(ec);
408  
        return this->parent_->signal_value(ec);
407  
    }
409  
    }
408  
};
410  
};
409  

411  

410  
// null handler
412  
// null handler
411 -
template< class V, class P >
413 +
template<class V, class P, class Ctx>
412 -
class converting_handler<null_like_conversion_tag, V, P>
414 +
class converting_handler<null_like_conversion_tag, V, P, Ctx>
413  
    : public scalar_handler<P, error::not_null>
415  
    : public scalar_handler<P, error::not_null>
414  
{
416  
{
415  
private:
417  
private:
416  
    V* value_;
418  
    V* value_;
417  

419  

418  
public:
420  
public:
419  
    converting_handler( V* v, P* p )
421  
    converting_handler( V* v, P* p )
420  
        : converting_handler::scalar_handler(p)
422  
        : converting_handler::scalar_handler(p)
421  
        , value_(v)
423  
        , value_(v)
422  
    {}
424  
    {}
423  

425  

424  
    bool on_null(system::error_code& ec)
426  
    bool on_null(system::error_code& ec)
425  
    {
427  
    {
426  
        *value_ = {};
428  
        *value_ = {};
427  
        return this->parent_->signal_value(ec);
429  
        return this->parent_->signal_value(ec);
428  
    }
430  
    }
429  
};
431  
};
430  

432  

431  
// described enum handler
433  
// described enum handler
432 -
template< class V, class P >
434 +
template<class V, class P, class Ctx>
433 -
class converting_handler<described_enum_conversion_tag, V, P>
435 +
class converting_handler<described_enum_conversion_tag, V, P, Ctx>
434  
    : public scalar_handler<P, error::not_string>
436  
    : public scalar_handler<P, error::not_string>
435  
{
437  
{
436  
#ifndef BOOST_DESCRIBE_CXX14
438  
#ifndef BOOST_DESCRIBE_CXX14
437  

439  

438  
    static_assert(
440  
    static_assert(
439  
        sizeof(V) == 0, "Enum support for parse_into requires C++14" );
441  
        sizeof(V) == 0, "Enum support for parse_into requires C++14" );
440  

442  

441  
#else
443  
#else
442  

444  

443  
private:
445  
private:
444  
    V* value_;
446  
    V* value_;
445  
    std::string name_;
447  
    std::string name_;
446  

448  

447  
public:
449  
public:
448  
    converting_handler( V* v, P* p )
450  
    converting_handler( V* v, P* p )
449  
        : converting_handler::scalar_handler(p)
451  
        : converting_handler::scalar_handler(p)
450  
        , value_(v)
452  
        , value_(v)
451  
    {}
453  
    {}
452  

454  

453  
    bool on_string_part( system::error_code&, string_view sv )
455  
    bool on_string_part( system::error_code&, string_view sv )
454  
    {
456  
    {
455  
        name_.append( sv.begin(), sv.end() );
457  
        name_.append( sv.begin(), sv.end() );
456  
        return true;
458  
        return true;
457  
    }
459  
    }
458  

460  

459  
    bool on_string(system::error_code& ec, string_view sv)
461  
    bool on_string(system::error_code& ec, string_view sv)
460  
    {
462  
    {
461  
        string_view name = sv;
463  
        string_view name = sv;
462  
        if( !name_.empty() )
464  
        if( !name_.empty() )
463  
        {
465  
        {
464  
            name_.append( sv.begin(), sv.end() );
466  
            name_.append( sv.begin(), sv.end() );
465  
            name = name_;
467  
            name = name_;
466  
        }
468  
        }
467  

469  

468  
        if( !describe::enum_from_string(name, *value_) )
470  
        if( !describe::enum_from_string(name, *value_) )
469  
        {
471  
        {
470  
            BOOST_JSON_FAIL(ec, error::unknown_name);
472  
            BOOST_JSON_FAIL(ec, error::unknown_name);
471  
            return false;
473  
            return false;
472  
        }
474  
        }
473  

475  

474  
        return this->parent_->signal_value(ec);
476  
        return this->parent_->signal_value(ec);
475  
    }
477  
    }
476  

478  

477  
#endif // BOOST_DESCRIBE_CXX14
479  
#endif // BOOST_DESCRIBE_CXX14
478  
};
480  
};
479  

481  

480 -
template< class V, class P >
482 +
template<class V, class P, class Ctx>
481 -
class converting_handler<no_conversion_tag, V, P>
483 +
class converting_handler<no_conversion_tag, V, P, Ctx>
482  
{
484  
{
483  
    static_assert( sizeof(V) == 0, "This type is not supported" );
485  
    static_assert( sizeof(V) == 0, "This type is not supported" );
484  
};
486  
};
485  

487  

486  
// sequence handler
488  
// sequence handler
487  
template< class It >
489  
template< class It >
488  
bool cannot_insert(It i, It e)
490  
bool cannot_insert(It i, It e)
489  
{
491  
{
490  
    return i == e;
492  
    return i == e;
491  
}
493  
}
492  

494  

493  
template< class It1, class It2 >
495  
template< class It1, class It2 >
494  
std::false_type cannot_insert(It1, It2)
496  
std::false_type cannot_insert(It1, It2)
495  
{
497  
{
496  
    return {};
498  
    return {};
497  
}
499  
}
498  

500  

499  
template< class It >
501  
template< class It >
500  
bool needs_more_elements(It i, It e)
502  
bool needs_more_elements(It i, It e)
501  
{
503  
{
502  
    return i != e;
504  
    return i != e;
503  
}
505  
}
504  

506  

505  
template< class It1, class It2 >
507  
template< class It1, class It2 >
506  
std::false_type needs_more_elements(It1, It2)
508  
std::false_type needs_more_elements(It1, It2)
507  
{
509  
{
508  
    return {};
510  
    return {};
509  
}
511  
}
510  

512  

511  
template<class T>
513  
template<class T>
512  
void
514  
void
513  
clear_container(
515  
clear_container(
514  
    T&,
516  
    T&,
515  
    mp11::mp_int<2>)
517  
    mp11::mp_int<2>)
516  
{
518  
{
517  
}
519  
}
518  

520  

519  
template<class T>
521  
template<class T>
520  
void
522  
void
521  
clear_container(
523  
clear_container(
522  
    T& target,
524  
    T& target,
523  
    mp11::mp_int<1>)
525  
    mp11::mp_int<1>)
524  
{
526  
{
525  
    target.clear();
527  
    target.clear();
526  
}
528  
}
527  

529  

528  
template<class T>
530  
template<class T>
529  
void
531  
void
530  
clear_container(
532  
clear_container(
531  
    T& target,
533  
    T& target,
532  
    mp11::mp_int<0>)
534  
    mp11::mp_int<0>)
533  
{
535  
{
534  
    target.clear();
536  
    target.clear();
535  
}
537  
}
536  

538  

537 -
template< class V, class P >
539 +
template<class V, class P, class Ctx>
538 -
class converting_handler<sequence_conversion_tag, V, P>
540 +
class converting_handler<sequence_conversion_tag, V, P, Ctx>
539  
    : public composite_handler<
541  
    : public composite_handler<
540 -
        converting_handler<sequence_conversion_tag, V, P>,
542 +
        converting_handler<sequence_conversion_tag, V, P, Ctx>,
541  
        detail::value_type<V>,
543  
        detail::value_type<V>,
542  
        P,
544  
        P,
 
545 +
        Ctx,
543  
        error::not_array>
546  
        error::not_array>
544  
{
547  
{
545  
private:
548  
private:
546  
    V* value_;
549  
    V* value_;
547  

550  

548  
    using Inserter = decltype(
551  
    using Inserter = decltype(
549  
        detail::inserter(*value_, inserter_implementation<V>()) );
552  
        detail::inserter(*value_, inserter_implementation<V>()) );
550  
    Inserter inserter;
553  
    Inserter inserter;
551  

554  

552  
public:
555  
public:
553  
    converting_handler( V* v, P* p )
556  
    converting_handler( V* v, P* p )
554  
        : converting_handler::composite_handler(p)
557  
        : converting_handler::composite_handler(p)
555  
        , value_(v)
558  
        , value_(v)
556  
        , inserter( detail::inserter(*value_, inserter_implementation<V>()) )
559  
        , inserter( detail::inserter(*value_, inserter_implementation<V>()) )
557  
    {}
560  
    {}
558  

561  

559  
    bool signal_value(system::error_code& ec)
562  
    bool signal_value(system::error_code& ec)
560  
    {
563  
    {
561  
        if(cannot_insert( inserter, value_->end() ))
564  
        if(cannot_insert( inserter, value_->end() ))
562  
        {
565  
        {
563  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
566  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
564  
            return false;
567  
            return false;
565  
        }
568  
        }
566  

569  

567  
        *inserter++ = std::move(this->next_value_);
570  
        *inserter++ = std::move(this->next_value_);
568  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
571  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
569  
# pragma GCC diagnostic push
572  
# pragma GCC diagnostic push
570  
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
573  
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
571  
#endif
574  
#endif
572  
        this->next_value_ = {};
575  
        this->next_value_ = {};
573  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
576  
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
574  
# pragma GCC diagnostic pop
577  
# pragma GCC diagnostic pop
575  
#endif
578  
#endif
576  
        return true;
579  
        return true;
577  
    }
580  
    }
578  

581  

579  
    bool signal_end(system::error_code& ec)
582  
    bool signal_end(system::error_code& ec)
580  
    {
583  
    {
581  
        if(needs_more_elements( inserter, value_->end() ))
584  
        if(needs_more_elements( inserter, value_->end() ))
582  
        {
585  
        {
583  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
586  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
584  
            return false;
587  
            return false;
585  
        }
588  
        }
586  

589  

587  
        inserter = detail::inserter(*value_, inserter_implementation<V>());
590  
        inserter = detail::inserter(*value_, inserter_implementation<V>());
588  

591  

589  
        return converting_handler::composite_handler::signal_end(ec);
592  
        return converting_handler::composite_handler::signal_end(ec);
590  
    }
593  
    }
591  

594  

592  
    bool on_array_begin( system::error_code& ec )
595  
    bool on_array_begin( system::error_code& ec )
593  
    {
596  
    {
594  
        if( this->inner_active_ )
597  
        if( this->inner_active_ )
595  
            return this->inner_.on_array_begin( ec );
598  
            return this->inner_.on_array_begin( ec );
596  

599  

597  
        this->inner_active_ = true;
600  
        this->inner_active_ = true;
598  
        clear_container( *value_, inserter_implementation<V>() );
601  
        clear_container( *value_, inserter_implementation<V>() );
599  
        return true;
602  
        return true;
600  
    }
603  
    }
601  

604  

602  
    bool on_array_end( system::error_code& ec )
605  
    bool on_array_end( system::error_code& ec )
603  
    {
606  
    {
604  
        if( this->inner_active_ )
607  
        if( this->inner_active_ )
605  
            return this->inner_.on_array_end( ec );
608  
            return this->inner_.on_array_end( ec );
606  

609  

607  
        return this->parent_->signal_end(ec);
610  
        return this->parent_->signal_end(ec);
608  
    }
611  
    }
609  
};
612  
};
610  

613  

611  
// map handler
614  
// map handler
612 -
template< class V, class P >
615 +
template<class V, class P, class Ctx>
613 -
class converting_handler<map_like_conversion_tag, V, P>
616 +
class converting_handler<map_like_conversion_tag, V, P, Ctx>
614  
    : public composite_handler<
617  
    : public composite_handler<
615 -
        converting_handler<map_like_conversion_tag, V, P>,
618 +
        converting_handler<map_like_conversion_tag, V, P, Ctx>,
616  
        detail::mapped_type<V>,
619  
        detail::mapped_type<V>,
617  
        P,
620  
        P,
 
621 +
        Ctx,
618  
        error::not_object>
622  
        error::not_object>
619  
{
623  
{
620  
private:
624  
private:
621  
    V* value_;
625  
    V* value_;
622  
    std::string key_;
626  
    std::string key_;
623  

627  

624  
public:
628  
public:
625  
    converting_handler( V* v, P* p )
629  
    converting_handler( V* v, P* p )
626  
        : converting_handler::composite_handler(p), value_(v)
630  
        : converting_handler::composite_handler(p), value_(v)
627  
    {}
631  
    {}
628  

632  

629  
    bool signal_value(system::error_code&)
633  
    bool signal_value(system::error_code&)
630  
    {
634  
    {
631 -
        value_->emplace( std::move(key_), std::move(this->next_value_) );
635 +
        using key_rep = conversion_representation<detail::key_type<V>, Ctx>;
632 -

636 +
        value_->emplace(
633 -
        key_ = {};
637 +
            static_cast<key_rep>( std::move(key_) ),
 
638 +
            std::move(this->next_value_) );
 
639 +
        key_.clear();
634  
        this->next_value_ = {};
640  
        this->next_value_ = {};
635  

641  

636  
        this->inner_active_ = false;
642  
        this->inner_active_ = false;
637  

643  

638  
        return true;
644  
        return true;
639  
    }
645  
    }
640  

646  

641  
    bool on_object_begin( system::error_code& ec )
647  
    bool on_object_begin( system::error_code& ec )
642  
    {
648  
    {
643  
        if( this->inner_active_ )
649  
        if( this->inner_active_ )
644  
            return this->inner_.on_object_begin(ec);
650  
            return this->inner_.on_object_begin(ec);
645  

651  

646  
        clear_container( *value_, inserter_implementation<V>() );
652  
        clear_container( *value_, inserter_implementation<V>() );
647  
        return true;
653  
        return true;
648  
    }
654  
    }
649  

655  

650  
    bool on_object_end(system::error_code& ec)
656  
    bool on_object_end(system::error_code& ec)
651  
    {
657  
    {
652  
        if( this->inner_active_ )
658  
        if( this->inner_active_ )
653  
            return this->inner_.on_object_end(ec);
659  
            return this->inner_.on_object_end(ec);
654  

660  

655  
        return this->parent_->signal_value(ec);
661  
        return this->parent_->signal_value(ec);
656  
    }
662  
    }
657  

663  

658  
    bool on_array_end( system::error_code& ec )
664  
    bool on_array_end( system::error_code& ec )
659  
    {
665  
    {
660  
        if( this->inner_active_ )
666  
        if( this->inner_active_ )
661  
            return this->inner_.on_array_end(ec);
667  
            return this->inner_.on_array_end(ec);
662  

668  

663  
        return this->parent_->signal_end(ec);
669  
        return this->parent_->signal_end(ec);
664  
    }
670  
    }
665  

671  

666  
    bool on_key_part( system::error_code& ec, string_view sv )
672  
    bool on_key_part( system::error_code& ec, string_view sv )
667  
    {
673  
    {
668  
        if( this->inner_active_ )
674  
        if( this->inner_active_ )
669  
            return this->inner_.on_key_part(ec, sv);
675  
            return this->inner_.on_key_part(ec, sv);
670  

676  

671  
        key_.append( sv.data(), sv.size() );
677  
        key_.append( sv.data(), sv.size() );
672  
        return true;
678  
        return true;
673  
    }
679  
    }
674  

680  

675  
    bool on_key( system::error_code& ec, string_view sv )
681  
    bool on_key( system::error_code& ec, string_view sv )
676  
    {
682  
    {
677  
        if( this->inner_active_ )
683  
        if( this->inner_active_ )
678  
            return this->inner_.on_key(ec, sv);
684  
            return this->inner_.on_key(ec, sv);
679  

685  

680  
        key_.append( sv.data(), sv.size() );
686  
        key_.append( sv.data(), sv.size() );
681  

687  

682  
        this->inner_active_ = true;
688  
        this->inner_active_ = true;
683  
        return true;
689  
        return true;
684  
    }
690  
    }
685  
};
691  
};
686  

692  

687  
// tuple handler
693  
// tuple handler
688 -
template<std::size_t I, class T>
694 +
template<
 
695 +
    std::size_t I,
 
696 +
    class P,
 
697 +
    class Ctx,
 
698 +
    class T,
 
699 +
    class Rep = conversion_representation<T, Ctx> >
689  
struct handler_tuple_element
700  
struct handler_tuple_element
690  
{
701  
{
691 -
    template< class... Args >
702 +
    using representation = conversion_representation<T, Ctx>;
692 -
    handler_tuple_element( Args&& ... args )
703 +
    using handler = get_handler<representation, P, Ctx>;
693 -
        : t_( static_cast<Args&&>(args)... )
704 +

 
705 +
    handler_tuple_element(T* t, P* p)
 
706 +
        : t_(std::addressof(rep_), p), tgt_(t)
694  
    {}
707  
    {}
695  

708  

696 -
    T t_;
709 +
    void
 
710 +
    finish()
 
711 +
    {
 
712 +
        *tgt_ = std::move(rep_);
 
713 +
    }
 
714 +

 
715 +
    Rep rep_;
 
716 +
    handler t_;
 
717 +
    T* tgt_;
697  
};
718  
};
698  

719  

699 -
template<std::size_t I, class T>
720 +
template<std::size_t I, class P, class Ctx, class T>
700 -
T&
721 +
struct handler_tuple_element<I, P, Ctx, T, T>
701 -
get( handler_tuple_element<I, T>& e )
722 +
{
 
723 +
    using handler = get_handler<T, P, Ctx>;
 
724 +

 
725 +
    handler_tuple_element(T* t, P* p)
 
726 +
        : t_(t, p)
 
727 +
    {}
 
728 +

 
729 +
    void
 
730 +
    finish() const noexcept
 
731 +
    {}
 
732 +

 
733 +
    handler t_;
 
734 +
};
 
735 +

 
736 +
template<std::size_t I, class P, class Ctx, class T>
 
737 +
typename handler_tuple_element<I, P, Ctx, T>::handler&
 
738 +
get( handler_tuple_element<I, P, Ctx, T>& e )
702  
{
739  
{
703  
    return e.t_;
740  
    return e.t_;
704  
}
741  
}
705  

742  

706  
template<
743  
template<
707  
    class P,
744  
    class P,
 
745 +
    class Ctx,
708  
    class LV,
746  
    class LV,
709  
    class S = mp11::make_index_sequence<mp11::mp_size<LV>::value> >
747  
    class S = mp11::make_index_sequence<mp11::mp_size<LV>::value> >
710  
struct handler_tuple;
748  
struct handler_tuple;
711  

749  

712 -
template< class P, template<class...> class L, class... V, std::size_t... I >
750 +
template< class P, class Ctx, template<class...> class L, class... V, std::size_t... I >
713 -
struct handler_tuple< P, L<V...>, mp11::index_sequence<I...> >
751 +
struct handler_tuple< P, Ctx, L<V...>, mp11::index_sequence<I...> >
714 -
    : handler_tuple_element<I, V>
752 +
    : handler_tuple_element<I, P, Ctx, V>
715  
    ...
753  
    ...
716  
{
754  
{
717  
    handler_tuple( handler_tuple const& ) = delete;
755  
    handler_tuple( handler_tuple const& ) = delete;
718  
    handler_tuple& operator=( handler_tuple const& ) = delete;
756  
    handler_tuple& operator=( handler_tuple const& ) = delete;
719  

757  

720  
    template< class Access, class T >
758  
    template< class Access, class T >
721  
    handler_tuple( Access access, T* pv, P* pp )
759  
    handler_tuple( Access access, T* pv, P* pp )
722 -
        : handler_tuple_element<I, V>(
760 +
        : handler_tuple_element<I, P, Ctx, V>(
723  
            access( pv, mp11::mp_size_t<I>() ),
761  
            access( pv, mp11::mp_size_t<I>() ),
724  
            pp )
762  
            pp )
725  
        ...
763  
        ...
726  
    {}
764  
    {}
 
765 +

 
766 +
    void
 
767 +
    finish()
 
768 +
    {
 
769 +
        auto _ = {
 
770 +
            (static_cast< handler_tuple_element<I, P, Ctx, V>* >(this)
 
771 +
                ->finish(), 0)
 
772 +
            ...};
 
773 +
        (void)_;
 
774 +
    }
727  
};
775  
};
728  

776  

729  
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
777  
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
730  

778  

731  
template< class T >
779  
template< class T >
732  
struct tuple_element_list_impl
780  
struct tuple_element_list_impl
733  
{
781  
{
734  
    template< class I >
782  
    template< class I >
735  
    using tuple_element_helper = tuple_element_t<I::value, T>;
783  
    using tuple_element_helper = tuple_element_t<I::value, T>;
736  

784  

737  
    using type = mp11::mp_transform<
785  
    using type = mp11::mp_transform<
738  
        tuple_element_helper,
786  
        tuple_element_helper,
739  
        mp11::mp_iota< std::tuple_size<T> > >;
787  
        mp11::mp_iota< std::tuple_size<T> > >;
740  
};
788  
};
741  
template< class T >
789  
template< class T >
742  
using tuple_element_list = typename tuple_element_list_impl<T>::type;
790  
using tuple_element_list = typename tuple_element_list_impl<T>::type;
743  

791  

744  
#else
792  
#else
745  

793  

746  
template< class I, class T >
794  
template< class I, class T >
747  
using tuple_element_helper = tuple_element_t<I::value, T>;
795  
using tuple_element_helper = tuple_element_t<I::value, T>;
748  
template< class T >
796  
template< class T >
749  
using tuple_element_list = mp11::mp_transform_q<
797  
using tuple_element_list = mp11::mp_transform_q<
750  
    mp11::mp_bind_back< tuple_element_helper, T>,
798  
    mp11::mp_bind_back< tuple_element_helper, T>,
751  
    mp11::mp_iota< std::tuple_size<T> > >;
799  
    mp11::mp_iota< std::tuple_size<T> > >;
752  

800  

753  
#endif
801  
#endif
754  

802  

755  
template< class Op, class... Args>
803  
template< class Op, class... Args>
756  
struct handler_op_invoker
804  
struct handler_op_invoker
757  
{
805  
{
758  
public:
806  
public:
759  
    std::tuple<Args&...> args;
807  
    std::tuple<Args&...> args;
760  

808  

761  
    template< class Handler >
809  
    template< class Handler >
762  
    bool
810  
    bool
763  
    operator()( Handler& handler ) const
811  
    operator()( Handler& handler ) const
764  
    {
812  
    {
765  
        return (*this)( handler, mp11::index_sequence_for<Args...>() );
813  
        return (*this)( handler, mp11::index_sequence_for<Args...>() );
766  
    }
814  
    }
767  

815  

768  
private:
816  
private:
769  
    template< class Handler, std::size_t... I >
817  
    template< class Handler, std::size_t... I >
770  
    bool
818  
    bool
771  
    operator()( Handler& handler, mp11::index_sequence<I...> ) const
819  
    operator()( Handler& handler, mp11::index_sequence<I...> ) const
772  
    {
820  
    {
773  
        return Op()( handler, std::get<I>(args)... );
821  
        return Op()( handler, std::get<I>(args)... );
774  
    }
822  
    }
775  
};
823  
};
776  

824  

777  
template< class Handlers, class F >
825  
template< class Handlers, class F >
778  
struct tuple_handler_op_invoker
826  
struct tuple_handler_op_invoker
779  
{
827  
{
780  
    Handlers& handlers;
828  
    Handlers& handlers;
781  
    F fn;
829  
    F fn;
782  

830  

783  
    template< class I >
831  
    template< class I >
784  
    bool
832  
    bool
785  
    operator()( I ) const
833  
    operator()( I ) const
786  
    {
834  
    {
787  
        return fn( get<I::value>(handlers) );
835  
        return fn( get<I::value>(handlers) );
788  
    }
836  
    }
789  
};
837  
};
790  

838  

791  
struct tuple_accessor
839  
struct tuple_accessor
792  
{
840  
{
793  
    template< class T, class I >
841  
    template< class T, class I >
794  
    auto operator()( T* t, I ) const -> tuple_element_t<I::value, T>*
842  
    auto operator()( T* t, I ) const -> tuple_element_t<I::value, T>*
795  
    {
843  
    {
796  
        using std::get;
844  
        using std::get;
797  
        return &get<I::value>(*t);
845  
        return &get<I::value>(*t);
798  
    }
846  
    }
799  
};
847  
};
800  

848  

801 -
template< class T, class P >
849 +
template<class T, class P, class Ctx>
802 -
class converting_handler<tuple_conversion_tag, T, P>
850 +
class converting_handler<tuple_conversion_tag, T, P, Ctx>
803  
{
851  
{
804  

852  

805  
private:
853  
private:
806  
    using ElementTypes = tuple_element_list<T>;
854  
    using ElementTypes = tuple_element_list<T>;
807 -

855 +
    using HandlerTuple = handler_tuple<converting_handler, Ctx, ElementTypes>;
808 -
    template<class V>
 
809 -
    using ElementHandler = get_handler<V, converting_handler>;
 
810 -
    using InnerHandlers = mp11::mp_transform<ElementHandler, ElementTypes>;
 
811 -
    using HandlerTuple = handler_tuple<converting_handler, InnerHandlers>;
 
812  

856  

813  
    T* value_;
857  
    T* value_;
814  
    P* parent_;
858  
    P* parent_;
815  

859  

816  
    HandlerTuple handlers_;
860  
    HandlerTuple handlers_;
817  
    int inner_active_ = -1;
861  
    int inner_active_ = -1;
818  

862  

819  
public:
863  
public:
820  
    converting_handler( converting_handler const& ) = delete;
864  
    converting_handler( converting_handler const& ) = delete;
821  
    converting_handler& operator=( converting_handler const& ) = delete;
865  
    converting_handler& operator=( converting_handler const& ) = delete;
822  

866  

823  
    converting_handler( T* v, P* p )
867  
    converting_handler( T* v, P* p )
824  
        : value_(v) , parent_(p) , handlers_(tuple_accessor(), v, this)
868  
        : value_(v) , parent_(p) , handlers_(tuple_accessor(), v, this)
825  
    {}
869  
    {}
826  

870  

827  
    bool signal_value(system::error_code&)
871  
    bool signal_value(system::error_code&)
828  
    {
872  
    {
829  
        ++inner_active_;
873  
        ++inner_active_;
830  
        return true;
874  
        return true;
831  
    }
875  
    }
832  

876  

833  
    bool signal_end(system::error_code& ec)
877  
    bool signal_end(system::error_code& ec)
834  
    {
878  
    {
835  
        constexpr int N = std::tuple_size<T>::value;
879  
        constexpr int N = std::tuple_size<T>::value;
836  
        if( inner_active_ < N )
880  
        if( inner_active_ < N )
837  
        {
881  
        {
838  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
882  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
839  
            return false;
883  
            return false;
840  
        }
884  
        }
841  

885  

 
886 +
        handlers_.finish();
842  
        inner_active_ = -1;
887  
        inner_active_ = -1;
843  
        return parent_->signal_value(ec);
888  
        return parent_->signal_value(ec);
844  
    }
889  
    }
845  

890  

846  
#define BOOST_JSON_HANDLE_EVENT(fn) \
891  
#define BOOST_JSON_HANDLE_EVENT(fn) \
847  
    struct do_ ## fn \
892  
    struct do_ ## fn \
848  
    { \
893  
    { \
849  
        template< class H, class... Args > \
894  
        template< class H, class... Args > \
850  
        bool operator()( H& h, Args& ... args ) const \
895  
        bool operator()( H& h, Args& ... args ) const \
851  
        { \
896  
        { \
852  
            return h. fn (args...); \
897  
            return h. fn (args...); \
853  
        } \
898  
        } \
854  
    }; \
899  
    }; \
855  
       \
900  
       \
856  
    template< class... Args > \
901  
    template< class... Args > \
857  
    bool fn( system::error_code& ec, Args&& ... args ) \
902  
    bool fn( system::error_code& ec, Args&& ... args ) \
858  
    { \
903  
    { \
859  
        if( inner_active_ < 0 ) \
904  
        if( inner_active_ < 0 ) \
860  
        { \
905  
        { \
861  
            BOOST_JSON_FAIL( ec, error::not_array ); \
906  
            BOOST_JSON_FAIL( ec, error::not_array ); \
862  
            return false; \
907  
            return false; \
863  
        } \
908  
        } \
864  
        constexpr int N = std::tuple_size<T>::value; \
909  
        constexpr int N = std::tuple_size<T>::value; \
865  
        if( inner_active_ >= N ) \
910  
        if( inner_active_ >= N ) \
866  
        { \
911  
        { \
867  
            BOOST_JSON_FAIL( ec, error::size_mismatch ); \
912  
            BOOST_JSON_FAIL( ec, error::size_mismatch ); \
868  
            return false; \
913  
            return false; \
869  
        } \
914  
        } \
870  
        using F = handler_op_invoker< do_ ## fn, system::error_code, Args...>; \
915  
        using F = handler_op_invoker< do_ ## fn, system::error_code, Args...>; \
871  
        using H = decltype(handlers_); \
916  
        using H = decltype(handlers_); \
872  
        return mp11::mp_with_index<N>( \
917  
        return mp11::mp_with_index<N>( \
873  
            inner_active_, \
918  
            inner_active_, \
874  
            tuple_handler_op_invoker<H, F>{ \
919  
            tuple_handler_op_invoker<H, F>{ \
875  
                handlers_, \
920  
                handlers_, \
876  
                F{ std::forward_as_tuple(ec, args...) } } ); \
921  
                F{ std::forward_as_tuple(ec, args...) } } ); \
877  
    }
922  
    }
878  

923  

879  
    BOOST_JSON_HANDLE_EVENT( on_object_begin )
924  
    BOOST_JSON_HANDLE_EVENT( on_object_begin )
880  
    BOOST_JSON_HANDLE_EVENT( on_object_end )
925  
    BOOST_JSON_HANDLE_EVENT( on_object_end )
881  

926  

882  
    struct do_on_array_begin
927  
    struct do_on_array_begin
883  
    {
928  
    {
884  
        HandlerTuple& handlers;
929  
        HandlerTuple& handlers;
885  
        system::error_code& ec;
930  
        system::error_code& ec;
886  

931  

887  
        template< class I >
932  
        template< class I >
888  
        bool operator()( I ) const
933  
        bool operator()( I ) const
889  
        {
934  
        {
890  
            return get<I::value>(handlers).on_array_begin(ec);
935  
            return get<I::value>(handlers).on_array_begin(ec);
891  
        }
936  
        }
892  
    };
937  
    };
893  
    bool on_array_begin( system::error_code& ec )
938  
    bool on_array_begin( system::error_code& ec )
894  
    {
939  
    {
895  
        if( inner_active_ < 0 )
940  
        if( inner_active_ < 0 )
896  
        {
941  
        {
897  
            inner_active_ = 0;
942  
            inner_active_ = 0;
898  
            return true;
943  
            return true;
899  
        }
944  
        }
900  

945  

901  
        constexpr int N = std::tuple_size<T>::value;
946  
        constexpr int N = std::tuple_size<T>::value;
902  

947  

903  
        if( inner_active_ >= N )
948  
        if( inner_active_ >= N )
904  
        {
949  
        {
905  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
950  
            BOOST_JSON_FAIL( ec, error::size_mismatch );
906  
            return false;
951  
            return false;
907  
        }
952  
        }
908  

953  

909  
        return mp11::mp_with_index<N>(
954  
        return mp11::mp_with_index<N>(
910  
            inner_active_, do_on_array_begin{handlers_, ec} );
955  
            inner_active_, do_on_array_begin{handlers_, ec} );
911  
    }
956  
    }
912  

957  

913  
    struct do_on_array_end
958  
    struct do_on_array_end
914  
    {
959  
    {
915  
        HandlerTuple& handlers;
960  
        HandlerTuple& handlers;
916  
        system::error_code& ec;
961  
        system::error_code& ec;
917  

962  

918  
        template< class I >
963  
        template< class I >
919  
        bool operator()( I ) const
964  
        bool operator()( I ) const
920  
        {
965  
        {
921  
            return get<I::value>(handlers).on_array_end(ec);
966  
            return get<I::value>(handlers).on_array_end(ec);
922  
        }
967  
        }
923  
    };
968  
    };
924  
    bool on_array_end( system::error_code& ec )
969  
    bool on_array_end( system::error_code& ec )
925  
    {
970  
    {
926  
        if( inner_active_ < 0 )
971  
        if( inner_active_ < 0 )
927  
            return parent_->signal_end(ec);
972  
            return parent_->signal_end(ec);
928  

973  

929  
        constexpr int N = std::tuple_size<T>::value;
974  
        constexpr int N = std::tuple_size<T>::value;
930  

975  

931  
        if( inner_active_ >= N )
976  
        if( inner_active_ >= N )
932  
            return signal_end(ec);
977  
            return signal_end(ec);
933  

978  

934  
        return mp11::mp_with_index<N>(
979  
        return mp11::mp_with_index<N>(
935  
            inner_active_, do_on_array_end{handlers_, ec} );
980  
            inner_active_, do_on_array_end{handlers_, ec} );
936  
    }
981  
    }
937  

982  

938  
    BOOST_JSON_HANDLE_EVENT( on_key_part )
983  
    BOOST_JSON_HANDLE_EVENT( on_key_part )
939  
    BOOST_JSON_HANDLE_EVENT( on_key )
984  
    BOOST_JSON_HANDLE_EVENT( on_key )
940  
    BOOST_JSON_HANDLE_EVENT( on_string_part )
985  
    BOOST_JSON_HANDLE_EVENT( on_string_part )
941  
    BOOST_JSON_HANDLE_EVENT( on_string )
986  
    BOOST_JSON_HANDLE_EVENT( on_string )
942  
    BOOST_JSON_HANDLE_EVENT( on_number_part )
987  
    BOOST_JSON_HANDLE_EVENT( on_number_part )
943  
    BOOST_JSON_HANDLE_EVENT( on_int64 )
988  
    BOOST_JSON_HANDLE_EVENT( on_int64 )
944  
    BOOST_JSON_HANDLE_EVENT( on_uint64 )
989  
    BOOST_JSON_HANDLE_EVENT( on_uint64 )
945  
    BOOST_JSON_HANDLE_EVENT( on_double )
990  
    BOOST_JSON_HANDLE_EVENT( on_double )
946  
    BOOST_JSON_HANDLE_EVENT( on_bool )
991  
    BOOST_JSON_HANDLE_EVENT( on_bool )
947  
    BOOST_JSON_HANDLE_EVENT( on_null )
992  
    BOOST_JSON_HANDLE_EVENT( on_null )
948  

993  

949  
#undef BOOST_JSON_HANDLE_EVENT
994  
#undef BOOST_JSON_HANDLE_EVENT
950  
};
995  
};
951  

996  

952  
// described struct handler
997  
// described struct handler
953  
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
998  
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
954  

999  

955  
template< class T >
1000  
template< class T >
956  
struct struct_element_list_impl
1001  
struct struct_element_list_impl
957  
{
1002  
{
958  
    template< class D >
1003  
    template< class D >
959  
    using helper = described_member_t<T, D>;
1004  
    using helper = described_member_t<T, D>;
960  

1005  

961  
    using type = mp11::mp_transform< helper, described_members<T> >;
1006  
    using type = mp11::mp_transform< helper, described_members<T> >;
962  
};
1007  
};
963  
template< class T >
1008  
template< class T >
964  
using struct_element_list = typename struct_element_list_impl<T>::type;
1009  
using struct_element_list = typename struct_element_list_impl<T>::type;
965  

1010  

966  
#else
1011  
#else
967  

1012  

968  
template< class T >
1013  
template< class T >
969  
using struct_element_list = mp11::mp_transform_q<
1014  
using struct_element_list = mp11::mp_transform_q<
970  
    mp11::mp_bind_front< described_member_t, T >, described_members<T> >;
1015  
    mp11::mp_bind_front< described_member_t, T >, described_members<T> >;
971  

1016  

972  
#endif
1017  
#endif
973  

1018  

974  
struct struct_accessor
1019  
struct struct_accessor
975  
{
1020  
{
976  
    template< class T >
1021  
    template< class T >
977  
    auto operator()( T*, mp11::mp_size< described_members<T> > ) const
1022  
    auto operator()( T*, mp11::mp_size< described_members<T> > ) const
978  
        -> void*
1023  
        -> void*
979  
    {
1024  
    {
980  
        return nullptr;
1025  
        return nullptr;
981  
    }
1026  
    }
982  

1027  

983  
    template< class T, class I >
1028  
    template< class T, class I >
984  
    auto operator()( T* t, I ) const
1029  
    auto operator()( T* t, I ) const
985  
        -> described_member_t<T, mp11::mp_at< described_members<T>, I> >*
1030  
        -> described_member_t<T, mp11::mp_at< described_members<T>, I> >*
986  
    {
1031  
    {
987  
        using Ds = described_members<T>;
1032  
        using Ds = described_members<T>;
988  
        using D = mp11::mp_at<Ds, I>;
1033  
        using D = mp11::mp_at<Ds, I>;
989  
        return &(t->*D::pointer);
1034  
        return &(t->*D::pointer);
990  
    }
1035  
    }
991  
};
1036  
};
992  

1037  

993  
struct struct_key_searcher
1038  
struct struct_key_searcher
994  
{
1039  
{
995  
    string_view key;
1040  
    string_view key;
996  
    int& found;
1041  
    int& found;
997  
    int index = 0;
1042  
    int index = 0;
998  

1043  

999  
    struct_key_searcher(string_view key, int& found) noexcept
1044  
    struct_key_searcher(string_view key, int& found) noexcept
1000  
        : key(key), found(found)
1045  
        : key(key), found(found)
1001  
    {}
1046  
    {}
1002  

1047  

1003  
    template< class D >
1048  
    template< class D >
1004  
    void
1049  
    void
1005  
    operator()( D )
1050  
    operator()( D )
1006  
    {
1051  
    {
1007  
        if( key == D::name )
1052  
        if( key == D::name )
1008  
            found = index;
1053  
            found = index;
1009  
        ++index;
1054  
        ++index;
1010  
    }
1055  
    }
1011  
};
1056  
};
1012  

1057  

1013  
template<class P>
1058  
template<class P>
1014  
struct ignoring_handler
1059  
struct ignoring_handler
1015  
{
1060  
{
1016  
    P* parent_;
1061  
    P* parent_;
1017  
    std::size_t array_depth_ = 0;
1062  
    std::size_t array_depth_ = 0;
1018  
    std::size_t object_depth_ = 0;
1063  
    std::size_t object_depth_ = 0;
1019  

1064  

1020  
    ignoring_handler(ignoring_handler const&) = delete;
1065  
    ignoring_handler(ignoring_handler const&) = delete;
1021  
    ignoring_handler& operator=(ignoring_handler const&) = delete;
1066  
    ignoring_handler& operator=(ignoring_handler const&) = delete;
1022  

1067  

1023 -
    ignoring_handler(void*, P* p) noexcept
1068 +
    ignoring_handler(P* p) noexcept
1024  
        : parent_(p)
1069  
        : parent_(p)
1025  
    {}
1070  
    {}
1026  

1071  

1027  
    bool on_object_begin(system::error_code&)
1072  
    bool on_object_begin(system::error_code&)
1028  
    {
1073  
    {
1029  
        ++object_depth_;
1074  
        ++object_depth_;
1030  
        return true;
1075  
        return true;
1031  
    }
1076  
    }
1032  

1077  

1033  
    bool on_object_end(system::error_code& ec)
1078  
    bool on_object_end(system::error_code& ec)
1034  
    {
1079  
    {
1035  
        BOOST_ASSERT( object_depth_ > 0 );
1080  
        BOOST_ASSERT( object_depth_ > 0 );
1036  
        --object_depth_;
1081  
        --object_depth_;
1037  

1082  

1038  
        if( (array_depth_ + object_depth_) == 0 )
1083  
        if( (array_depth_ + object_depth_) == 0 )
1039  
            return parent_->signal_value(ec);
1084  
            return parent_->signal_value(ec);
1040  
        return true;
1085  
        return true;
1041  
    }
1086  
    }
1042  

1087  

1043  
    bool on_array_begin(system::error_code&)
1088  
    bool on_array_begin(system::error_code&)
1044  
    {
1089  
    {
1045  
        ++array_depth_;
1090  
        ++array_depth_;
1046  
        return true;
1091  
        return true;
1047  
    }
1092  
    }
1048  

1093  

1049  
    bool on_array_end(system::error_code& ec)
1094  
    bool on_array_end(system::error_code& ec)
1050  
    {
1095  
    {
1051  
        BOOST_ASSERT( array_depth_ > 0 );
1096  
        BOOST_ASSERT( array_depth_ > 0 );
1052  
        --array_depth_;
1097  
        --array_depth_;
1053  

1098  

1054  
        if( (array_depth_ + object_depth_) == 0 )
1099  
        if( (array_depth_ + object_depth_) == 0 )
1055 -
            return parent_->signal_value(ec);
1100 +
            return parent_->signal_end(ec);
1056  
        return true;
1101  
        return true;
1057  
    }
1102  
    }
1058  

1103  

1059  
    bool on_key_part(system::error_code&, string_view)
1104  
    bool on_key_part(system::error_code&, string_view)
1060  
    {
1105  
    {
1061  
        return true;
1106  
        return true;
1062  
    }
1107  
    }
1063  

1108  

1064  
    bool on_key(system::error_code&, string_view)
1109  
    bool on_key(system::error_code&, string_view)
1065  
    {
1110  
    {
1066  
        return true;
1111  
        return true;
1067  
    }
1112  
    }
1068  

1113  

1069  
    bool on_string_part(system::error_code&, string_view)
1114  
    bool on_string_part(system::error_code&, string_view)
1070  
    {
1115  
    {
1071  
        return true;
1116  
        return true;
1072  
    }
1117  
    }
1073  

1118  

1074  
    bool on_string(system::error_code& ec, string_view)
1119  
    bool on_string(system::error_code& ec, string_view)
1075  
    {
1120  
    {
1076  
        if( (array_depth_ + object_depth_) == 0 )
1121  
        if( (array_depth_ + object_depth_) == 0 )
1077  
            return parent_->signal_value(ec);
1122  
            return parent_->signal_value(ec);
1078  
        return true;
1123  
        return true;
1079  
    }
1124  
    }
1080  

1125  

1081  
    bool on_number_part(system::error_code&)
1126  
    bool on_number_part(system::error_code&)
1082  
    {
1127  
    {
1083  
        return true;
1128  
        return true;
1084  
    }
1129  
    }
1085  

1130  

1086  
    bool on_int64(system::error_code& ec, std::int64_t)
1131  
    bool on_int64(system::error_code& ec, std::int64_t)
1087  
    {
1132  
    {
1088  
        if( (array_depth_ + object_depth_) == 0 )
1133  
        if( (array_depth_ + object_depth_) == 0 )
1089  
            return parent_->signal_value(ec);
1134  
            return parent_->signal_value(ec);
1090  
        return true;
1135  
        return true;
1091  
    }
1136  
    }
1092  

1137  

1093  
    bool on_uint64(system::error_code& ec, std::uint64_t)
1138  
    bool on_uint64(system::error_code& ec, std::uint64_t)
1094  
    {
1139  
    {
1095  
        if( (array_depth_ + object_depth_) == 0 )
1140  
        if( (array_depth_ + object_depth_) == 0 )
1096  
            return parent_->signal_value(ec);
1141  
            return parent_->signal_value(ec);
1097  
        return true;
1142  
        return true;
1098  
    }
1143  
    }
1099  

1144  

1100  
    bool on_double(system::error_code& ec, double)
1145  
    bool on_double(system::error_code& ec, double)
1101  
    {
1146  
    {
1102  
        if( (array_depth_ + object_depth_) == 0 )
1147  
        if( (array_depth_ + object_depth_) == 0 )
1103  
            return parent_->signal_value(ec);
1148  
            return parent_->signal_value(ec);
1104  
        return true;
1149  
        return true;
1105  
    }
1150  
    }
1106  

1151  

1107  
    bool on_bool(system::error_code& ec, bool)
1152  
    bool on_bool(system::error_code& ec, bool)
1108  
    {
1153  
    {
1109  
        if( (array_depth_ + object_depth_) == 0 )
1154  
        if( (array_depth_ + object_depth_) == 0 )
1110  
            return parent_->signal_value(ec);
1155  
            return parent_->signal_value(ec);
1111  
        return true;
1156  
        return true;
1112  
    }
1157  
    }
1113  

1158  

1114  
    bool on_null(system::error_code& ec)
1159  
    bool on_null(system::error_code& ec)
1115  
    {
1160  
    {
1116  
        if( (array_depth_ + object_depth_) == 0 )
1161  
        if( (array_depth_ + object_depth_) == 0 )
1117  
            return parent_->signal_value(ec);
1162  
            return parent_->signal_value(ec);
1118  
        return true;
1163  
        return true;
1119  
    }
1164  
    }
1120  
};
1165  
};
1121  

1166  

1122 -
template<class V, class P>
1167 +
template<class V, class P, class Ctx>
1123 -
class converting_handler<described_class_conversion_tag, V, P>
1168 +
class converting_handler<described_class_conversion_tag, V, P, Ctx>
1124  
{
1169  
{
1125  
#if !defined(BOOST_DESCRIBE_CXX14)
1170  
#if !defined(BOOST_DESCRIBE_CXX14)
1126  

1171  

1127  
    static_assert(
1172  
    static_assert(
1128  
        sizeof(V) == 0, "Struct support for parse_into requires C++14" );
1173  
        sizeof(V) == 0, "Struct support for parse_into requires C++14" );
1129  

1174  

1130  
#else
1175  
#else
1131  

1176  

1132 -
    static_assert(
 
1133 -
        uniquely_named_members<V>::value,
 
1134 -
        "The type has several described members with the same name.");
 
1135 -

 
1136  
private:
1177  
private:
1137  
    using Dm = described_members<V>;
1178  
    using Dm = described_members<V>;
1138  
    using Dt = struct_element_list<V>;
1179  
    using Dt = struct_element_list<V>;
 
1180 +
    using InnerCount = mp11::mp_size<Dt>;
1139  

1181  

1140 -
    template<class T>
1182 +
    handler_tuple<converting_handler, Ctx, Dt> handlers_;
1141 -
    using MemberHandler = get_handler<T, converting_handler>;
1183 +
    ignoring_handler<converting_handler> ignorer_;
1142 -
    using InnerHandlers = mp11::mp_push_back<
1184 +
    std::string key_;
1143 -
        mp11::mp_transform<MemberHandler, Dt>,
 
1144 -
        ignoring_handler<converting_handler> >;
 
1145 -
    using InnerCount = mp11::mp_size<InnerHandlers>;
 
1146 -

 
1147  
    V* value_;
1185  
    V* value_;
1148 -

 
1149 -
    std::string key_;
 
1150 -

 
1151 -
    handler_tuple<converting_handler, InnerHandlers> handlers_;
 
1152  
    P* parent_;
1186  
    P* parent_;
1153  
    int inner_active_ = -1;
1187  
    int inner_active_ = -1;
1154  
    std::size_t activated_ = 0;
1188  
    std::size_t activated_ = 0;
1155  

1189  

1156  
public:
1190  
public:
1157  
    converting_handler( converting_handler const& ) = delete;
1191  
    converting_handler( converting_handler const& ) = delete;
1158  
    converting_handler& operator=( converting_handler const& ) = delete;
1192  
    converting_handler& operator=( converting_handler const& ) = delete;
1159  

1193  

1160  
    converting_handler( V* v, P* p )
1194  
    converting_handler( V* v, P* p )
1161 -
        : value_(v), parent_(p), handlers_(struct_accessor(), v, this)
1195 +
        : handlers_(struct_accessor(), v, this)
 
1196 +
        , ignorer_(this)
 
1197 +
        , value_(v)
 
1198 +
        , parent_(p)
1162  
    {}
1199  
    {}
1163  

1200  

1164  
    struct is_required_checker
1201  
    struct is_required_checker
1165 -
        bool operator()( mp11::mp_size<Dt> ) const noexcept
 
1166 -
        {
 
1167 -
            return false;
 
1168 -
        }
 
1169 -

 
1170  
    {
1202  
    {
1171  
        template< class I >
1203  
        template< class I >
1172  
        auto operator()( I ) const noexcept
1204  
        auto operator()( I ) const noexcept
1173  
        {
1205  
        {
1174  
            using T = mp11::mp_at<Dt, I>;
1206  
            using T = mp11::mp_at<Dt, I>;
1175  
            return !is_optional_like<T>::value;
1207  
            return !is_optional_like<T>::value;
1176  
        }
1208  
        }
1177 -

 
1178  
    };
1209  
    };
1179  
    bool signal_value(system::error_code&)
1210  
    bool signal_value(system::error_code&)
1180  
    {
1211  
    {
1181  
        BOOST_ASSERT( inner_active_ >= 0 );
1212  
        BOOST_ASSERT( inner_active_ >= 0 );
1182 -
        bool required_member = mp11::mp_with_index<InnerCount>(
1213 +
        if( static_cast<std::size_t>(inner_active_) < InnerCount::value )
1183 -
            inner_active_,
1214 +
        {
1184 -
            is_required_checker{});
1215 +
            bool required_member = mp11::mp_with_index<InnerCount>(
1185 -
        if( required_member )
1216 +
                inner_active_,
1186 -
            ++activated_;
1217 +
                is_required_checker{});
 
1218 +
            if( required_member )
 
1219 +
                ++activated_;
 
1220 +
        }
1187  

1221  

1188  
        key_ = {};
1222  
        key_ = {};
1189  
        inner_active_ = -1;
1223  
        inner_active_ = -1;
1190  
        return true;
1224  
        return true;
1191  
    }
1225  
    }
1192  

1226  

1193  
    bool signal_end(system::error_code& ec)
1227  
    bool signal_end(system::error_code& ec)
1194  
    {
1228  
    {
1195  
        key_ = {};
1229  
        key_ = {};
1196  
        inner_active_ = -1;
1230  
        inner_active_ = -1;
1197  
        return parent_->signal_value(ec);
1231  
        return parent_->signal_value(ec);
1198  
    }
1232  
    }
1199  

1233  

1200  
#define BOOST_JSON_INVOKE_INNER(fn) \
1234  
#define BOOST_JSON_INVOKE_INNER(fn) \
1201  
    if( inner_active_ < 0 ) \
1235  
    if( inner_active_ < 0 ) \
1202  
    { \
1236  
    { \
1203  
        BOOST_JSON_FAIL( ec, error::not_object ); \
1237  
        BOOST_JSON_FAIL( ec, error::not_object ); \
1204  
        return false; \
1238  
        return false; \
1205  
    } \
1239  
    } \
 
1240 +
    if(inner_active_ == InnerCount::value) \
 
1241 +
        return ignorer_.fn; \
1206  
    auto f = [&](auto& handler) { return handler.fn ; }; \
1242  
    auto f = [&](auto& handler) { return handler.fn ; }; \
1207  
    using F = decltype(f); \
1243  
    using F = decltype(f); \
1208  
    using H = decltype(handlers_); \
1244  
    using H = decltype(handlers_); \
1209  
    return mp11::mp_with_index<InnerCount>( \
1245  
    return mp11::mp_with_index<InnerCount>( \
1210  
            inner_active_, \
1246  
            inner_active_, \
1211  
            tuple_handler_op_invoker<H, F>{handlers_, f} );
1247  
            tuple_handler_op_invoker<H, F>{handlers_, f} );
1212  

1248  

1213  
    bool on_object_begin( system::error_code& ec )
1249  
    bool on_object_begin( system::error_code& ec )
1214  
    {
1250  
    {
1215  
        if( inner_active_ < 0 )
1251  
        if( inner_active_ < 0 )
1216  
            return true;
1252  
            return true;
1217  

1253  

1218  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
1254  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
1219  
    }
1255  
    }
1220  

1256  

1221  
    bool on_object_end( system::error_code& ec )
1257  
    bool on_object_end( system::error_code& ec )
1222  
    {
1258  
    {
1223  
        if( inner_active_ < 0 )
1259  
        if( inner_active_ < 0 )
1224  
        {
1260  
        {
1225  
            using C = mp11::mp_count_if<Dt, is_optional_like>;
1261  
            using C = mp11::mp_count_if<Dt, is_optional_like>;
1226  
            constexpr int N = mp11::mp_size<Dt>::value - C::value;
1262  
            constexpr int N = mp11::mp_size<Dt>::value - C::value;
1227  
            if( activated_ < N )
1263  
            if( activated_ < N )
1228  
            {
1264  
            {
1229  
                BOOST_JSON_FAIL( ec, error::size_mismatch );
1265  
                BOOST_JSON_FAIL( ec, error::size_mismatch );
1230  
                return false;
1266  
                return false;
1231  
            }
1267  
            }
1232  

1268  

 
1269 +
            handlers_.finish();
1233  
            return parent_->signal_value(ec);
1270  
            return parent_->signal_value(ec);
1234  
        }
1271  
        }
1235  

1272  

1236  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
1273  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
1237  
    }
1274  
    }
1238  

1275  

1239  
    bool on_array_begin( system::error_code& ec )
1276  
    bool on_array_begin( system::error_code& ec )
1240  
    {
1277  
    {
1241  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
1278  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
1242  
    }
1279  
    }
1243  

1280  

1244  
    bool on_array_end( system::error_code& ec )
1281  
    bool on_array_end( system::error_code& ec )
1245  
    {
1282  
    {
1246  
        if( inner_active_ < 0 )
1283  
        if( inner_active_ < 0 )
1247  
            return parent_->signal_end(ec);
1284  
            return parent_->signal_end(ec);
1248  

1285  

1249  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
1286  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
1250  
    }
1287  
    }
1251  

1288  

1252  
    bool on_key_part( system::error_code& ec, string_view sv )
1289  
    bool on_key_part( system::error_code& ec, string_view sv )
1253  
    {
1290  
    {
1254  
        if( inner_active_ < 0 )
1291  
        if( inner_active_ < 0 )
1255  
        {
1292  
        {
1256  
            key_.append( sv.data(), sv.size() );
1293  
            key_.append( sv.data(), sv.size() );
1257  
            return true;
1294  
            return true;
1258  
        }
1295  
        }
1259  

1296  

1260  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
1297  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
1261  
    }
1298  
    }
1262  

1299  

1263  
    bool on_key( system::error_code& ec, string_view sv )
1300  
    bool on_key( system::error_code& ec, string_view sv )
1264  
    {
1301  
    {
1265  
        if( inner_active_ >= 0 )
1302  
        if( inner_active_ >= 0 )
1266  
        {
1303  
        {
1267  
            BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
1304  
            BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
1268  
        }
1305  
        }
1269  

1306  

1270  
        string_view key = sv;
1307  
        string_view key = sv;
1271  
        if( !key_.empty() )
1308  
        if( !key_.empty() )
1272  
        {
1309  
        {
1273  
            key_.append( sv.data(), sv.size() );
1310  
            key_.append( sv.data(), sv.size() );
1274  
            key = key_;
1311  
            key = key_;
1275  
        }
1312  
        }
1276  

1313  

1277 -
        inner_active_ = InnerCount::value - 1;
1314 +
        inner_active_ = InnerCount::value;
1278  
        mp11::mp_for_each<Dm>( struct_key_searcher(key, inner_active_) );
1315  
        mp11::mp_for_each<Dm>( struct_key_searcher(key, inner_active_) );
1279  
        return true;
1316  
        return true;
1280  
    }
1317  
    }
1281  

1318  

1282  
    bool on_string_part( system::error_code& ec, string_view sv )
1319  
    bool on_string_part( system::error_code& ec, string_view sv )
1283  
    {
1320  
    {
1284  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
1321  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
1285  
    }
1322  
    }
1286  

1323  

1287  
    bool on_string( system::error_code& ec, string_view sv )
1324  
    bool on_string( system::error_code& ec, string_view sv )
1288  
    {
1325  
    {
1289  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
1326  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
1290  
    }
1327  
    }
1291  

1328  

1292  
    bool on_number_part( system::error_code& ec )
1329  
    bool on_number_part( system::error_code& ec )
1293  
    {
1330  
    {
1294  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
1331  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
1295  
    }
1332  
    }
1296  

1333  

1297  
    bool on_int64( system::error_code& ec, std::int64_t v )
1334  
    bool on_int64( system::error_code& ec, std::int64_t v )
1298  
    {
1335  
    {
1299  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
1336  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
1300  
    }
1337  
    }
1301  

1338  

1302  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
1339  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
1303  
    {
1340  
    {
1304  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
1341  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
1305  
    }
1342  
    }
1306  

1343  

1307  
    bool on_double( system::error_code& ec, double v )
1344  
    bool on_double( system::error_code& ec, double v )
1308  
    {
1345  
    {
1309  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
1346  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
1310  
    }
1347  
    }
1311  

1348  

1312  
    bool on_bool( system::error_code& ec, bool v )
1349  
    bool on_bool( system::error_code& ec, bool v )
1313  
    {
1350  
    {
1314  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
1351  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
1315  
    }
1352  
    }
1316  

1353  

1317  
    bool on_null( system::error_code& ec )
1354  
    bool on_null( system::error_code& ec )
1318  
    {
1355  
    {
1319  
        BOOST_JSON_INVOKE_INNER( on_null(ec) );
1356  
        BOOST_JSON_INVOKE_INNER( on_null(ec) );
1320  
    }
1357  
    }
1321  

1358  

1322  
#undef BOOST_JSON_INVOKE_INNER
1359  
#undef BOOST_JSON_INVOKE_INNER
1323  

1360  

1324  
#endif
1361  
#endif
1325  
};
1362  
};
1326  

1363  

1327  
// variant handler
1364  
// variant handler
1328  
struct object_begin_handler_event
1365  
struct object_begin_handler_event
1329  
{ };
1366  
{ };
1330  

1367  

1331  
struct object_end_handler_event
1368  
struct object_end_handler_event
1332  
{ };
1369  
{ };
1333  

1370  

1334  
struct array_begin_handler_event
1371  
struct array_begin_handler_event
1335  
{ };
1372  
{ };
1336  

1373  

1337  
struct array_end_handler_event
1374  
struct array_end_handler_event
1338  
{ };
1375  
{ };
1339  

1376  

1340  
struct key_handler_event
1377  
struct key_handler_event
1341  
{
1378  
{
1342  
    std::string value;
1379  
    std::string value;
1343  
};
1380  
};
1344  

1381  

1345  
struct string_handler_event
1382  
struct string_handler_event
1346  
{
1383  
{
1347  
    std::string value;
1384  
    std::string value;
1348  
};
1385  
};
1349  

1386  

1350  
struct int64_handler_event
1387  
struct int64_handler_event
1351  
{
1388  
{
1352  
    std::int64_t value;
1389  
    std::int64_t value;
1353  
};
1390  
};
1354  

1391  

1355  
struct uint64_handler_event
1392  
struct uint64_handler_event
1356  
{
1393  
{
1357  
    std::uint64_t value;
1394  
    std::uint64_t value;
1358  
};
1395  
};
1359  

1396  

1360  
struct double_handler_event
1397  
struct double_handler_event
1361  
{
1398  
{
1362  
    double value;
1399  
    double value;
1363  
};
1400  
};
1364  

1401  

1365  
struct bool_handler_event
1402  
struct bool_handler_event
1366  
{
1403  
{
1367  
    bool value;
1404  
    bool value;
1368  
};
1405  
};
1369  

1406  

1370  
struct null_handler_event
1407  
struct null_handler_event
1371  
{ };
1408  
{ };
1372  

1409  

1373  
using parse_event = variant2::variant<
1410  
using parse_event = variant2::variant<
1374  
    object_begin_handler_event,
1411  
    object_begin_handler_event,
1375  
    object_end_handler_event,
1412  
    object_end_handler_event,
1376  
    array_begin_handler_event,
1413  
    array_begin_handler_event,
1377  
    array_end_handler_event,
1414  
    array_end_handler_event,
1378  
    key_handler_event,
1415  
    key_handler_event,
1379  
    string_handler_event,
1416  
    string_handler_event,
1380  
    int64_handler_event,
1417  
    int64_handler_event,
1381  
    uint64_handler_event,
1418  
    uint64_handler_event,
1382  
    double_handler_event,
1419  
    double_handler_event,
1383  
    bool_handler_event,
1420  
    bool_handler_event,
1384  
    null_handler_event>;
1421  
    null_handler_event>;
1385  

1422  

1386  
template< class H >
1423  
template< class H >
1387  
struct event_visitor
1424  
struct event_visitor
1388  
{
1425  
{
1389  
    H& handler;
1426  
    H& handler;
1390  
    system::error_code& ec;
1427  
    system::error_code& ec;
1391  

1428  

1392  
    bool
1429  
    bool
1393  
    operator()(object_begin_handler_event&) const
1430  
    operator()(object_begin_handler_event&) const
1394  
    {
1431  
    {
1395  
        return handler.on_object_begin(ec);
1432  
        return handler.on_object_begin(ec);
1396  
    }
1433  
    }
1397  

1434  

1398  
    bool
1435  
    bool
1399  
    operator()(object_end_handler_event&) const
1436  
    operator()(object_end_handler_event&) const
1400  
    {
1437  
    {
1401  
        return handler.on_object_end(ec);
1438  
        return handler.on_object_end(ec);
1402  
    }
1439  
    }
1403  

1440  

1404  
    bool
1441  
    bool
1405  
    operator()(array_begin_handler_event&) const
1442  
    operator()(array_begin_handler_event&) const
1406  
    {
1443  
    {
1407  
        return handler.on_array_begin(ec);
1444  
        return handler.on_array_begin(ec);
1408  
    }
1445  
    }
1409  

1446  

1410  
    bool
1447  
    bool
1411  
    operator()(array_end_handler_event&) const
1448  
    operator()(array_end_handler_event&) const
1412  
    {
1449  
    {
1413  
        return handler.on_array_end(ec);
1450  
        return handler.on_array_end(ec);
1414  
    }
1451  
    }
1415  

1452  

1416  
    bool
1453  
    bool
1417  
    operator()(key_handler_event& ev) const
1454  
    operator()(key_handler_event& ev) const
1418  
    {
1455  
    {
1419  
        return handler.on_key(ec, ev.value);
1456  
        return handler.on_key(ec, ev.value);
1420  
    }
1457  
    }
1421  

1458  

1422  
    bool
1459  
    bool
1423  
    operator()(string_handler_event& ev) const
1460  
    operator()(string_handler_event& ev) const
1424  
    {
1461  
    {
1425  
        return handler.on_string(ec, ev.value);
1462  
        return handler.on_string(ec, ev.value);
1426  
    }
1463  
    }
1427  

1464  

1428  
    bool
1465  
    bool
1429  
    operator()(int64_handler_event& ev) const
1466  
    operator()(int64_handler_event& ev) const
1430  
    {
1467  
    {
1431  
        return handler.on_int64(ec, ev.value);
1468  
        return handler.on_int64(ec, ev.value);
1432  
    }
1469  
    }
1433  

1470  

1434  
    bool
1471  
    bool
1435  
    operator()(uint64_handler_event& ev) const
1472  
    operator()(uint64_handler_event& ev) const
1436  
    {
1473  
    {
1437  
        return handler.on_uint64(ec, ev.value);
1474  
        return handler.on_uint64(ec, ev.value);
1438  
    }
1475  
    }
1439  

1476  

1440  
    bool
1477  
    bool
1441  
    operator()(double_handler_event& ev) const
1478  
    operator()(double_handler_event& ev) const
1442  
    {
1479  
    {
1443  
        return handler.on_double(ec, ev.value);
1480  
        return handler.on_double(ec, ev.value);
1444  
    }
1481  
    }
1445  

1482  

1446  
    bool
1483  
    bool
1447  
    operator()(bool_handler_event& ev) const
1484  
    operator()(bool_handler_event& ev) const
1448  
    {
1485  
    {
1449  
        return handler.on_bool(ec, ev.value);
1486  
        return handler.on_bool(ec, ev.value);
1450  
    }
1487  
    }
1451  

1488  

1452  
    bool
1489  
    bool
1453  
    operator()(null_handler_event&) const
1490  
    operator()(null_handler_event&) const
1454  
    {
1491  
    {
1455  
        return handler.on_null(ec);
1492  
        return handler.on_null(ec);
1456  
    }
1493  
    }
1457  
};
1494  
};
1458  

1495  

1459 -
// L<T...> -> variant< monostate, get_handler<T, P>... >
1496 +
// L<T...> -> variant< monostate, get_handler<T, P, Ctx>... >
1460 -
template< class P, class L >
1497 +
template<class P, class L, class Ctx>
1461  
using inner_handler_variant = mp11::mp_push_front<
1498  
using inner_handler_variant = mp11::mp_push_front<
1462  
    mp11::mp_transform_q<
1499  
    mp11::mp_transform_q<
1463 -
        mp11::mp_bind_back<get_handler, P>,
1500 +
        mp11::mp_bind_back<get_handler, P, Ctx>,
1464  
        mp11::mp_apply<variant2::variant, L>>,
1501  
        mp11::mp_apply<variant2::variant, L>>,
1465  
    variant2::monostate>;
1502  
    variant2::monostate>;
1466  

1503  

1467 -
template< class T, class P >
1504 +
template<class T, class P, class Ctx>
1468 -
class converting_handler<variant_conversion_tag, T, P>
1505 +
class converting_handler<variant_conversion_tag, T, P, Ctx>
1469  
{
1506  
{
1470  
private:
1507  
private:
1471  
    using variant_size = mp11::mp_size<T>;
1508  
    using variant_size = mp11::mp_size<T>;
1472  

1509  

1473  
    T* value_;
1510  
    T* value_;
1474  
    P* parent_;
1511  
    P* parent_;
1475  

1512  

1476  
    std::string string_;
1513  
    std::string string_;
1477  
    std::vector< parse_event > events_;
1514  
    std::vector< parse_event > events_;
1478 -
    inner_handler_variant<converting_handler, T> inner_;
1515 +
    inner_handler_variant<converting_handler, T, Ctx> inner_;
1479  
    int inner_active_ = -1;
1516  
    int inner_active_ = -1;
1480  

1517  

1481  
public:
1518  
public:
1482  
    converting_handler( converting_handler const& ) = delete;
1519  
    converting_handler( converting_handler const& ) = delete;
1483  
    converting_handler& operator=( converting_handler const& ) = delete;
1520  
    converting_handler& operator=( converting_handler const& ) = delete;
1484  

1521  

1485  
    converting_handler( T* v, P* p )
1522  
    converting_handler( T* v, P* p )
1486  
        : value_( v )
1523  
        : value_( v )
1487  
        , parent_( p )
1524  
        , parent_( p )
1488  
    {}
1525  
    {}
1489  

1526  

1490  
    bool signal_value(system::error_code& ec)
1527  
    bool signal_value(system::error_code& ec)
1491  
    {
1528  
    {
1492  
        inner_.template emplace<0>();
1529  
        inner_.template emplace<0>();
1493  
        inner_active_ = -1;
1530  
        inner_active_ = -1;
1494  
        events_.clear();
1531  
        events_.clear();
1495  
        return parent_->signal_value(ec);
1532  
        return parent_->signal_value(ec);
1496  
    }
1533  
    }
1497  

1534  

1498  
    bool signal_end(system::error_code& ec)
1535  
    bool signal_end(system::error_code& ec)
1499  
    {
1536  
    {
1500  
        return parent_->signal_end(ec);
1537  
        return parent_->signal_end(ec);
1501  
    }
1538  
    }
1502  

1539  

1503  
    struct alternative_selector
1540  
    struct alternative_selector
1504  
    {
1541  
    {
1505  
        converting_handler* self;
1542  
        converting_handler* self;
1506  

1543  

1507  
        template< class I >
1544  
        template< class I >
1508  
        void
1545  
        void
1509  
        operator()( I ) const
1546  
        operator()( I ) const
1510  
        {
1547  
        {
1511  
            using V = mp11::mp_at<T, I>;
1548  
            using V = mp11::mp_at<T, I>;
1512  
            auto& v = self->value_->template emplace<I::value>( V{} );
1549  
            auto& v = self->value_->template emplace<I::value>( V{} );
1513  
            self->inner_.template emplace<I::value + 1>(&v, self);
1550  
            self->inner_.template emplace<I::value + 1>(&v, self);
1514  
        }
1551  
        }
1515  
    };
1552  
    };
1516  
    void
1553  
    void
1517  
    next_alternative()
1554  
    next_alternative()
1518  
    {
1555  
    {
1519  
        if( ++inner_active_ >= static_cast<int>(variant_size::value) )
1556  
        if( ++inner_active_ >= static_cast<int>(variant_size::value) )
1520  
            return;
1557  
            return;
1521  

1558  

1522  
        mp11::mp_with_index< variant_size::value >(
1559  
        mp11::mp_with_index< variant_size::value >(
1523  
            inner_active_, alternative_selector{this} );
1560  
            inner_active_, alternative_selector{this} );
1524  
    }
1561  
    }
1525  

1562  

1526  
    struct event_processor
1563  
    struct event_processor
1527  
    {
1564  
    {
1528  
        converting_handler* self;
1565  
        converting_handler* self;
1529  
        system::error_code& ec;
1566  
        system::error_code& ec;
1530  
        parse_event& event;
1567  
        parse_event& event;
1531  

1568  

1532  
        template< class I >
1569  
        template< class I >
1533  
        bool operator()( I ) const
1570  
        bool operator()( I ) const
1534  
        {
1571  
        {
1535  
            auto& handler = variant2::get<I::value + 1>(self->inner_);
1572  
            auto& handler = variant2::get<I::value + 1>(self->inner_);
1536  
            using Handler = remove_cvref<decltype(handler)>;
1573  
            using Handler = remove_cvref<decltype(handler)>;
1537  
            return variant2::visit(
1574  
            return variant2::visit(
1538  
                event_visitor<Handler>{handler, ec}, event );
1575  
                event_visitor<Handler>{handler, ec}, event );
1539  
        }
1576  
        }
1540  
    };
1577  
    };
1541  
    bool process_events(system::error_code& ec)
1578  
    bool process_events(system::error_code& ec)
1542  
    {
1579  
    {
1543  
        constexpr std::size_t N = variant_size::value;
1580  
        constexpr std::size_t N = variant_size::value;
1544  

1581  

1545  
        // should be pointers not iterators, otherwise MSVC crashes
1582  
        // should be pointers not iterators, otherwise MSVC crashes
1546  
        auto const last = events_.data() + events_.size();
1583  
        auto const last = events_.data() + events_.size();
1547  
        auto first = last - 1;
1584  
        auto first = last - 1;
1548  
        bool ok = false;
1585  
        bool ok = false;
1549  

1586  

1550  
        if( inner_active_ < 0 )
1587  
        if( inner_active_ < 0 )
1551  
            next_alternative();
1588  
            next_alternative();
1552  
        do
1589  
        do
1553  
        {
1590  
        {
1554  
            if( static_cast<std::size_t>(inner_active_) >= N )
1591  
            if( static_cast<std::size_t>(inner_active_) >= N )
1555  
            {
1592  
            {
1556  
                BOOST_JSON_FAIL( ec, error::exhausted_variants );
1593  
                BOOST_JSON_FAIL( ec, error::exhausted_variants );
1557  
                return false;
1594  
                return false;
1558  
            }
1595  
            }
1559  

1596  

1560  
            for ( ; first != last; ++first )
1597  
            for ( ; first != last; ++first )
1561  
            {
1598  
            {
1562  
                ok = mp11::mp_with_index< N >(
1599  
                ok = mp11::mp_with_index< N >(
1563  
                    inner_active_, event_processor{this, ec, *first} );
1600  
                    inner_active_, event_processor{this, ec, *first} );
1564  
                if( !ok )
1601  
                if( !ok )
1565  
                {
1602  
                {
1566  
                    first = events_.data();
1603  
                    first = events_.data();
1567  
                    next_alternative();
1604  
                    next_alternative();
1568  
                    ec.clear();
1605  
                    ec.clear();
1569  
                    break;
1606  
                    break;
1570  
                }
1607  
                }
1571  
            }
1608  
            }
1572  
        }
1609  
        }
1573  
        while( !ok );
1610  
        while( !ok );
1574  

1611  

1575  
        return true;
1612  
        return true;
1576  
    }
1613  
    }
1577  

1614  

1578  
#define BOOST_JSON_INVOKE_INNER(ev, ec) \
1615  
#define BOOST_JSON_INVOKE_INNER(ev, ec) \
1579  
    events_.emplace_back( ev ); \
1616  
    events_.emplace_back( ev ); \
1580  
    return process_events(ec);
1617  
    return process_events(ec);
1581  

1618  

1582  
    bool on_object_begin( system::error_code& ec )
1619  
    bool on_object_begin( system::error_code& ec )
1583  
    {
1620  
    {
1584  
        BOOST_JSON_INVOKE_INNER( object_begin_handler_event{}, ec );
1621  
        BOOST_JSON_INVOKE_INNER( object_begin_handler_event{}, ec );
1585  
    }
1622  
    }
1586  

1623  

1587  
    bool on_object_end( system::error_code& ec )
1624  
    bool on_object_end( system::error_code& ec )
1588  
    {
1625  
    {
1589  
        BOOST_JSON_INVOKE_INNER( object_end_handler_event{}, ec );
1626  
        BOOST_JSON_INVOKE_INNER( object_end_handler_event{}, ec );
1590  
    }
1627  
    }
1591  

1628  

1592  
    bool on_array_begin( system::error_code& ec )
1629  
    bool on_array_begin( system::error_code& ec )
1593  
    {
1630  
    {
1594  
        BOOST_JSON_INVOKE_INNER( array_begin_handler_event{}, ec );
1631  
        BOOST_JSON_INVOKE_INNER( array_begin_handler_event{}, ec );
1595  
    }
1632  
    }
1596  

1633  

1597  
    bool on_array_end( system::error_code& ec )
1634  
    bool on_array_end( system::error_code& ec )
1598  
    {
1635  
    {
1599  
        if( !inner_active_ )
1636  
        if( !inner_active_ )
1600  
            return signal_end(ec);
1637  
            return signal_end(ec);
1601  

1638  

1602  
        BOOST_JSON_INVOKE_INNER( array_end_handler_event{}, ec );
1639  
        BOOST_JSON_INVOKE_INNER( array_end_handler_event{}, ec );
1603  
    }
1640  
    }
1604  

1641  

1605  
    bool on_key_part( system::error_code&, string_view sv )
1642  
    bool on_key_part( system::error_code&, string_view sv )
1606  
    {
1643  
    {
1607  
        string_.append(sv);
1644  
        string_.append(sv);
1608  
        return true;
1645  
        return true;
1609  
    }
1646  
    }
1610  

1647  

1611  
    bool on_key( system::error_code& ec, string_view sv )
1648  
    bool on_key( system::error_code& ec, string_view sv )
1612  
    {
1649  
    {
1613  
        string_.append(sv);
1650  
        string_.append(sv);
1614  
        BOOST_JSON_INVOKE_INNER( key_handler_event{ std::move(string_) }, ec );
1651  
        BOOST_JSON_INVOKE_INNER( key_handler_event{ std::move(string_) }, ec );
1615  
    }
1652  
    }
1616  

1653  

1617  
    bool on_string_part( system::error_code&, string_view sv )
1654  
    bool on_string_part( system::error_code&, string_view sv )
1618  
    {
1655  
    {
1619  
        string_.append(sv);
1656  
        string_.append(sv);
1620  
        return true;
1657  
        return true;
1621  
    }
1658  
    }
1622  

1659  

1623  
    bool on_string( system::error_code& ec, string_view sv )
1660  
    bool on_string( system::error_code& ec, string_view sv )
1624  
    {
1661  
    {
1625  
        string_.append(sv);
1662  
        string_.append(sv);
1626  
        BOOST_JSON_INVOKE_INNER(
1663  
        BOOST_JSON_INVOKE_INNER(
1627  
            string_handler_event{ std::move(string_) }, ec );
1664  
            string_handler_event{ std::move(string_) }, ec );
1628  
    }
1665  
    }
1629  

1666  

1630  
    bool on_number_part( system::error_code& )
1667  
    bool on_number_part( system::error_code& )
1631  
    {
1668  
    {
1632  
        return true;
1669  
        return true;
1633  
    }
1670  
    }
1634  

1671  

1635  
    bool on_int64( system::error_code& ec, std::int64_t v )
1672  
    bool on_int64( system::error_code& ec, std::int64_t v )
1636  
    {
1673  
    {
1637  
        BOOST_JSON_INVOKE_INNER( int64_handler_event{v}, ec );
1674  
        BOOST_JSON_INVOKE_INNER( int64_handler_event{v}, ec );
1638  
    }
1675  
    }
1639  

1676  

1640  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
1677  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
1641  
    {
1678  
    {
1642  
        BOOST_JSON_INVOKE_INNER( uint64_handler_event{v}, ec );
1679  
        BOOST_JSON_INVOKE_INNER( uint64_handler_event{v}, ec );
1643  
    }
1680  
    }
1644  

1681  

1645  
    bool on_double( system::error_code& ec, double v )
1682  
    bool on_double( system::error_code& ec, double v )
1646  
    {
1683  
    {
1647  
        BOOST_JSON_INVOKE_INNER( double_handler_event{v}, ec );
1684  
        BOOST_JSON_INVOKE_INNER( double_handler_event{v}, ec );
1648  
    }
1685  
    }
1649  

1686  

1650  
    bool on_bool( system::error_code& ec, bool v )
1687  
    bool on_bool( system::error_code& ec, bool v )
1651  
    {
1688  
    {
1652  
        BOOST_JSON_INVOKE_INNER( bool_handler_event{v}, ec );
1689  
        BOOST_JSON_INVOKE_INNER( bool_handler_event{v}, ec );
1653  
    }
1690  
    }
1654  

1691  

1655  
    bool on_null( system::error_code& ec )
1692  
    bool on_null( system::error_code& ec )
1656  
    {
1693  
    {
1657  
        BOOST_JSON_INVOKE_INNER( null_handler_event{}, ec );
1694  
        BOOST_JSON_INVOKE_INNER( null_handler_event{}, ec );
1658  
    }
1695  
    }
1659  

1696  

1660  
#undef BOOST_JSON_INVOKE_INNER
1697  
#undef BOOST_JSON_INVOKE_INNER
1661  
};
1698  
};
1662  

1699  

1663  
// optional handler
1700  
// optional handler
1664 -
template<class V, class P>
1701 +
template<class V, class P, class Ctx>
1665 -
class converting_handler<optional_conversion_tag, V, P>
1702 +
class converting_handler<optional_conversion_tag, V, P, Ctx>
1666  
{
1703  
{
1667  
private:
1704  
private:
1668  
    using inner_type = value_result_type<V>;
1705  
    using inner_type = value_result_type<V>;
1669 -
    using inner_handler_type = get_handler<inner_type, converting_handler>;
1706 +
    using inner_rep = conversion_representation<inner_type, Ctx>;
 
1707 +
    using inner_handler_type = get_handler<
 
1708 +
        inner_rep, converting_handler, Ctx>;
1670  

1709  

1671  
    V* value_;
1710  
    V* value_;
1672  
    P* parent_;
1711  
    P* parent_;
1673  

1712  

1674 -
    inner_type inner_value_ = {};
1713 +
    inner_rep inner_value_ = {};
1675  
    inner_handler_type inner_;
1714  
    inner_handler_type inner_;
1676  
    bool inner_active_ = false;
1715  
    bool inner_active_ = false;
1677  

1716  

1678  
public:
1717  
public:
1679  
    converting_handler( converting_handler const& ) = delete;
1718  
    converting_handler( converting_handler const& ) = delete;
1680  
    converting_handler& operator=( converting_handler const& ) = delete;
1719  
    converting_handler& operator=( converting_handler const& ) = delete;
1681  

1720  

1682  
    converting_handler( V* v, P* p )
1721  
    converting_handler( V* v, P* p )
1683  
        : value_(v), parent_(p), inner_(&inner_value_, this)
1722  
        : value_(v), parent_(p), inner_(&inner_value_, this)
1684  
    {}
1723  
    {}
1685  

1724  

1686  
    bool signal_value(system::error_code& ec)
1725  
    bool signal_value(system::error_code& ec)
1687  
    {
1726  
    {
1688  
        *value_ = std::move(inner_value_);
1727  
        *value_ = std::move(inner_value_);
1689  

1728  

1690  
        inner_active_ = false;
1729  
        inner_active_ = false;
1691  
        return parent_->signal_value(ec);
1730  
        return parent_->signal_value(ec);
1692  
    }
1731  
    }
1693  

1732  

1694  
    bool signal_end(system::error_code& ec)
1733  
    bool signal_end(system::error_code& ec)
1695  
    {
1734  
    {
1696  
        return parent_->signal_end(ec);
1735  
        return parent_->signal_end(ec);
1697  
    }
1736  
    }
1698  

1737  

1699  
#define BOOST_JSON_INVOKE_INNER(fn) \
1738  
#define BOOST_JSON_INVOKE_INNER(fn) \
1700  
    if( !inner_active_ ) \
1739  
    if( !inner_active_ ) \
1701  
        inner_active_ = true; \
1740  
        inner_active_ = true; \
1702  
    return inner_.fn;
1741  
    return inner_.fn;
1703  

1742  

1704  
    bool on_object_begin( system::error_code& ec )
1743  
    bool on_object_begin( system::error_code& ec )
1705  
    {
1744  
    {
1706  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
1745  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
1707  
    }
1746  
    }
1708  

1747  

1709  
    bool on_object_end( system::error_code& ec )
1748  
    bool on_object_end( system::error_code& ec )
1710  
    {
1749  
    {
1711  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
1750  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
1712  
    }
1751  
    }
1713  

1752  

1714  
    bool on_array_begin( system::error_code& ec )
1753  
    bool on_array_begin( system::error_code& ec )
1715  
    {
1754  
    {
1716  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
1755  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
1717  
    }
1756  
    }
1718  

1757  

1719  
    bool on_array_end( system::error_code& ec )
1758  
    bool on_array_end( system::error_code& ec )
1720  
    {
1759  
    {
1721  
        if( !inner_active_ )
1760  
        if( !inner_active_ )
1722  
            return signal_end(ec);
1761  
            return signal_end(ec);
1723  

1762  

1724  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
1763  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
1725  
    }
1764  
    }
1726  

1765  

1727  
    bool on_key_part( system::error_code& ec, string_view sv )
1766  
    bool on_key_part( system::error_code& ec, string_view sv )
1728  
    {
1767  
    {
1729  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
1768  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
1730  
    }
1769  
    }
1731  

1770  

1732  
    bool on_key( system::error_code& ec, string_view sv )
1771  
    bool on_key( system::error_code& ec, string_view sv )
1733  
    {
1772  
    {
1734  
        BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
1773  
        BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
1735  
    }
1774  
    }
1736  

1775  

1737  
    bool on_string_part( system::error_code& ec, string_view sv )
1776  
    bool on_string_part( system::error_code& ec, string_view sv )
1738  
    {
1777  
    {
1739  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
1778  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
1740  
    }
1779  
    }
1741  

1780  

1742  
    bool on_string( system::error_code& ec, string_view sv )
1781  
    bool on_string( system::error_code& ec, string_view sv )
1743  
    {
1782  
    {
1744  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
1783  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
1745  
    }
1784  
    }
1746  

1785  

1747  
    bool on_number_part( system::error_code& ec )
1786  
    bool on_number_part( system::error_code& ec )
1748  
    {
1787  
    {
1749  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
1788  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
1750  
    }
1789  
    }
1751  

1790  

1752  
    bool on_int64( system::error_code& ec, std::int64_t v )
1791  
    bool on_int64( system::error_code& ec, std::int64_t v )
1753  
    {
1792  
    {
1754  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
1793  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
1755  
    }
1794  
    }
1756  

1795  

1757  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
1796  
    bool on_uint64( system::error_code& ec, std::uint64_t v )
1758  
    {
1797  
    {
1759  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
1798  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
1760  
    }
1799  
    }
1761  

1800  

1762  
    bool on_double( system::error_code& ec, double v )
1801  
    bool on_double( system::error_code& ec, double v )
1763  
    {
1802  
    {
1764  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
1803  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
1765  
    }
1804  
    }
1766  

1805  

1767  
    bool on_bool( system::error_code& ec, bool v )
1806  
    bool on_bool( system::error_code& ec, bool v )
1768  
    {
1807  
    {
1769  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
1808  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
1770  
    }
1809  
    }
1771  

1810  

1772  
    bool on_null(system::error_code& ec)
1811  
    bool on_null(system::error_code& ec)
1773  
    {
1812  
    {
1774  
        if( !inner_active_ )
1813  
        if( !inner_active_ )
1775  
        {
1814  
        {
1776  
            *value_ = {};
1815  
            *value_ = {};
1777  
            return this->parent_->signal_value(ec);
1816  
            return this->parent_->signal_value(ec);
1778  
        }
1817  
        }
1779  
        else
1818  
        else
1780  
        {
1819  
        {
1781  
            return inner_.on_null(ec);
1820  
            return inner_.on_null(ec);
1782  
        }
1821  
        }
1783  
    }
1822  
    }
1784  

1823  

1785  
#undef BOOST_JSON_INVOKE_INNER
1824  
#undef BOOST_JSON_INVOKE_INNER
1786  
};
1825  
};
1787  

1826  

1788  
// path handler
1827  
// path handler
1789 -
template< class V, class P >
1828 +
template<class V, class P, class Ctx>
1790 -
class converting_handler<path_conversion_tag, V, P>
1829 +
class converting_handler<path_conversion_tag, V, P, Ctx>
1791  
    : public scalar_handler<P, error::not_string>
1830  
    : public scalar_handler<P, error::not_string>
1792  
{
1831  
{
1793  
private:
1832  
private:
1794  
    V* value_;
1833  
    V* value_;
1795  
    bool cleared_ = false;
1834  
    bool cleared_ = false;
1796  

1835  

1797  
public:
1836  
public:
1798  
    converting_handler( V* v, P* p )
1837  
    converting_handler( V* v, P* p )
1799  
        : converting_handler::scalar_handler(p)
1838  
        : converting_handler::scalar_handler(p)
1800  
        , value_(v)
1839  
        , value_(v)
1801  
    {}
1840  
    {}
1802  

1841  

1803  
    bool on_string_part( system::error_code&, string_view sv )
1842  
    bool on_string_part( system::error_code&, string_view sv )
1804  
    {
1843  
    {
1805  
        if( !cleared_ )
1844  
        if( !cleared_ )
1806  
        {
1845  
        {
1807  
            cleared_ = true;
1846  
            cleared_ = true;
1808  
            value_->clear();
1847  
            value_->clear();
1809  
        }
1848  
        }
1810  

1849  

1811  
        value_->concat( sv.begin(), sv.end() );
1850  
        value_->concat( sv.begin(), sv.end() );
1812  
        return true;
1851  
        return true;
1813  
    }
1852  
    }
1814  

1853  

1815  
    bool on_string(system::error_code& ec, string_view sv)
1854  
    bool on_string(system::error_code& ec, string_view sv)
1816  
    {
1855  
    {
1817  
        if( !cleared_ )
1856  
        if( !cleared_ )
1818  
            value_->clear();
1857  
            value_->clear();
1819  
        else
1858  
        else
1820  
            cleared_ = false;
1859  
            cleared_ = false;
1821  

1860  

1822  
        value_->concat( sv.begin(), sv.end() );
1861  
        value_->concat( sv.begin(), sv.end() );
1823  

1862  

1824  
        return this->parent_->signal_value(ec);
1863  
        return this->parent_->signal_value(ec);
1825  
    }
1864  
    }
1826  
};
1865  
};
1827  

1866  

1828  
// into_handler
1867  
// into_handler
1829 -
template< class V >
1868 +
template<
1830 -
class into_handler
1869 +
    class T, class Ctx, class Rep = conversion_representation<T, Ctx> >
 
1870 +
class direct_target_holder
1831  
{
1871  
{
1832 -
private:
1872 +
    Rep rep_;
 
1873 +
    T* tgt_;
1833  

1874  

1834 -
    using inner_handler_type = get_handler<V, into_handler>;
1875 +
public:
 
1876 +
    using representation = Rep;
1835  

1877  

1836 -
    inner_handler_type inner_;
1878 +
    direct_target_holder(T* tgt)
1837 -
    bool inner_active_ = true;
1879 +
        : rep_(*tgt)
 
1880 +
        , tgt_(tgt)
 
1881 +
    {}
1838  

1882  

1839 -
public:
1883 +
    representation*
 
1884 +
    target_address(T*) noexcept
 
1885 +
    {
 
1886 +
        return std::addressof(rep_);
 
1887 +
    }
1840  

1888  

1841 -
    into_handler( into_handler const& ) = delete;
1889 +
    void
1842 -
    into_handler& operator=( into_handler const& ) = delete;
1890 +
    finish()
 
1891 +
    {
 
1892 +
        *tgt_ = std::move(rep_);
 
1893 +
    }
 
1894 +
};
1843  

1895  

 
1896 +
template<class T, class Ctx>
 
1897 +
class direct_target_holder<T, Ctx, T>
 
1898 +
{
1844  
public:
1899  
public:
 
1900 +
    using representation = T;
 
1901 +

 
1902 +
    direct_target_holder(T*) noexcept
 
1903 +
    {}
 
1904 +

 
1905 +
    representation*
 
1906 +
    target_address(T* tgt) const noexcept
 
1907 +
    {
 
1908 +
        return tgt;
 
1909 +
    }
 
1910 +

 
1911 +
    void
 
1912 +
    finish() const noexcept
 
1913 +
    {}
 
1914 +
};
 
1915 +

 
1916 +
template<class V, class Ctx>
 
1917 +
class into_handler
 
1918 +
    : direct_target_holder<V, Ctx>
 
1919 +
{
 
1920 +
private:
 
1921 +
    using inner_handler_type = get_handler<
 
1922 +
        typename into_handler::representation, into_handler, Ctx>;
 
1923 +

 
1924 +
    inner_handler_type inner_;
 
1925 +
    bool inner_active_ = true;
1845  

1926  

 
1927 +
public:
1846  
    static constexpr std::size_t max_object_size = object::max_size();
1928  
    static constexpr std::size_t max_object_size = object::max_size();
1847  
    static constexpr std::size_t max_array_size = array::max_size();
1929  
    static constexpr std::size_t max_array_size = array::max_size();
1848  
    static constexpr std::size_t max_key_size = string::max_size();
1930  
    static constexpr std::size_t max_key_size = string::max_size();
1849  
    static constexpr std::size_t max_string_size = string::max_size();
1931  
    static constexpr std::size_t max_string_size = string::max_size();
1850  

1932  

1851 -
public:
1933 +
    into_handler(into_handler const&) = delete;
 
1934 +
    into_handler& operator=(into_handler const&) = delete;
1852  

1935  

1853 -
    explicit into_handler( V* v ): inner_( v, this )
1936 +
    explicit
1854 -
    {
1937 +
    into_handler( V* v, Ctx const& = Ctx{} )
1855 -
    }
1938 +
        : into_handler::direct_target_holder(v)
 
1939 +
        , inner_(into_handler::target_address(v), this)
 
1940 +
    {}
1856  

1941  

1857  
    bool signal_value(system::error_code&)
1942  
    bool signal_value(system::error_code&)
1858  
    {
1943  
    {
 
1944 +
        into_handler::finish();
1859  
        return true;
1945  
        return true;
1860  
    }
1946  
    }
1861  

1947  

1862  
    bool signal_end(system::error_code&)
1948  
    bool signal_end(system::error_code&)
1863  
    {
1949  
    {
1864  
        return true;
1950  
        return true;
1865  
    }
1951  
    }
1866  

1952  

1867  
    bool on_document_begin( system::error_code& )
1953  
    bool on_document_begin( system::error_code& )
1868  
    {
1954  
    {
1869  
        return true;
1955  
        return true;
1870  
    }
1956  
    }
1871  

1957  

1872  
    bool on_document_end( system::error_code& )
1958  
    bool on_document_end( system::error_code& )
1873  
    {
1959  
    {
1874  
        inner_active_ = false;
1960  
        inner_active_ = false;
1875  
        return true;
1961  
        return true;
1876  
    }
1962  
    }
1877  

1963  

1878  
#define BOOST_JSON_INVOKE_INNER(f) \
1964  
#define BOOST_JSON_INVOKE_INNER(f) \
1879  
    if( !inner_active_ ) \
1965  
    if( !inner_active_ ) \
1880  
    { \
1966  
    { \
1881  
        BOOST_JSON_FAIL( ec, error::extra_data ); \
1967  
        BOOST_JSON_FAIL( ec, error::extra_data ); \
1882  
        return false; \
1968  
        return false; \
1883  
    } \
1969  
    } \
1884  
    else \
1970  
    else \
1885  
        return inner_.f
1971  
        return inner_.f
1886  

1972  

1887  
    bool on_object_begin( system::error_code& ec )
1973  
    bool on_object_begin( system::error_code& ec )
1888  
    {
1974  
    {
1889  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
1975  
        BOOST_JSON_INVOKE_INNER( on_object_begin(ec) );
1890  
    }
1976  
    }
1891  

1977  

1892  
    bool on_object_end( std::size_t, system::error_code& ec )
1978  
    bool on_object_end( std::size_t, system::error_code& ec )
1893  
    {
1979  
    {
1894  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
1980  
        BOOST_JSON_INVOKE_INNER( on_object_end(ec) );
1895  
    }
1981  
    }
1896  

1982  

1897  
    bool on_array_begin( system::error_code& ec )
1983  
    bool on_array_begin( system::error_code& ec )
1898  
    {
1984  
    {
1899  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
1985  
        BOOST_JSON_INVOKE_INNER( on_array_begin(ec) );
1900  
    }
1986  
    }
1901  

1987  

1902  
    bool on_array_end( std::size_t, system::error_code& ec )
1988  
    bool on_array_end( std::size_t, system::error_code& ec )
1903  
    {
1989  
    {
1904  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
1990  
        BOOST_JSON_INVOKE_INNER( on_array_end(ec) );
1905  
    }
1991  
    }
1906  

1992  

1907  
    bool on_key_part( string_view sv, std::size_t, system::error_code& ec )
1993  
    bool on_key_part( string_view sv, std::size_t, system::error_code& ec )
1908  
    {
1994  
    {
1909  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
1995  
        BOOST_JSON_INVOKE_INNER( on_key_part(ec, sv) );
1910  
    }
1996  
    }
1911  

1997  

1912  
    bool on_key( string_view sv, std::size_t, system::error_code& ec )
1998  
    bool on_key( string_view sv, std::size_t, system::error_code& ec )
1913  
    {
1999  
    {
1914  
        BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
2000  
        BOOST_JSON_INVOKE_INNER( on_key(ec, sv) );
1915  
    }
2001  
    }
1916  

2002  

1917  
    bool on_string_part( string_view sv, std::size_t, system::error_code& ec )
2003  
    bool on_string_part( string_view sv, std::size_t, system::error_code& ec )
1918  
    {
2004  
    {
1919  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
2005  
        BOOST_JSON_INVOKE_INNER( on_string_part(ec, sv) );
1920  
    }
2006  
    }
1921  

2007  

1922  
    bool on_string( string_view sv, std::size_t, system::error_code& ec )
2008  
    bool on_string( string_view sv, std::size_t, system::error_code& ec )
1923  
    {
2009  
    {
1924  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
2010  
        BOOST_JSON_INVOKE_INNER( on_string(ec, sv) );
1925  
    }
2011  
    }
1926  

2012  

1927  
    bool on_number_part( string_view, system::error_code& ec )
2013  
    bool on_number_part( string_view, system::error_code& ec )
1928  
    {
2014  
    {
1929  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
2015  
        BOOST_JSON_INVOKE_INNER( on_number_part(ec) );
1930  
    }
2016  
    }
1931  

2017  

1932  
    bool on_int64( std::int64_t v, string_view, system::error_code& ec )
2018  
    bool on_int64( std::int64_t v, string_view, system::error_code& ec )
1933  
    {
2019  
    {
1934  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
2020  
        BOOST_JSON_INVOKE_INNER( on_int64(ec, v) );
1935  
    }
2021  
    }
1936  

2022  

1937  
    bool on_uint64( std::uint64_t v, string_view, system::error_code& ec )
2023  
    bool on_uint64( std::uint64_t v, string_view, system::error_code& ec )
1938  
    {
2024  
    {
1939  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
2025  
        BOOST_JSON_INVOKE_INNER( on_uint64(ec, v) );
1940  
    }
2026  
    }
1941  

2027  

1942  
    bool on_double( double v, string_view, system::error_code& ec )
2028  
    bool on_double( double v, string_view, system::error_code& ec )
1943  
    {
2029  
    {
1944  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
2030  
        BOOST_JSON_INVOKE_INNER( on_double(ec, v) );
1945  
    }
2031  
    }
1946  

2032  

1947  
    bool on_bool( bool v, system::error_code& ec )
2033  
    bool on_bool( bool v, system::error_code& ec )
1948  
    {
2034  
    {
1949  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
2035  
        BOOST_JSON_INVOKE_INNER( on_bool(ec, v) );
1950  
    }
2036  
    }
1951  

2037  

1952  
    bool on_null( system::error_code& ec )
2038  
    bool on_null( system::error_code& ec )
1953  
    {
2039  
    {
1954  
        BOOST_JSON_INVOKE_INNER( on_null(ec) );
2040  
        BOOST_JSON_INVOKE_INNER( on_null(ec) );
1955  
    }
2041  
    }
1956  

2042  

1957  
    bool on_comment_part(string_view, system::error_code&)
2043  
    bool on_comment_part(string_view, system::error_code&)
1958  
    {
2044  
    {
1959  
        return true;
2045  
        return true;
1960  
    }
2046  
    }
1961  

2047  

1962  
    bool on_comment(string_view, system::error_code&)
2048  
    bool on_comment(string_view, system::error_code&)
1963  
    {
2049  
    {
1964  
        return true;
2050  
        return true;
1965 -

 
1966  
    }
2051  
    }
1967  
#undef BOOST_JSON_INVOKE_INNER
2052  
#undef BOOST_JSON_INVOKE_INNER
1968  
};
2053  
};
1969  

2054  

1970  
} // namespace detail
2055  
} // namespace detail
1971  
} // namespace boost
2056  
} // namespace boost
1972  
} // namespace json
2057  
} // namespace json
1973  

2058  

1974  
#endif
2059  
#endif