Drop boost::optional requirement

This commit is contained in:
Jason Turner 2011-09-11 06:56:15 -06:00
parent 0a9cb0cbe9
commit cd97880d70
3 changed files with 56 additions and 48 deletions

View File

@ -7,7 +7,6 @@
#ifndef CHAISCRIPT_DYNAMIC_OBJECT_HPP_
#define CHAISCRIPT_DYNAMIC_OBJECT_HPP_
#include <boost/optional.hpp>
namespace chaiscript
{
@ -66,16 +65,26 @@ namespace chaiscript
class Dynamic_Object_Function : public Proxy_Function_Base
{
public:
Dynamic_Object_Function(
const std::string &t_type_name,
const Proxy_Function &t_func)
: Proxy_Function_Base(t_func->get_param_types()),
m_type_name(t_type_name), m_func(t_func)
{
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
}
Dynamic_Object_Function(
const std::string &t_type_name,
const Proxy_Function &t_func,
const boost::optional<Type_Info> &t_ti = boost::optional<Type_Info>())
const Type_Info &t_ti)
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)),
m_type_name(t_type_name), m_func(t_func), m_ti(t_ti)
{
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
}
m_type_name(t_type_name), m_func(t_func), m_ti(new Type_Info(t_ti))
{
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
}
virtual ~Dynamic_Object_Function() {}
@ -137,23 +146,18 @@ namespace chaiscript
private:
static std::vector<Type_Info> build_param_types(
const std::vector<Type_Info> &t_inner_types, boost::optional<Type_Info> t_objectti)
const std::vector<Type_Info> &t_inner_types, const Type_Info& t_objectti)
{
if (t_objectti)
{
std::vector<Type_Info> types(t_inner_types);
std::vector<Type_Info> types(t_inner_types);
assert(types.size() > 1);
assert(types[1].bare_equal(user_type<Boxed_Value>()));
types[1] = *t_objectti;
return types;
} else {
return t_inner_types;
}
assert(types.size() > 1);
assert(types[1].bare_equal(user_type<Boxed_Value>()));
types[1] = t_objectti;
return types;
}
static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name,
const boost::optional<Type_Info> &ti)
const std::shared_ptr<Type_Info> &ti)
{
static Type_Info doti = user_type<Dynamic_Object>();
if (bv.get_type_info().bare_equal(doti))
@ -176,7 +180,7 @@ namespace chaiscript
}
static bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
const boost::optional<Type_Info> &ti)
const std::shared_ptr<Type_Info> &ti)
{
if (bvs.size() > 0)
{
@ -188,7 +192,7 @@ namespace chaiscript
std::string m_type_name;
Proxy_Function m_func;
boost::optional<Type_Info> m_ti;
std::shared_ptr<Type_Info> m_ti;
};
@ -207,10 +211,10 @@ namespace chaiscript
const Proxy_Function &t_func)
: Proxy_Function_Base(build_type_list(t_func->get_param_types())),
m_type_name(t_type_name), m_func(t_func)
{
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
}
{
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
}
static std::vector<Type_Info> build_type_list(const std::vector<Type_Info> &tl)
{

View File

@ -1117,19 +1117,23 @@ namespace chaiscript
}
else {
boost::optional<chaiscript::Type_Info> ti;
try {
ti = t_ss.get_type(class_name);
// Do know type name
t_ss.add(Proxy_Function
(new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function
(new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function,
std::ref(t_ss), this->children.back(),
t_param_names, std::placeholders::_1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)), t_ss.get_type(class_name))), function_name);
} catch (const std::range_error &) {
// No biggie, the type name is just not known
// Do not know type name
t_ss.add(Proxy_Function
(new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function
(new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function,
std::ref(t_ss), this->children.back(),
t_param_names, std::placeholders::_1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)))), function_name);
}
t_ss.add(Proxy_Function
(new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function
(new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function,
std::ref(t_ss), this->children.back(),
t_param_names, std::placeholders::_1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)), ti)), function_name);
}
}
catch (const exception::reserved_word_error &e) {

View File

@ -9,7 +9,7 @@
#include <list>
#include <chaiscript/chaiscript.hpp>
#include <boost/thread.hpp>
#include <thread>
void do_work(chaiscript::ChaiScript &c)
{
@ -20,21 +20,21 @@ void do_work(chaiscript::ChaiScript &c)
}
int main(int argc, char *argv[]) {
std::string input;
chaiscript::ChaiScript chai;
std::string input;
chaiscript::ChaiScript chai;
//chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations");
//chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations");
std::vector<std::shared_ptr<boost::thread> > threads;
std::vector<std::shared_ptr<std::thread> > threads;
for (int i = 0; i < argc - 1; ++i)
{
threads.push_back(std::shared_ptr<boost::thread>(new boost::thread(std::bind(do_work, std::ref(chai)))));
}
for (int i = 0; i < argc - 1; ++i)
{
threads.push_back(std::shared_ptr<std::thread>(new std::thread(std::bind(do_work, std::ref(chai)))));
}
for (int i = 0; i < argc - 1; ++i)
{
threads[i]->join();
}
for (int i = 0; i < argc - 1; ++i)
{
threads[i]->join();
}
}