Merge branch 'develop' into remove_std_function
Conflicts: include/chaiscript/dispatchkit/proxy_functions_detail.hpp
This commit is contained in:
@@ -54,6 +54,23 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
template<size_t ... I>
|
||||||
|
struct Indexes
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t S, size_t ... I>
|
||||||
|
struct Make_Indexes
|
||||||
|
{
|
||||||
|
typedef typename Make_Indexes<S-1, I..., sizeof...(I)>::indexes indexes;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t ... I>
|
||||||
|
struct Make_Indexes<0, I...>
|
||||||
|
{
|
||||||
|
typedef Indexes<I...> indexes;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to return a list of all param types
|
* Used by Proxy_Function_Impl to return a list of all param types
|
||||||
* it contains.
|
* it contains.
|
||||||
@@ -66,77 +83,40 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Forward declaration
|
|
||||||
template<typename ... Rest>
|
|
||||||
struct Try_Cast;
|
|
||||||
|
|
||||||
template<typename Param, typename ... Rest>
|
|
||||||
struct Try_Cast<Param, Rest...>
|
|
||||||
{
|
|
||||||
static void do_try(const std::vector<Boxed_Value> ¶ms, size_t generation, const Type_Conversions &t_conversions)
|
|
||||||
{
|
|
||||||
boxed_cast<Param>(params[generation], &t_conversions);
|
|
||||||
Try_Cast<Rest...>::do_try(params, generation+1, t_conversions);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 0th case
|
|
||||||
template<>
|
|
||||||
struct Try_Cast<>
|
|
||||||
{
|
|
||||||
static void do_try(const std::vector<Boxed_Value> &, size_t, const Type_Conversions &)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||||
* Proxy_Function_Impl object. This function is primarily used to prevent
|
* Proxy_Function_Impl object. This function is primarily used to prevent
|
||||||
* registration of two functions with the exact same signatures
|
* registration of two functions with the exact same signatures
|
||||||
*/
|
*/
|
||||||
template<typename Ret, typename ... Params>
|
template<typename Ret, typename ... Params, size_t ... I>
|
||||||
bool compare_types_cast(Ret (*)(Params...),
|
bool compare_types_cast(Indexes<I...>, Ret (*)(Params...),
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Try_Cast<Params...>::do_try(params, 0, t_conversions);
|
std::initializer_list<void *>{(boxed_cast<Params>(params[I], &t_conversions), nullptr)...};
|
||||||
|
return true;
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ret, int count, typename ... Params>
|
|
||||||
struct Call_Func
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename Callable, typename ... InnerParams>
|
|
||||||
static Ret do_call(const Callable &f,
|
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions, InnerParams &&... innerparams)
|
|
||||||
{
|
|
||||||
return Call_Func<Ret, count - 1, Params...>::do_call(f, params, t_conversions, std::forward<InnerParams>(innerparams)..., params[sizeof...(Params) - count]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Ret, typename ... Params>
|
template<typename Ret, typename ... Params>
|
||||||
struct Call_Func<Ret, 0, Params...>
|
bool compare_types_cast(Ret (*f)(Params...),
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions)
|
||||||
{
|
{
|
||||||
#ifdef CHAISCRIPT_MSVC
|
typedef typename Make_Indexes<sizeof...(Params)>::indexes indexes;
|
||||||
#pragma warning(push)
|
return compare_types_cast(indexes(), f, params, t_conversions);
|
||||||
#pragma warning(disable : 4100) /// Disable unreferenced formal parameter warning, which only shows up in MSVC I don't think there's any way around it \todo evaluate this
|
}
|
||||||
#endif
|
|
||||||
template<typename Callable, typename ... InnerParams>
|
|
||||||
static Ret do_call(const Callable &f,
|
template<typename Callable, typename Ret, typename ... Params, size_t ... I>
|
||||||
const std::vector<Boxed_Value> &, const Type_Conversions &t_conversions, InnerParams &&... innerparams)
|
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &, Indexes<I...>, const Callable &f,
|
||||||
{
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions)
|
||||||
return f(boxed_cast<Params>(std::forward<InnerParams>(innerparams), &t_conversions)...);
|
{
|
||||||
}
|
return f(boxed_cast<Params>(params[I], &t_conversions)...);
|
||||||
#ifdef CHAISCRIPT_MSVC
|
}
|
||||||
#pragma warning(pop)
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
* Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
||||||
@@ -145,15 +125,11 @@ namespace chaiscript
|
|||||||
* 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...)> &, const Callable &f,
|
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions &t_conversions)
|
||||||
{
|
{
|
||||||
if (params.size() == sizeof...(Params))
|
typedef typename Make_Indexes<sizeof...(Params)>::indexes indexes;
|
||||||
{
|
return call_func(sig, indexes(), f, params, t_conversions);
|
||||||
return Call_Func<Ret, sizeof...(Params), Params...>::do_call(f, params, t_conversions);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw exception::arity_error(static_cast<int>(params.size()), sizeof...(Params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,10 @@ Master Status: [](https://travis-ci.org/ChaiScript/ChaiScript) [](https://ci.appveyor.com/project/lefticus/chaiscript/branch/develop) [](https://coveralls.io/r/ChaiScript/ChaiScript?branch=develop)
|
Develop Status: [](https://travis-ci.org/ChaiScript/ChaiScript) [](https://ci.appveyor.com/project/lefticus/chaiscript/branch/develop) [](https://coveralls.io/r/ChaiScript/ChaiScript?branch=develop)
|
||||||
|
|
||||||
|
<a href="https://scan.coverity.com/projects/5297">
|
||||||
|
<img alt="Coverity Scan Build Status"
|
||||||
|
src="https://img.shields.io/coverity/scan/5297.svg"/>
|
||||||
|
</a>
|
||||||
|
|
||||||
ChaiScript
|
ChaiScript
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user