| 3646 | |
| 3647 | template <typename T> |
| 3648 | conversion_result<T> try_as_integer() const |
| 3649 | { |
| 3650 | using result_type = conversion_result<T>; |
| 3651 | |
| 3652 | switch (storage_kind()) |
| 3653 | { |
| 3654 | case json_storage_kind::short_str: |
| 3655 | case json_storage_kind::long_str: |
| 3656 | { |
| 3657 | T val; |
| 3658 | auto result = jsoncons::to_integer<T>(as_string_view().data(), as_string_view().length(), val); |
| 3659 | if (!result) |
| 3660 | { |
| 3661 | return result_type(jsoncons::unexpect, conv_errc::not_integer); |
| 3662 | } |
| 3663 | return val; |
| 3664 | } |
| 3665 | case json_storage_kind::half_float: |
| 3666 | return result_type(static_cast<T>(cast<half_storage>().value())); |
| 3667 | case json_storage_kind::float64: |
| 3668 | return result_type(static_cast<T>(cast<double_storage>().value())); |
| 3669 | case json_storage_kind::int64: |
| 3670 | return result_type(static_cast<T>(cast<int64_storage>().value())); |
| 3671 | case json_storage_kind::uint64: |
| 3672 | return result_type(static_cast<T>(cast<uint64_storage>().value())); |
| 3673 | case json_storage_kind::boolean: |
| 3674 | return result_type(static_cast<T>(cast<bool_storage>().value() ? 1 : 0)); |
| 3675 | case json_storage_kind::const_json_ref: |
| 3676 | return cast<const_json_ref_storage>().value().template try_as_integer<T>(); |
| 3677 | case json_storage_kind::json_ref: |
| 3678 | return cast<json_ref_storage>().value().template try_as_integer<T>(); |
| 3679 | default: |
| 3680 | return result_type(jsoncons::unexpect, conv_errc::not_integer); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | template <typename T> |
| 3685 | T as_integer() const |
nothing calls this directly
no test coverage detected