Phase one of getting rid of std::function usage

This commit is contained in:
Jason Turner
2015-05-22 09:30:42 -06:00
parent 33a929ef93
commit 03143a9f83
4 changed files with 102 additions and 13 deletions

View File

@@ -549,6 +549,45 @@ namespace chaiscript
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const = 0;
};
/// For any callable object
template<typename Func, typename Callable>
class Proxy_Function_Callable_Impl : public Proxy_Function_Impl_Base
{
public:
Proxy_Function_Callable_Impl(Callable f)
: Proxy_Function_Impl_Base(detail::build_param_type_list(static_cast<Func *>(nullptr))),
m_f(std::move(f)), m_dummy_func(nullptr)
{
}
virtual ~Proxy_Function_Callable_Impl() {}
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
{
return detail::compare_types_cast(m_dummy_func, vals, t_conversions);
}
virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE
{
return dynamic_cast<const Proxy_Function_Callable_Impl<Func, Callable> *>(&t_func) != nullptr;
}
protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
{
typedef typename detail::Callable_Traits<Callable>::Return_Type Return_Type;
return detail::Do_Call<Return_Type>::go(m_f, params, t_conversions);
}
private:
Callable m_f;
Func *m_dummy_func;
};
/// The standard typesafe function call implementation of Proxy_Function
/// It takes a std::function<> object and performs runtime
/// type checking of Boxed_Value parameters, in a type safe manner