| 746 | } |
| 747 | |
| 748 | Value::Int64 Value::asInt64() const { |
| 749 | switch (type()) { |
| 750 | case intValue: |
| 751 | return Int64(value_.int_); |
| 752 | case uintValue: |
| 753 | JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range"); |
| 754 | return Int64(value_.uint_); |
| 755 | case realValue: |
| 756 | // If the double value is in proximity to minInt64, it will be rounded to |
| 757 | // minInt64. The correct value in this scenario is indeterminable |
| 758 | JSON_ASSERT_MESSAGE( |
| 759 | value_.real_ != minInt64, |
| 760 | "Double value is minInt64, precise value cannot be determined"); |
| 761 | JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64), "double out of Int64 range"); |
| 762 | return Int64(value_.real_); |
| 763 | case nullValue: |
| 764 | return 0; |
| 765 | case booleanValue: |
| 766 | return value_.bool_ ? 1 : 0; |
| 767 | default: |
| 768 | break; |
| 769 | } |
| 770 | JSON_FAIL_MESSAGE("Value is not convertible to Int64."); |
| 771 | } |
| 772 | |
| 773 | Value::UInt64 Value::asUInt64() const { |
| 774 | switch (type()) { |