#include #define gettypeinfo(z,n,text) ti.push_back(Get_Type_Info()()); #define casthelper(z,n,text) ,Cast_Helper()(params[n]) #ifndef BOOST_PP_IS_ITERATING #ifndef __proxy_functions_hpp__ #define __proxy_functions_hpp__ #include "boxed_value.hpp" #include "type_info.hpp" #include #include #include #include #include // handle_return implementations template struct Handle_Return { Boxed_Value operator()(const boost::function &f) { return Boxed_Value(f()); } }; template struct Handle_Return { Boxed_Value operator()(const boost::function &f) { return Boxed_Value(boost::ref(f())); } }; template<> struct Handle_Return { Boxed_Value operator()(const boost::function &f) { f(); return Boxed_Value(); } }; // Build param type list (variadic) template std::vector build_param_type_list(const boost::function &f) { std::vector ti; ti.push_back(Get_Type_Info()()); return ti; } // call_func implementations (variadic) template Boxed_Value call_func(const boost::function &f, const std::vector ¶ms) { if (params.size() != 0) { throw std::range_error("Incorrect number of parameters"); } else { return Handle_Return()(f); } } struct Param_List_Builder { Param_List_Builder &operator<<(const Boxed_Value &so) { objects.push_back(so); return *this; } template Param_List_Builder &operator<<(T t) { objects.push_back(Boxed_Value(t)); return *this; } operator const std::vector &() const { return objects; } std::vector objects; }; #define BOOST_PP_ITERATION_LIMITS ( 1, 10 ) #define BOOST_PP_FILENAME_1 "proxy_functions.hpp" #include BOOST_PP_ITERATE() class Proxy_Function { public: virtual Boxed_Value operator()(const std::vector ¶ms) = 0; virtual std::vector get_param_types() = 0; }; template class Proxy_Function_Impl : public Proxy_Function { public: Proxy_Function_Impl(const Func &f) : m_f(f) { } virtual Boxed_Value operator()(const std::vector ¶ms) { return call_func(m_f, params); } virtual std::vector get_param_types() { return build_param_type_list(m_f); } private: Func m_f; }; # endif #else # define n BOOST_PP_ITERATION() template std::vector build_param_type_list(const boost::function &f) { std::vector ti; ti.push_back(Get_Type_Info()()); BOOST_PP_REPEAT(n, gettypeinfo, ~) return ti; } template Boxed_Value call_func(const boost::function &f, const std::vector ¶ms) { if (params.size() != n) { throw std::range_error("Incorrect number of parameters"); } else { return Handle_Return()(boost::bind(f BOOST_PP_REPEAT(n, casthelper, ~))); } } #endif