| 308 | } |
| 309 | |
| 310 | int64_t Value::as_i64() const { |
| 311 | const double value = as_number(); |
| 312 | if (!std::isfinite(value) || std::floor(value) != value) { |
| 313 | throw std::runtime_error("json number is not an integer"); |
| 314 | } |
| 315 | return static_cast<int64_t>(value); |
| 316 | } |
| 317 | |
| 318 | float Value::as_f32() const { |
| 319 | return static_cast<float>(as_number()); |
| 320 | } |
| 321 | |
| 322 | const std::string & Value::as_string() const { |
| 323 | if (!is_string()) { |
| 324 | throw std::runtime_error("json value is not a string"); |
| 325 | } |
| 326 | return string_value_; |
no test coverage detected