| 74 | /// \endcode |
| 75 | template<typename Type> |
| 76 | decltype(auto) boxed_cast(const Boxed_Value &bv, const Type_Conversions_State *t_conversions = nullptr) |
| 77 | { |
| 78 | if (!t_conversions || bv.get_type_info().bare_equal(user_type<Type>()) || (t_conversions && !(*t_conversions)->convertable_type<Type>())) { |
| 79 | try { |
| 80 | return(detail::Cast_Helper<Type>::cast(bv, t_conversions)); |
| 81 | } catch (const chaiscript::detail::exception::bad_any_cast &) { |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | if (t_conversions && (*t_conversions)->convertable_type<Type>()) |
| 87 | { |
| 88 | try { |
| 89 | // We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it |
| 90 | // either way, we are not responsible if it doesn't work |
| 91 | return(detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_conversion<Type>(t_conversions->saves(), bv), t_conversions)); |
| 92 | } catch (...) { |
| 93 | try { |
| 94 | // try going the other way |
| 95 | return(detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_down_conversion<Type>(t_conversions->saves(), bv), t_conversions)); |
| 96 | } catch (const chaiscript::detail::exception::bad_any_cast &) { |
| 97 | throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); |
| 98 | } |
| 99 | } |
| 100 | } else { |
| 101 | // If it's not convertable, just throw the error, don't waste the time on the |
| 102 | // attempted dynamic_cast |
| 103 | throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); |
| 104 | } |
| 105 | |
| 106 | } |
| 107 | |
| 108 | } |
| 109 |
nothing calls this directly
no test coverage detected