MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / try_as_integer

Function try_as_integer

include/jsoncons/basic_json.hpp:3648–3682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

storage_kindFunction · 0.85
as_string_viewFunction · 0.85
dataMethod · 0.45
lengthMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected