Rename scripting_* files to something a bit more appropriate

This commit is contained in:
Jason Turner 2009-05-27 01:05:47 +00:00
parent 6a608f995a
commit 079f3478f8
6 changed files with 59 additions and 59 deletions

View File

@ -1,39 +1,39 @@
#ifndef __scripting_object_hpp__ #ifndef __boxed_value_hpp__
#define __scripting_object_hpp__ #define __boxed_value_hpp__
#include "scripting_type_info.hpp" #include "type_info.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/any.hpp> #include <boost/any.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
class Scripting_Object class Boxed_Value
{ {
public: public:
template<typename T> template<typename T>
explicit Scripting_Object(boost::shared_ptr<T> obj) explicit Boxed_Value(boost::shared_ptr<T> obj)
: m_type_info(Get_Type_Info<T>()()), m_obj(obj), m_is_ref(false) : m_type_info(Get_Type_Info<T>()()), m_obj(obj), m_is_ref(false)
{ {
} }
template<typename T> template<typename T>
explicit Scripting_Object(boost::reference_wrapper<T> obj) explicit Boxed_Value(boost::reference_wrapper<T> obj)
: m_type_info(Get_Type_Info<T>()()), m_obj(obj), m_is_ref(true) : m_type_info(Get_Type_Info<T>()()), m_obj(obj), m_is_ref(true)
{ {
} }
template<typename T> template<typename T>
explicit Scripting_Object(const T& t) explicit Boxed_Value(const T& t)
: m_type_info(Get_Type_Info<T>()()), m_obj(boost::shared_ptr<T>(new T(t))), m_is_ref(false) : m_type_info(Get_Type_Info<T>()()), m_obj(boost::shared_ptr<T>(new T(t))), m_is_ref(false)
{ {
} }
Scripting_Object(const Scripting_Object &t_so) Boxed_Value(const Boxed_Value &t_so)
: m_type_info(t_so.m_type_info), m_obj(t_so.m_obj), m_is_ref(t_so.m_is_ref) : m_type_info(t_so.m_type_info), m_obj(t_so.m_obj), m_is_ref(t_so.m_is_ref)
{ {
} }
Scripting_Object() Boxed_Value()
: m_type_info(Get_Type_Info<void>()()), m_is_ref(false) : m_type_info(Get_Type_Info<void>()()), m_is_ref(false)
{ {
} }
@ -64,7 +64,7 @@ class Scripting_Object
template<typename Result> template<typename Result>
struct Cast_Helper struct Cast_Helper
{ {
typename boost::reference_wrapper<typename boost::add_const<Result>::type > operator()(Scripting_Object ob) typename boost::reference_wrapper<typename boost::add_const<Result>::type > operator()(Boxed_Value ob)
{ {
if (ob.is_ref()) if (ob.is_ref())
{ {
@ -78,7 +78,7 @@ struct Cast_Helper
template<typename Result> template<typename Result>
struct Cast_Helper<const Result &> struct Cast_Helper<const Result &>
{ {
typename boost::reference_wrapper<typename boost::add_const<Result>::type > operator()(Scripting_Object ob) typename boost::reference_wrapper<typename boost::add_const<Result>::type > operator()(Boxed_Value ob)
{ {
if (ob.is_ref()) if (ob.is_ref())
{ {
@ -92,7 +92,7 @@ struct Cast_Helper<const Result &>
template<typename Result> template<typename Result>
struct Cast_Helper<Result *> struct Cast_Helper<Result *>
{ {
Result *operator()(Scripting_Object ob) Result *operator()(Boxed_Value ob)
{ {
if (ob.is_ref()) if (ob.is_ref())
{ {
@ -106,7 +106,7 @@ struct Cast_Helper<Result *>
template<typename Result> template<typename Result>
struct Cast_Helper<Result &> struct Cast_Helper<Result &>
{ {
typename boost::reference_wrapper<Result> operator()(Scripting_Object ob) typename boost::reference_wrapper<Result> operator()(Boxed_Value ob)
{ {
if (ob.is_ref()) if (ob.is_ref())
{ {

View File

@ -8,9 +8,9 @@
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
#include "scripting_object.hpp" #include "boxed_value.hpp"
#include "scripting_functions.hpp" #include "proxy_functions.hpp"
#include "scripting_constructors.hpp" #include "proxy_constructors.hpp"
class Scripting_System class Scripting_System
{ {
@ -18,18 +18,18 @@ class Scripting_System
template<typename Function> template<typename Function>
void register_function(const Function &func, const std::string &name) void register_function(const Function &func, const std::string &name)
{ {
m_functions.insert(std::make_pair(name, boost::shared_ptr<Function_Handler>(new Function_Handler_Impl<Function>(func)))); m_functions.insert(std::make_pair(name, boost::shared_ptr<Proxy_Function>(new Proxy_Function_Impl<Function>(func))));
} }
template<typename Class> template<typename Class>
void add_object(const std::string &name, const Class &obj) void add_object(const std::string &name, const Class &obj)
{ {
m_objects.insert(std::make_pair(name, Scripting_Object(obj))); m_objects.insert(std::make_pair(name, Boxed_Value(obj)));
} }
Scripting_Object get_object(const std::string &name) const Boxed_Value get_object(const std::string &name) const
{ {
std::map<std::string, Scripting_Object>::const_iterator itr = m_objects.find(name); std::map<std::string, Boxed_Value>::const_iterator itr = m_objects.find(name);
if (itr != m_objects.end()) if (itr != m_objects.end())
{ {
return itr->second; return itr->second;
@ -44,9 +44,9 @@ class Scripting_System
m_types.insert(std::make_pair(name, &typeid(Type))); m_types.insert(std::make_pair(name, &typeid(Type)));
} }
boost::shared_ptr<Function_Handler> get_function(const std::string &t_name) boost::shared_ptr<Proxy_Function> get_function(const std::string &t_name)
{ {
std::map<std::string, boost::shared_ptr<Function_Handler> >::const_iterator itr = m_functions.find(t_name); std::map<std::string, boost::shared_ptr<Proxy_Function> >::const_iterator itr = m_functions.find(t_name);
if (itr != m_functions.end()) if (itr != m_functions.end())
{ {
return itr->second; return itr->second;
@ -56,9 +56,9 @@ class Scripting_System
} }
private: private:
std::map<std::string, Scripting_Object > m_objects; std::map<std::string, Boxed_Value > m_objects;
std::map<std::string, const std::type_info *> m_types; std::map<std::string, const std::type_info *> m_types;
std::map<std::string, boost::shared_ptr<Function_Handler> > m_functions; std::map<std::string, boost::shared_ptr<Proxy_Function> > m_functions;
}; };
#endif #endif

View File

@ -1,8 +1,8 @@
#include <boost/preprocessor.hpp> #include <boost/preprocessor.hpp>
#ifndef BOOST_PP_IS_ITERATING #ifndef BOOST_PP_IS_ITERATING
#ifndef __scripting_constructors_hpp__ #ifndef __proxy_constructors_hpp__
#define __scripting_constructors_hpp__ #define __proxy_constructors_hpp__
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -22,7 +22,7 @@ boost::function<boost::shared_ptr<Class> ()> build_constructor()
} }
#define BOOST_PP_ITERATION_LIMITS ( 1, 10 ) #define BOOST_PP_ITERATION_LIMITS ( 1, 10 )
#define BOOST_PP_FILENAME_1 "scripting_constructors.hpp" #define BOOST_PP_FILENAME_1 "proxy_constructors.hpp"
#include BOOST_PP_ITERATE() #include BOOST_PP_ITERATE()
# endif # endif
#else #else

View File

@ -5,11 +5,11 @@
#ifndef BOOST_PP_IS_ITERATING #ifndef BOOST_PP_IS_ITERATING
#ifndef __scripting_functions_hpp__ #ifndef __proxy_functions_hpp__
#define __scripting_functions_hpp__ #define __proxy_functions_hpp__
#include "scripting_object.hpp" #include "boxed_value.hpp"
#include "scripting_type_info.hpp" #include "type_info.hpp"
#include <string> #include <string>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -20,28 +20,28 @@
template<typename Ret> template<typename Ret>
struct Handle_Return struct Handle_Return
{ {
Scripting_Object operator()(const boost::function<Ret ()> &f) Boxed_Value operator()(const boost::function<Ret ()> &f)
{ {
return Scripting_Object(f()); return Boxed_Value(f());
} }
}; };
template<typename Ret> template<typename Ret>
struct Handle_Return<Ret &> struct Handle_Return<Ret &>
{ {
Scripting_Object operator()(const boost::function<Ret &()> &f) Boxed_Value operator()(const boost::function<Ret &()> &f)
{ {
return Scripting_Object(boost::ref(f())); return Boxed_Value(boost::ref(f()));
} }
}; };
template<> template<>
struct Handle_Return<void> struct Handle_Return<void>
{ {
Scripting_Object operator()(const boost::function<void ()> &f) Boxed_Value operator()(const boost::function<void ()> &f)
{ {
f(); f();
return Scripting_Object(); return Boxed_Value();
} }
}; };
@ -57,7 +57,7 @@ std::vector<Type_Info> build_param_type_list(const boost::function<Ret ()> &f)
// call_func implementations (variadic) // call_func implementations (variadic)
template<typename Ret> template<typename Ret>
Scripting_Object call_func(const boost::function<Ret ()> &f, const std::vector<Scripting_Object> &params) Boxed_Value call_func(const boost::function<Ret ()> &f, const std::vector<Boxed_Value> &params)
{ {
if (params.size() != 0) if (params.size() != 0)
{ {
@ -70,7 +70,7 @@ Scripting_Object call_func(const boost::function<Ret ()> &f, const std::vector<S
struct Param_List_Builder struct Param_List_Builder
{ {
Param_List_Builder &operator<<(const Scripting_Object &so) Param_List_Builder &operator<<(const Boxed_Value &so)
{ {
objects.push_back(so); objects.push_back(so);
return *this; return *this;
@ -79,42 +79,42 @@ struct Param_List_Builder
template<typename T> template<typename T>
Param_List_Builder &operator<<(T t) Param_List_Builder &operator<<(T t)
{ {
objects.push_back(Scripting_Object(t)); objects.push_back(Boxed_Value(t));
return *this; return *this;
} }
operator const std::vector<Scripting_Object> &() const operator const std::vector<Boxed_Value> &() const
{ {
return objects; return objects;
} }
std::vector<Scripting_Object> objects; std::vector<Boxed_Value> objects;
}; };
#define BOOST_PP_ITERATION_LIMITS ( 1, 10 ) #define BOOST_PP_ITERATION_LIMITS ( 1, 10 )
#define BOOST_PP_FILENAME_1 "scripting_functions.hpp" #define BOOST_PP_FILENAME_1 "proxy_functions.hpp"
#include BOOST_PP_ITERATE() #include BOOST_PP_ITERATE()
class Function_Handler class Proxy_Function
{ {
public: public:
virtual Scripting_Object operator()(const std::vector<Scripting_Object> &params) = 0; virtual Boxed_Value operator()(const std::vector<Boxed_Value> &params) = 0;
virtual std::vector<Type_Info> get_param_types() = 0; virtual std::vector<Type_Info> get_param_types() = 0;
}; };
template<typename Func> template<typename Func>
class Function_Handler_Impl : public Function_Handler class Proxy_Function_Impl : public Proxy_Function
{ {
public: public:
Function_Handler_Impl(const Func &f) Proxy_Function_Impl(const Func &f)
: m_f(f) : m_f(f)
{ {
} }
virtual Scripting_Object operator()(const std::vector<Scripting_Object> &params) virtual Boxed_Value operator()(const std::vector<Boxed_Value> &params)
{ {
return call_func(m_f, params); return call_func(m_f, params);
} }
@ -146,8 +146,8 @@ std::vector<Type_Info> build_param_type_list(const boost::function<Ret (BOOST_PP
} }
template<typename Ret, BOOST_PP_ENUM_PARAMS(n, typename Param)> template<typename Ret, BOOST_PP_ENUM_PARAMS(n, typename Param)>
Scripting_Object call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f, Boxed_Value call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f,
const std::vector<Scripting_Object> &params) const std::vector<Boxed_Value> &params)
{ {
if (params.size() != n) if (params.size() != n)
{ {

View File

@ -4,7 +4,7 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include "scripting_system.hpp" #include "boxedcpp.hpp"
struct Test struct Test
{ {
@ -69,14 +69,14 @@ int main()
ss.add_object("d", boost::shared_ptr<double>(new double(10.2))); ss.add_object("d", boost::shared_ptr<double>(new double(10.2)));
ss.add_object("str", std::string("Hello World")); ss.add_object("str", std::string("Hello World"));
std::vector<Scripting_Object> sos; std::vector<Boxed_Value> sos;
sos.push_back(ss.get_object("testobj")); sos.push_back(ss.get_object("testobj"));
sos.push_back(ss.get_object("d")); sos.push_back(ss.get_object("d"));
boost::shared_ptr<Function_Handler> method1(ss.get_function("method")); boost::shared_ptr<Proxy_Function> method1(ss.get_function("method"));
(*method1)(sos); (*method1)(sos);
(*method1)(sos); (*method1)(sos);
Scripting_Object o = (*method1)(sos); Boxed_Value o = (*method1)(sos);
(*ss.get_function("print"))(Param_List_Builder() << ss.get_object("str")); (*ss.get_function("print"))(Param_List_Builder() << ss.get_object("str"));
@ -85,13 +85,13 @@ int main()
std::cout << Cast_Helper<int>()(o) << std::endl; std::cout << Cast_Helper<int>()(o) << std::endl;
(*ss.get_function("voidfunc"))(std::vector<Scripting_Object>()); (*ss.get_function("voidfunc"))(std::vector<Boxed_Value>());
std::vector<Scripting_Object> sos3; std::vector<Boxed_Value> sos3;
sos3.push_back(ss.get_object("testobj2")); sos3.push_back(ss.get_object("testobj2"));
(*ss.get_function("show_message"))(sos3); (*ss.get_function("show_message"))(sos3);
Scripting_Object stringref = (*ss.get_function("get_message"))(sos3); Boxed_Value stringref = (*ss.get_function("get_message"))(sos3);
std::string &sr = Cast_Helper<std::string &>()(stringref); std::string &sr = Cast_Helper<std::string &>()(stringref);
sr = "Bob Updated The message"; sr = "Bob Updated The message";

View File

@ -1,5 +1,5 @@
#ifndef __scripting_type_info_hpp__ #ifndef __type_info_hpp__
#define __scripting_type_info_hpp__ #define __type_info_hpp__
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>