Remove Do_Call helper class
This commit is contained in:
@@ -226,48 +226,47 @@ namespace chaiscript
|
|||||||
return m_data->m_type_info.bare_equal(ti);
|
return m_data->m_type_info.bare_equal(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct Sentinel {
|
|
||||||
Sentinel(std::shared_ptr<T> &ptr, Data &data)
|
|
||||||
: m_ptr(ptr), m_data(data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~Sentinel()
|
|
||||||
{
|
|
||||||
// save new pointer data
|
|
||||||
m_data.get().m_data_ptr = m_ptr.get().get();
|
|
||||||
m_data.get().m_const_data_ptr = m_ptr.get().get();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sentinel& operator=(Sentinel&&s) {
|
|
||||||
m_ptr = std::move(s.m_ptr);
|
|
||||||
m_data = std::move(s.m_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
Sentinel(Sentinel &&s)
|
|
||||||
: m_ptr(std::move(s.m_ptr)),
|
|
||||||
m_data(std::move(s.m_data))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
operator std::shared_ptr<T>&() const
|
|
||||||
{
|
|
||||||
return m_ptr.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sentinel &operator=(const Sentinel &) = delete;
|
|
||||||
Sentinel(Sentinel&) = delete;
|
|
||||||
|
|
||||||
std::reference_wrapper<std::shared_ptr<T>> m_ptr;
|
|
||||||
std::reference_wrapper<Data> m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Sentinel<T> pointer_sentinel(std::shared_ptr<T> &ptr) const
|
auto pointer_sentinel(std::shared_ptr<T> &ptr) const
|
||||||
{
|
{
|
||||||
return Sentinel<T>(ptr, *(m_data.get()));
|
struct Sentinel {
|
||||||
|
Sentinel(std::shared_ptr<T> &ptr, Data &data)
|
||||||
|
: m_ptr(ptr), m_data(data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~Sentinel()
|
||||||
|
{
|
||||||
|
// save new pointer data
|
||||||
|
m_data.get().m_data_ptr = m_ptr.get().get();
|
||||||
|
m_data.get().m_const_data_ptr = m_ptr.get().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentinel& operator=(Sentinel&&s) {
|
||||||
|
m_ptr = std::move(s.m_ptr);
|
||||||
|
m_data = std::move(s.m_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentinel(Sentinel &&s)
|
||||||
|
: m_ptr(std::move(s.m_ptr)),
|
||||||
|
m_data(std::move(s.m_data))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
operator std::shared_ptr<T>&() const
|
||||||
|
{
|
||||||
|
return m_ptr.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentinel &operator=(const Sentinel &) = delete;
|
||||||
|
Sentinel(Sentinel&) = delete;
|
||||||
|
|
||||||
|
std::reference_wrapper<std::shared_ptr<T>> m_ptr;
|
||||||
|
std::reference_wrapper<Data> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
return Sentinel(ptr, *(m_data.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_null() const noexcept
|
bool is_null() const noexcept
|
||||||
|
@@ -595,8 +595,7 @@ namespace chaiscript
|
|||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
||||||
{
|
{
|
||||||
typedef typename detail::Function_Signature<Func>::Return_Type Return_Type;
|
return detail::call_func(detail::Function_Signature<Func>(), m_f, params, t_conversions);
|
||||||
return detail::Do_Call<Return_Type>::template go<Func>(m_f, params, t_conversions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -648,7 +647,7 @@ namespace chaiscript
|
|||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
||||||
{
|
{
|
||||||
return detail::Do_Call<typename std::function<Func>::result_type>::template go<Func>(m_f.get(), params, t_conversions);
|
return detail::call_func(detail::Function_Signature<Func>(), m_f.get(), params, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -99,17 +99,23 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/// Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
||||||
* Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
/// The function attempts to unbox each parameter to the expected type.
|
||||||
* The function attempts to unbox each parameter to the expected type.
|
/// if any unboxing fails the execution of the function fails and
|
||||||
* if any unboxing fails the execution of the function fails and
|
/// the bad_boxed_cast is passed up to the caller.
|
||||||
* the bad_boxed_cast is passed up to the caller.
|
|
||||||
*/
|
|
||||||
template<typename Callable, typename Ret, typename ... Params>
|
template<typename Callable, typename Ret, typename ... Params>
|
||||||
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
{
|
{
|
||||||
return call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions);
|
return Handle_Return<Ret>::handle(call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Callable, typename ... Params>
|
||||||
|
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<void (Params...)> &sig, const Callable &f,
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions);
|
||||||
|
return Handle_Return<void>::handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -118,34 +124,4 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace chaiscript
|
|
||||||
{
|
|
||||||
namespace dispatch
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename Ret>
|
|
||||||
struct Do_Call
|
|
||||||
{
|
|
||||||
template<typename Signature, typename Callable>
|
|
||||||
static Boxed_Value go(const Callable &fun, const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
|
||||||
{
|
|
||||||
return Handle_Return<Ret>::handle(call_func(Function_Signature<Signature>(), fun, params, t_conversions));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct Do_Call<void>
|
|
||||||
{
|
|
||||||
template<typename Signature, typename Callable>
|
|
||||||
static Boxed_Value go(const Callable &fun, const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
|
||||||
{
|
|
||||||
call_func(Function_Signature<Signature>(), fun, params, t_conversions);
|
|
||||||
return Handle_Return<void>::handle();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user