| 439 | } |
| 440 | |
| 441 | bool variant::as_bool()const |
| 442 | { |
| 443 | switch( get_type() ) |
| 444 | { |
| 445 | case string_type: |
| 446 | { |
| 447 | const string& s = **reinterpret_cast<const const_string_ptr*>(this); |
| 448 | if( s == "true" ) |
| 449 | return true; |
| 450 | if( s == "false" ) |
| 451 | return false; |
| 452 | FC_THROW_EXCEPTION( bad_cast_exception, "Cannot convert string to bool (only \"true\" or \"false\" can be converted)" ); |
| 453 | } |
| 454 | case double_type: |
| 455 | return *reinterpret_cast<const double*>(this) != 0.0; |
| 456 | case int64_type: |
| 457 | return *reinterpret_cast<const int64_t*>(this) != 0; |
| 458 | case uint64_type: |
| 459 | return *reinterpret_cast<const uint64_t*>(this) != 0; |
| 460 | case bool_type: |
| 461 | return *reinterpret_cast<const bool*>(this); |
| 462 | case null_type: |
| 463 | return false; |
| 464 | default: |
| 465 | FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to bool" , ("type",get_type())); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | string variant::as_string()const |
| 470 | { |
no outgoing calls
no test coverage detected