Clean up syntax for build_function_caller to allow for further use of it better

This commit is contained in:
Jason Turner
2009-06-21 17:20:26 +00:00
parent 75431a052b
commit d4ec79607f
4 changed files with 20 additions and 6 deletions

View File

@@ -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)
)
);
}

View File

@@ -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)
)
)
);

View File

@@ -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

View File

@@ -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"));