| 3507 | } |
| 3508 | |
| 3509 | bool Value::isConvertibleTo(ValueType other) const |
| 3510 | { |
| 3511 | switch (other) |
| 3512 | { |
| 3513 | case nullValue: |
| 3514 | return (isNumeric() && asDouble() == 0.0) || (type() == booleanValue && !value_.bool_) || |
| 3515 | (type() == stringValue && asString().empty()) || |
| 3516 | (type() == arrayValue && value_.map_->empty()) || |
| 3517 | (type() == objectValue && value_.map_->empty()) || type() == nullValue; |
| 3518 | case intValue: |
| 3519 | return isInt() || (type() == realValue && InRange(value_.real_, minInt, maxInt)) || |
| 3520 | type() == booleanValue || type() == nullValue; |
| 3521 | case uintValue: |
| 3522 | return isUInt() || (type() == realValue && InRange(value_.real_, 0, maxUInt)) || |
| 3523 | type() == booleanValue || type() == nullValue; |
| 3524 | case realValue: |
| 3525 | return isNumeric() || type() == booleanValue || type() == nullValue; |
| 3526 | case booleanValue: |
| 3527 | return isNumeric() || type() == booleanValue || type() == nullValue; |
| 3528 | case stringValue: |
| 3529 | return isNumeric() || type() == booleanValue || type() == stringValue || type() == nullValue; |
| 3530 | case arrayValue: |
| 3531 | return type() == arrayValue || type() == nullValue; |
| 3532 | case objectValue: |
| 3533 | return type() == objectValue || type() == nullValue; |
| 3534 | } |
| 3535 | JSON_ASSERT_UNREACHABLE; |
| 3536 | return false; |
| 3537 | } |
| 3538 | |
| 3539 | /// Number of values in array or object |
| 3540 | ArrayIndex Value::size() const |