|
4 | 4 |
|
5 | 5 | // See https://github.com/danielaparker/jsoncons for latest version
|
6 | 6 |
|
7 |
| -#ifndef JSONCONS_STAJ_READER_HPP |
8 |
| -#define JSONCONS_STAJ_READER_HPP |
| 7 | +#ifndef JSONCONS_STAJ_CURSOR_HPP |
| 8 | +#define JSONCONS_STAJ_CURSOR_HPP |
9 | 9 |
|
10 | 10 | #include <memory> // std::allocator
|
11 | 11 | #include <string>
|
|
23 | 23 | #include <jsoncons/sink.hpp>
|
24 | 24 | #include <jsoncons/detail/write_number.hpp>
|
25 | 25 | #include <jsoncons/json_type_traits.hpp>
|
| 26 | +#include <jsoncons/typed_array_view.hpp> |
26 | 27 | #include <jsoncons/converter.hpp>
|
27 | 28 |
|
28 | 29 | namespace jsoncons {
|
@@ -462,223 +463,6 @@ enum class staj_cursor_state
|
462 | 463 | shape
|
463 | 464 | };
|
464 | 465 |
|
465 |
| -struct uint8_array_arg_t {explicit uint8_array_arg_t() = default; }; |
466 |
| -constexpr uint8_array_arg_t uint8_array_arg = uint8_array_arg_t(); |
467 |
| -struct uint16_array_arg_t {explicit uint16_array_arg_t() = default; }; |
468 |
| -struct uint32_array_arg_t {explicit uint32_array_arg_t() = default; }; |
469 |
| -constexpr uint32_array_arg_t uint32_array_arg = uint32_array_arg_t(); |
470 |
| -struct uint64_array_arg_t {explicit uint64_array_arg_t() = default; }; |
471 |
| -constexpr uint64_array_arg_t uint64_array_arg = uint64_array_arg_t(); |
472 |
| -struct int8_array_arg_t {explicit int8_array_arg_t() = default; }; |
473 |
| -constexpr int8_array_arg_t int8_array_arg = int8_array_arg_t(); |
474 |
| -struct int16_array_arg_t {explicit int16_array_arg_t() = default; }; |
475 |
| -constexpr int16_array_arg_t int16_array_arg = int16_array_arg_t(); |
476 |
| -struct int32_array_arg_t {explicit int32_array_arg_t() = default; }; |
477 |
| -constexpr int32_array_arg_t int32_array_arg = int32_array_arg_t(); |
478 |
| -struct int64_array_arg_t {explicit int64_array_arg_t() = default; }; |
479 |
| -constexpr int64_array_arg_t int64_array_arg = int64_array_arg_t(); |
480 |
| -constexpr uint16_array_arg_t uint16_array_arg = uint16_array_arg_t(); |
481 |
| -struct half_array_arg_t {explicit half_array_arg_t() = default; }; |
482 |
| -constexpr half_array_arg_t half_array_arg = half_array_arg_t(); |
483 |
| -struct float_array_arg_t {explicit float_array_arg_t() = default; }; |
484 |
| -constexpr float_array_arg_t float_array_arg = float_array_arg_t(); |
485 |
| -struct double_array_arg_t {explicit double_array_arg_t() = default; }; |
486 |
| -constexpr double_array_arg_t double_array_arg = double_array_arg_t(); |
487 |
| -struct float128_array_arg_t {explicit float128_array_arg_t() = default; }; |
488 |
| -constexpr float128_array_arg_t float128_array_arg = float128_array_arg_t(); |
489 |
| - |
490 |
| -enum class typed_array_type{uint8_value=1,uint16_value,uint32_value,uint64_value, |
491 |
| - int8_value,int16_value,int32_value,int64_value, |
492 |
| - half_value, float_value,double_value}; |
493 |
| - |
494 |
| -class typed_array_view |
495 |
| -{ |
496 |
| - typed_array_type type_; |
497 |
| - union |
498 |
| - { |
499 |
| - const uint8_t* uint8_data_; |
500 |
| - const uint16_t* uint16_data_; |
501 |
| - const uint32_t* uint32_data_; |
502 |
| - const uint64_t* uint64_data_; |
503 |
| - const int8_t* int8_data_; |
504 |
| - const int16_t* int16_data_; |
505 |
| - const int32_t* int32_data_; |
506 |
| - const int64_t* int64_data_; |
507 |
| - const float* float_data_; |
508 |
| - const double* double_data_; |
509 |
| - } data_; |
510 |
| - std::size_t size_; |
511 |
| -public: |
512 |
| - |
513 |
| - typed_array_view() |
514 |
| - : type_(), data_(), size_(0) |
515 |
| - { |
516 |
| - } |
517 |
| - |
518 |
| - typed_array_view(const typed_array_view& other) |
519 |
| - : type_(other.type_), data_(other.data_), size_(other.size()) |
520 |
| - { |
521 |
| - } |
522 |
| - |
523 |
| - typed_array_view(typed_array_view&& other) noexcept |
524 |
| - { |
525 |
| - swap(*this,other); |
526 |
| - } |
527 |
| - |
528 |
| - typed_array_view(const uint8_t* data, std::size_t size) |
529 |
| - : type_(typed_array_type::uint8_value), size_(size) |
530 |
| - { |
531 |
| - data_.uint8_data_ = data; |
532 |
| - } |
533 |
| - |
534 |
| - typed_array_view(const uint16_t* data, std::size_t size) |
535 |
| - : type_(typed_array_type::uint16_value), size_(size) |
536 |
| - { |
537 |
| - data_.uint16_data_ = data; |
538 |
| - } |
539 |
| - |
540 |
| - typed_array_view(const uint32_t* data, std::size_t size) |
541 |
| - : type_(typed_array_type::uint32_value), size_(size) |
542 |
| - { |
543 |
| - data_.uint32_data_ = data; |
544 |
| - } |
545 |
| - |
546 |
| - typed_array_view(const uint64_t* data, std::size_t size) |
547 |
| - : type_(typed_array_type::uint64_value), size_(size) |
548 |
| - { |
549 |
| - data_.uint64_data_ = data; |
550 |
| - } |
551 |
| - |
552 |
| - typed_array_view(const int8_t* data, std::size_t size) |
553 |
| - : type_(typed_array_type::int8_value), size_(size) |
554 |
| - { |
555 |
| - data_.int8_data_ = data; |
556 |
| - } |
557 |
| - |
558 |
| - typed_array_view(const int16_t* data, std::size_t size) |
559 |
| - : type_(typed_array_type::int16_value), size_(size) |
560 |
| - { |
561 |
| - data_.int16_data_ = data; |
562 |
| - } |
563 |
| - |
564 |
| - typed_array_view(const int32_t* data, std::size_t size) |
565 |
| - : type_(typed_array_type::int32_value), size_(size) |
566 |
| - { |
567 |
| - data_.int32_data_ = data; |
568 |
| - } |
569 |
| - |
570 |
| - typed_array_view(const int64_t* data, std::size_t size) |
571 |
| - : type_(typed_array_type::int64_value), size_(size) |
572 |
| - { |
573 |
| - data_.int64_data_ = data; |
574 |
| - } |
575 |
| - |
576 |
| - typed_array_view(half_array_arg_t, const uint16_t* data, std::size_t size) |
577 |
| - : type_(typed_array_type::half_value), size_(size) |
578 |
| - { |
579 |
| - data_.uint16_data_ = data; |
580 |
| - } |
581 |
| - |
582 |
| - typed_array_view(const float* data, std::size_t size) |
583 |
| - : type_(typed_array_type::float_value), size_(size) |
584 |
| - { |
585 |
| - data_.float_data_ = data; |
586 |
| - } |
587 |
| - |
588 |
| - typed_array_view(const double* data, std::size_t size) |
589 |
| - : type_(typed_array_type::double_value), size_(size) |
590 |
| - { |
591 |
| - data_.double_data_ = data; |
592 |
| - } |
593 |
| - |
594 |
| - typed_array_view& operator=(const typed_array_view& other) |
595 |
| - { |
596 |
| - typed_array_view temp(other); |
597 |
| - swap(*this,temp); |
598 |
| - return *this; |
599 |
| - } |
600 |
| - |
601 |
| - typed_array_type type() const {return type_;} |
602 |
| - |
603 |
| - std::size_t size() const |
604 |
| - { |
605 |
| - return size_; |
606 |
| - } |
607 |
| - |
608 |
| - jsoncons::span<const uint8_t> data(uint8_array_arg_t) const |
609 |
| - { |
610 |
| - JSONCONS_ASSERT(type_ == typed_array_type::uint8_value); |
611 |
| - return jsoncons::span<const uint8_t>(data_.uint8_data_, size_); |
612 |
| - } |
613 |
| - |
614 |
| - jsoncons::span<const uint16_t> data(uint16_array_arg_t) const |
615 |
| - { |
616 |
| - JSONCONS_ASSERT(type_ == typed_array_type::uint16_value); |
617 |
| - return jsoncons::span<const uint16_t>(data_.uint16_data_, size_); |
618 |
| - } |
619 |
| - |
620 |
| - jsoncons::span<const uint32_t> data(uint32_array_arg_t) const |
621 |
| - { |
622 |
| - JSONCONS_ASSERT(type_ == typed_array_type::uint32_value); |
623 |
| - return jsoncons::span<const uint32_t>(data_.uint32_data_, size_); |
624 |
| - } |
625 |
| - |
626 |
| - jsoncons::span<const uint64_t> data(uint64_array_arg_t) const |
627 |
| - { |
628 |
| - JSONCONS_ASSERT(type_ == typed_array_type::uint64_value); |
629 |
| - return jsoncons::span<const uint64_t>(data_.uint64_data_, size_); |
630 |
| - } |
631 |
| - |
632 |
| - jsoncons::span<const int8_t> data(int8_array_arg_t) const |
633 |
| - { |
634 |
| - JSONCONS_ASSERT(type_ == typed_array_type::int8_value); |
635 |
| - return jsoncons::span<const int8_t>(data_.int8_data_, size_); |
636 |
| - } |
637 |
| - |
638 |
| - jsoncons::span<const int16_t> data(int16_array_arg_t) const |
639 |
| - { |
640 |
| - JSONCONS_ASSERT(type_ == typed_array_type::int16_value); |
641 |
| - return jsoncons::span<const int16_t>(data_.int16_data_, size_); |
642 |
| - } |
643 |
| - |
644 |
| - jsoncons::span<const int32_t> data(int32_array_arg_t) const |
645 |
| - { |
646 |
| - JSONCONS_ASSERT(type_ == typed_array_type::int32_value); |
647 |
| - return jsoncons::span<const int32_t>(data_.int32_data_, size_); |
648 |
| - } |
649 |
| - |
650 |
| - jsoncons::span<const int64_t> data(int64_array_arg_t) const |
651 |
| - { |
652 |
| - JSONCONS_ASSERT(type_ == typed_array_type::int64_value); |
653 |
| - return jsoncons::span<const int64_t>(data_.int64_data_, size_); |
654 |
| - } |
655 |
| - |
656 |
| - jsoncons::span<const uint16_t> data(half_array_arg_t) const |
657 |
| - { |
658 |
| - JSONCONS_ASSERT(type_ == typed_array_type::half_value); |
659 |
| - return jsoncons::span<const uint16_t>(data_.uint16_data_, size_); |
660 |
| - } |
661 |
| - |
662 |
| - jsoncons::span<const float> data(float_array_arg_t) const |
663 |
| - { |
664 |
| - JSONCONS_ASSERT(type_ == typed_array_type::float_value); |
665 |
| - return jsoncons::span<const float>(data_.float_data_, size_); |
666 |
| - } |
667 |
| - |
668 |
| - jsoncons::span<const double> data(double_array_arg_t) const |
669 |
| - { |
670 |
| - JSONCONS_ASSERT(type_ == typed_array_type::double_value); |
671 |
| - return jsoncons::span<const double>(data_.double_data_, size_); |
672 |
| - } |
673 |
| - |
674 |
| - friend void swap(typed_array_view& a, typed_array_view& b) noexcept |
675 |
| - { |
676 |
| - std::swap(a.data_,b.data_); |
677 |
| - std::swap(a.type_,b.type_); |
678 |
| - std::swap(a.size_,b.size_); |
679 |
| - } |
680 |
| -}; |
681 |
| - |
682 | 466 | template <class CharT>
|
683 | 467 | class basic_staj_visitor : public basic_json_visitor<CharT>
|
684 | 468 | {
|
|
0 commit comments