* Converts a bson value to bool * It returns true for any Numeric value not 0 and false for any 0. * For non Numeric, it returns false for EOD, Undefined or NULL and true for any other value. */
| 707 | * For non Numeric, it returns false for EOD, Undefined or NULL and true for any other value. |
| 708 | */ |
| 709 | bool |
| 710 | BsonValueAsBool(const bson_value_t *value) |
| 711 | { |
| 712 | switch (value->value_type) |
| 713 | { |
| 714 | case BSON_TYPE_BOOL: |
| 715 | { |
| 716 | return value->value.v_bool; |
| 717 | } |
| 718 | |
| 719 | case BSON_TYPE_DOUBLE: |
| 720 | { |
| 721 | return value->value.v_double != 0.0; |
| 722 | } |
| 723 | |
| 724 | case BSON_TYPE_INT32: |
| 725 | { |
| 726 | return value->value.v_int32 != 0; |
| 727 | } |
| 728 | |
| 729 | case BSON_TYPE_INT64: |
| 730 | { |
| 731 | return value->value.v_int64 != 0; |
| 732 | } |
| 733 | |
| 734 | case BSON_TYPE_DECIMAL128: |
| 735 | { |
| 736 | return !IsDecimal128Zero(value); |
| 737 | } |
| 738 | |
| 739 | case BSON_TYPE_NULL: |
| 740 | case BSON_TYPE_EOD: |
| 741 | case BSON_TYPE_UNDEFINED: |
| 742 | { |
| 743 | return false; |
| 744 | } |
| 745 | |
| 746 | default: |
| 747 | { |
| 748 | /* Any other value evaluates to true. */ |
| 749 | return true; |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | |
| 755 | /* Given a bson value it tries to get its date time representation in milliseconds. */ |
no test coverage detected