17
17
#include < utility>
18
18
#include < vector>
19
19
20
+ #include < jsoncons/allocator_set.hpp>
21
+ #include < jsoncons/basic_json.hpp>
20
22
#include < jsoncons/config/compiler_support.hpp>
21
23
#include < jsoncons/conv_error.hpp>
24
+ #include < jsoncons/decode_traits.hpp>
25
+ #include < jsoncons/json_cursor.hpp>
22
26
#include < jsoncons/json_exception.hpp>
23
27
#include < jsoncons/json_type.hpp>
24
- #include < jsoncons/reflect/json_conv_traits.hpp>
25
28
#include < jsoncons/json_visitor.hpp>
29
+ #include < jsoncons/reflect/decode_json.hpp>
30
+ #include < jsoncons/reflect/json_conv_traits.hpp>
31
+ #include < jsoncons/reflect/read_result.hpp>
26
32
#include < jsoncons/semantic_tag.hpp>
27
33
#include < jsoncons/ser_context.hpp>
34
+ #include < jsoncons/source.hpp>
28
35
#include < jsoncons/staj_cursor.hpp>
29
36
#include < jsoncons/staj_event.hpp>
30
- #include < jsoncons/reflect/read_result.hpp>
31
37
#include < jsoncons/utility/more_type_traits.hpp>
32
38
33
39
namespace jsoncons {
@@ -184,7 +190,8 @@ struct decode_traits<T,
184
190
!ext_traits::is_typed_array<T>::value
185
191
>::type>
186
192
{
187
- using value_type = typename T::value_type;
193
+ using element_type = typename T::value_type;
194
+ using value_type = T;
188
195
using result_type = read_result<value_type>;
189
196
190
197
template <typename CharT>
@@ -205,7 +212,7 @@ struct decode_traits<T,
205
212
cursor.next (ec);
206
213
while (cursor.current ().event_type () != staj_event_type::end_array && !ec)
207
214
{
208
- auto r = decode_traits<value_type >::try_decode (cursor);
215
+ auto r = decode_traits<element_type >::try_decode (cursor);
209
216
if (!r)
210
217
{
211
218
return result_type (r.error ());
@@ -225,7 +232,8 @@ struct typed_array_visitor : public default_json_visitor
225
232
T& v_;
226
233
int level_{0 };
227
234
public:
228
- using value_type = typename T::value_type;
235
+ using element_type = typename T::value_type;
236
+ using value_type = T;
229
237
using result_type = read_result<value_type>;
230
238
231
239
typed_array_visitor (T& v)
@@ -278,7 +286,7 @@ struct typed_array_visitor : public default_json_visitor
278
286
const ser_context&,
279
287
std::error_code&) override
280
288
{
281
- v_.push_back (static_cast <value_type >(value));
289
+ v_.push_back (static_cast <element_type >(value));
282
290
JSONCONS_VISITOR_RETURN;
283
291
}
284
292
@@ -287,7 +295,7 @@ struct typed_array_visitor : public default_json_visitor
287
295
const ser_context&,
288
296
std::error_code&) override
289
297
{
290
- v_.push_back (static_cast <value_type >(value));
298
+ v_.push_back (static_cast <element_type >(value));
291
299
JSONCONS_VISITOR_RETURN;
292
300
}
293
301
@@ -296,35 +304,35 @@ struct typed_array_visitor : public default_json_visitor
296
304
const ser_context&,
297
305
std::error_code&) override
298
306
{
299
- visit_half_ (typename std::integral_constant<bool , std::is_integral<value_type >::value>::type (), value);
307
+ visit_half_ (typename std::integral_constant<bool , std::is_integral<element_type >::value>::type (), value);
300
308
JSONCONS_VISITOR_RETURN;
301
309
}
302
310
303
311
void visit_half_ (std::true_type, uint16_t value)
304
312
{
305
- v_.push_back (static_cast <value_type >(value));
313
+ v_.push_back (static_cast <element_type >(value));
306
314
}
307
315
308
316
void visit_half_ (std::false_type, uint16_t value)
309
317
{
310
- v_.push_back (static_cast <value_type >(binary::decode_half (value)));
318
+ v_.push_back (static_cast <element_type >(binary::decode_half (value)));
311
319
}
312
320
313
321
JSONCONS_VISITOR_RETURN_TYPE visit_double (double value,
314
322
semantic_tag,
315
323
const ser_context&,
316
324
std::error_code&) override
317
325
{
318
- v_.push_back (static_cast <value_type >(value));
326
+ v_.push_back (static_cast <element_type >(value));
319
327
JSONCONS_VISITOR_RETURN;
320
328
}
321
329
322
- JSONCONS_VISITOR_RETURN_TYPE visit_typed_array (const jsoncons::span<const value_type >& data,
330
+ JSONCONS_VISITOR_RETURN_TYPE visit_typed_array (const jsoncons::span<const element_type >& data,
323
331
semantic_tag,
324
332
const ser_context&,
325
333
std::error_code&) override
326
334
{
327
- v_ = std::vector<value_type >(data.begin (),data.end ());
335
+ v_ = std::vector<element_type >(data.begin (),data.end ());
328
336
JSONCONS_VISITOR_RETURN;
329
337
}
330
338
@@ -348,7 +356,8 @@ struct decode_traits<T,
348
356
ext_traits::is_typed_array<T>::value
349
357
>::type>
350
358
{
351
- using value_type = typename T::value_type;
359
+ using element_type = typename T::value_type;
360
+ using value_type = T;
352
361
using result_type = read_result<value_type>;
353
362
354
363
template <typename CharT>
@@ -375,7 +384,7 @@ struct decode_traits<T,
375
384
}
376
385
for (auto ch : bytes)
377
386
{
378
- v.push_back (static_cast <value_type >(ch));
387
+ v.push_back (static_cast <element_type >(ch));
379
388
}
380
389
cursor.next (ec);
381
390
return result_type{std::move (v)};
@@ -422,7 +431,7 @@ struct decode_traits<T,
422
431
ext_traits::is_typed_array<T>::value
423
432
>::type>
424
433
{
425
- using value_type = typename T::value_type ;
434
+ using value_type = T ;
426
435
using result_type = read_result<value_type>;
427
436
428
437
template <typename CharT>
@@ -474,7 +483,8 @@ struct decode_traits<T,
474
483
ext_traits::is_insertable<T>::value
475
484
>::type>
476
485
{
477
- using value_type = typename T::value_type;
486
+ using element_type = typename T::value_type;
487
+ using value_type = T;
478
488
using result_type = read_result<value_type>;
479
489
480
490
template <typename CharT>
@@ -499,7 +509,7 @@ struct decode_traits<T,
499
509
cursor.next (ec);
500
510
while (cursor.current ().event_type () != staj_event_type::end_array && !ec)
501
511
{
502
- auto r = decode_traits<value_type >::try_decode (cursor);
512
+ auto r = decode_traits<element_type >::try_decode (cursor);
503
513
if (!r)
504
514
{
505
515
return result_type (r.error ());
@@ -528,19 +538,20 @@ struct decode_traits<T,
528
538
template <typename T, std::size_t N>
529
539
struct decode_traits <std::array<T,N>>
530
540
{
531
- using value_type = typename std::array<T,N>::value_type;
541
+ using element_type = typename std::array<T,N>::value_type;
542
+ using value_type = typename std::array<T,N>;
532
543
using result_type = read_result<value_type>;
533
544
534
545
template <typename CharT>
535
- static std::array<T, N> try_decode (basic_staj_cursor<CharT>& cursor)
546
+ static result_type try_decode (basic_staj_cursor<CharT>& cursor)
536
547
{
537
548
std::error_code ec;
538
549
539
550
std::array<T,N> v;
540
551
cursor.array_expected (ec);
541
552
if (JSONCONS_UNLIKELY (ec))
542
553
{
543
- return result_type{ read_error{ec, cursor.line (), cursor.column ()}} ;
554
+ return result_type ( read_error{ec, cursor.line (), cursor.column ()}) ;
544
555
}
545
556
v.fill (T{});
546
557
if (cursor.current ().event_type () != staj_event_type::begin_array)
@@ -550,7 +561,7 @@ struct decode_traits<std::array<T,N>>
550
561
cursor.next (ec);
551
562
for (std::size_t i = 0 ; i < N && cursor.current ().event_type () != staj_event_type::end_array && !ec; ++i)
552
563
{
553
- auto r = decode_traits<value_type >::try_decode (cursor);
564
+ auto r = decode_traits<element_type >::try_decode (cursor);
554
565
if (!r)
555
566
{
556
567
return result_type (r.error ());
@@ -576,7 +587,7 @@ struct decode_traits<T,
576
587
>::type>
577
588
{
578
589
using mapped_type = typename T::mapped_type;
579
- using value_type = typename T::value_type ;
590
+ using value_type = T ;
580
591
using key_type = typename T::key_type;
581
592
using result_type = read_result<value_type>;
582
593
@@ -647,7 +658,7 @@ struct decode_traits<T,
647
658
>::type>
648
659
{
649
660
using mapped_type = typename T::mapped_type;
650
- using value_type = typename T::value_type ;
661
+ using value_type = T ;
651
662
using key_type = typename T::key_type;
652
663
using result_type = read_result<value_type>;
653
664
0 commit comments