This commit is contained in:
Jason Turner
2011-03-14 09:12:01 -06:00
12 changed files with 78 additions and 39 deletions

View File

@@ -21,8 +21,8 @@ namespace chaiscript
{
public:
bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to,
const std::string &what)
: from(t_from), to(&t_to), m_what(what)
const std::string &t_what) throw()
: from(t_from), to(&t_to), m_what(t_what)
{
}
@@ -31,8 +31,8 @@ namespace chaiscript
{
}
bad_boxed_cast(const std::string &w) throw()
: m_what(w)
bad_boxed_cast(const std::string &t_what) throw()
: m_what(t_what)
{
}

View File

@@ -581,6 +581,9 @@ namespace chaiscript
m->add(user_type<std::runtime_error>(), "runtime_error");
m->add(chaiscript::base_class<std::exception, std::runtime_error>());
m->add(constructor<std::runtime_error (const std::string &)>(), "runtime_error");
m->add(fun(boost::function<std::string (const std::runtime_error &)>(&what)), "what");

View File

@@ -203,14 +203,14 @@ namespace chaiscript
throw exception::bad_boxed_cast(">> only valid for integer types");
}
Boxed_Value smart_size(boost::int64_t i) const
Boxed_Value smart_size(boost::int64_t t_i) const
{
if (i < boost::integer_traits<int>::const_min
|| i > boost::integer_traits<int>::const_max)
if (t_i < boost::integer_traits<int>::const_min
|| t_i > boost::integer_traits<int>::const_max)
{
return Boxed_Value(i);
return Boxed_Value(t_i);
} else {
return Boxed_Value(static_cast<int>(i));
return Boxed_Value(static_cast<int>(t_i));
}
}

View File

@@ -21,7 +21,7 @@ namespace chaiscript
{
public:
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to,
const std::string &t_what)
const std::string &t_what) throw()
: bad_boxed_cast(t_from, t_to, t_what)
{
}
@@ -35,6 +35,8 @@ namespace chaiscript
: bad_boxed_cast(w)
{
}
virtual ~bad_boxed_dynamic_cast() throw() {}
};
}
@@ -74,17 +76,17 @@ namespace chaiscript
{
}
virtual Boxed_Value convert(const Boxed_Value &derived)
virtual Boxed_Value convert(const Boxed_Value &t_derived)
{
if (derived.get_type_info().bare_equal(user_type<Derived>()))
if (t_derived.get_type_info().bare_equal(user_type<Derived>()))
{
if (derived.is_pointer())
if (t_derived.is_pointer())
{
// Dynamic cast out the contained boxed value, which we know is the type we want
if (derived.is_const())
if (t_derived.is_const())
{
boost::shared_ptr<const Base> data
= boost::dynamic_pointer_cast<const Base>(detail::Cast_Helper<boost::shared_ptr<const Derived> >::cast(derived));
= boost::dynamic_pointer_cast<const Base>(detail::Cast_Helper<boost::shared_ptr<const Derived> >::cast(t_derived));
if (!data)
{
throw std::bad_cast();
@@ -93,7 +95,7 @@ namespace chaiscript
return Boxed_Value(data);
} else {
boost::shared_ptr<Base> data
= boost::dynamic_pointer_cast<Base>(detail::Cast_Helper<boost::shared_ptr<Derived> >::cast(derived));
= boost::dynamic_pointer_cast<Base>(detail::Cast_Helper<boost::shared_ptr<Derived> >::cast(t_derived));
if (!data)
{
@@ -104,19 +106,19 @@ namespace chaiscript
}
} else {
// Pull the reference out of the contained boxed value, which we know is the type we want
if (derived.is_const())
if (t_derived.is_const())
{
const Derived &d = detail::Cast_Helper<const Derived &>::cast(derived);
const Derived &d = detail::Cast_Helper<const Derived &>::cast(t_derived);
const Base &data = dynamic_cast<const Base &>(d);
return Boxed_Value(boost::cref(data));
} else {
Derived &d = detail::Cast_Helper<Derived &>::cast(derived);
Derived &d = detail::Cast_Helper<Derived &>::cast(t_derived);
Base &data = dynamic_cast<Base &>(d);
return Boxed_Value(boost::ref(data));
}
}
} else {
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unknown dynamic_cast_conversion");
throw exception::bad_boxed_dynamic_cast(t_derived.get_type_info(), typeid(Base), "Unknown dynamic_cast_conversion");
}
}
};

View File

@@ -69,7 +69,7 @@ namespace chaiscript
{
call_func(fun, params);
return Handle_Return<void>::handle();
};
}
};
}
}