diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index 4bed054..fea92b2 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -430,3 +430,4 @@ namespace fc #include FC_REFLECT_TYPENAME( fc::variant ) +FC_REFLECT_ENUM( fc::variant::type_id, (null_type)(int64_type)(uint64_type)(double_type)(bool_type)(string_type)(array_type)(object_type) ) diff --git a/src/variant.cpp b/src/variant.cpp index c6077f1..fe69efe 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -8,6 +8,7 @@ //#include #include #include +#include namespace fc { @@ -351,7 +352,7 @@ int64_t variant::as_int64()const case null_type: return 0; default: - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to int64", ("type", "") ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to int64", ("type", get_type()) ); } } @@ -372,7 +373,7 @@ uint64_t variant::as_uint64()const case null_type: return 0; default: - FC_THROW_EXCEPTION( bad_cast_exception,"Invalid cast from ${type} to uint64", ("type","")); + FC_THROW_EXCEPTION( bad_cast_exception,"Invalid cast from ${type} to uint64", ("type",get_type())); } } @@ -394,7 +395,7 @@ double variant::as_double()const case null_type: return 0; default: - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to double" ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to double", ("type",get_type()) ); } } @@ -415,7 +416,7 @@ bool variant::as_bool()const case null_type: return false; default: - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to bool" ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to bool" , ("type",get_type())); } } @@ -436,7 +437,7 @@ string variant::as_string()const case null_type: return string(); default: - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to string", ("type", int64_t(get_type()) ) ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to string", ("type", get_type() ) ); } } @@ -447,7 +448,7 @@ variants& variant::get_array() if( get_type() == array_type ) return **reinterpret_cast(this); - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Array" ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Array", ("type",get_type()) ); } @@ -456,7 +457,7 @@ const variants& variant::get_array()const { if( get_type() == array_type ) return **reinterpret_cast(this); - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Array" ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Array", ("type",get_type()) ); } @@ -465,7 +466,7 @@ variant_object& variant::get_object() { if( get_type() == object_type ) return **reinterpret_cast(this); - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Object" ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Object", ("type",get_type()) ); } const variant& variant::operator[]( const char* key )const @@ -486,7 +487,7 @@ const string& variant::get_string()const { if( get_type() == string_type ) return **reinterpret_cast(this); - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from type '${type}' to Object", ("type",int(get_type())) ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from type '${type}' to Object", ("type",get_type()) ); } @@ -495,7 +496,7 @@ const variant_object& variant::get_object()const { if( get_type() == object_type ) return **reinterpret_cast(this); - FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from type '${type}' to Object", ("type",int(get_type())) ); + FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from type '${type}' to Object", ("type",get_type()) ); } void to_variant( const std::string& s, variant& v )