Add support for getting command argument types as a vector

This commit is contained in:
Jason Turner 2009-05-26 17:49:03 +00:00
parent 5424b6be41
commit 1980ba840c

View File

@ -3,13 +3,35 @@
#include "scripting_object.hpp"
#include "scripting_type_info.hpp"
#include <string>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <stdexcept>
#include <vector>
template<typename Ret>
std::vector<Type_Info> build_param_type_list(const boost::function<Ret ()> &f)
{
return std::vector<Type_Info>();
}
template<typename Ret, typename Param1>
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (Param1)> &f)
{
std::vector<Type_Info> ti;
ti.push_back(Get_Type_Info<Param1>()());
return ti;
}
template<typename Ret, typename Param1, typename Param2>
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (Param1, Param2)> &f)
{
std::vector<Type_Info> ti;
ti.push_back(Get_Type_Info<Param1>()());
ti.push_back(Get_Type_Info<Param2>()());
return ti;
}
// handle_return implementations
template<typename Ret>
@ -83,6 +105,8 @@ class Function_Handler
{
public:
virtual Scripting_Object operator()(const std::vector<Scripting_Object> &params) = 0;
virtual std::vector<Type_Info> get_param_types() = 0;
};
template<typename Func>
@ -99,6 +123,11 @@ class Function_Handler_Impl : public Function_Handler
return call_func(m_f, params);
}
virtual std::vector<Type_Info> get_param_types()
{
return build_param_type_list(m_f);
}
private:
Func m_f;
};
@ -125,7 +154,5 @@ std::vector<Scripting_Object> build_param_list(const Scripting_Object &so1, con
return sos;
}
#endif