MCPcopy Create free account
hub / github.com/Clarionos/clarion / as_bool

Method as_bool

libraries/fc/src/variant.cpp:441–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439}
440
441bool 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
469string variant::as_string()const
470{

Callers 2

from_variantFunction · 0.80
operator !Function · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected