#include #define addparam(z,n,text) params.push_back(Boxed_Value(BOOST_PP_CAT(p, n) )); #define curry(z,n,text) BOOST_PP_CAT(_, BOOST_PP_INC(n)) #ifndef BOOST_PP_IS_ITERATING #ifndef __function_call_hpp__ #define __function_call_hpp__ #include #include #include #include #include #include "proxy_functions.hpp" namespace dispatchkit { template class Function_Caller_Ret { public: Function_Caller_Ret() { } Ret call(const std::vector > > &t_funcs, const std::vector ¶ms) { return boxed_cast(dispatch(t_funcs, params)); } }; template<> class Function_Caller_Ret { public: Function_Caller_Ret() { } void call(const std::vector > > &t_funcs, const std::vector ¶ms) { dispatch(t_funcs, params); } }; } #define BOOST_PP_ITERATION_LIMITS ( 0, 9 ) #define BOOST_PP_FILENAME_1 "function_call.hpp" #include BOOST_PP_ITERATE() namespace dispatchkit { template boost::function build_function_caller(const std::vector > > &funcs) { FunctionType *p; return build_function_caller_helper(p, funcs); } template boost::function build_function_caller(boost::shared_ptr func) { std::vector > > funcs; funcs.push_back(std::make_pair(std::string(), func)); return build_function_caller(funcs); } template boost::function build_function_caller(const Boxed_Value &bv) { return build_function_caller(boxed_cast >(bv)); } template boost::function build_functor(ScriptEngine &e, const std::string &script) { return build_function_caller(e.evaluate_string(script)); } } # endif #else # define n BOOST_PP_ITERATION() namespace dispatchkit { template Ret function_caller(const std::vector > > &funcs BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) { std::vector params; BOOST_PP_REPEAT(n, addparam, ~) return Function_Caller_Ret().call(funcs, params); } template boost::function build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector > > &funcs) { return boost::bind(&function_caller, funcs BOOST_PP_ENUM_TRAILING(n, curry, ~)); } } #endif