Clean up syntax for build_function_caller to allow for further use of it better
This commit is contained in:
@@ -15,8 +15,8 @@ struct Callback_Handler
|
||||
boost::shared_ptr<dispatchkit::Proxy_Function> t_value)
|
||||
{
|
||||
m_callbacks.push_back(
|
||||
std::make_pair(dispatchkit::build_function_caller<std::string>(t_name),
|
||||
dispatchkit::build_function_caller<double, int>(t_value)
|
||||
std::make_pair(dispatchkit::build_function_caller<std::string ()>(t_name),
|
||||
dispatchkit::build_function_caller<double (int)>(t_value)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ struct Sensor_Manager
|
||||
m_sensors.insert(
|
||||
std::make_pair(t_name,
|
||||
Sensor(t_milliseconds, t_state_object,
|
||||
dispatchkit::build_function_caller<double, dispatchkit::Boxed_Value>(t_func)
|
||||
dispatchkit::build_function_caller<double (dispatchkit::Boxed_Value)>(t_func)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@@ -48,6 +48,18 @@ namespace dispatchkit
|
||||
#define BOOST_PP_ITERATION_LIMITS ( 0, 9 )
|
||||
#define BOOST_PP_FILENAME_1 "function_call.hpp"
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
namespace dispatchkit
|
||||
{
|
||||
template<typename FunctionType, typename Function>
|
||||
boost::function<FunctionType>
|
||||
build_function_caller(Function func)
|
||||
{
|
||||
FunctionType *p;
|
||||
return build_function_caller_helper(p, func);
|
||||
}
|
||||
}
|
||||
|
||||
# endif
|
||||
#else
|
||||
# define n BOOST_PP_ITERATION()
|
||||
@@ -67,7 +79,7 @@ namespace dispatchkit
|
||||
|
||||
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param)) >
|
||||
build_function_caller(boost::shared_ptr<Proxy_Function> func)
|
||||
build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), boost::shared_ptr<Proxy_Function> func)
|
||||
{
|
||||
std::vector<std::pair<std::string, boost::shared_ptr<Proxy_Function> > > funcs;
|
||||
funcs.push_back(std::make_pair(std::string(), func));
|
||||
@@ -77,11 +89,13 @@ namespace dispatchkit
|
||||
|
||||
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param)) >
|
||||
build_function_caller(const std::vector<std::pair<std::string, boost::shared_ptr<Proxy_Function> > > &funcs)
|
||||
build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector<std::pair<std::string, boost::shared_ptr<Proxy_Function> > > &funcs)
|
||||
{
|
||||
return boost::bind(&function_caller<Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>, funcs
|
||||
BOOST_PP_ENUM_TRAILING(n, curry, ~));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -157,7 +157,7 @@ int main()
|
||||
|
||||
//Build a bound function proxy for calling the script handled function
|
||||
boost::function<void (Test &)> show_message =
|
||||
build_function_caller<void, Test &>(ss.get_function("show_message"));
|
||||
build_function_caller<void (Test &)>(ss.get_function("show_message"));
|
||||
|
||||
Test &t = Cast_Helper<Test &>()(ss.get_object("testobj2"));
|
||||
|
||||
|
Reference in New Issue
Block a user