1 #ifndef __PYTHON_EXPR_H__
2 #define __PYTHON_EXPR_H__
4 #include "boost/tuple/tuple.hpp"
5 #include "boost/variant/get.hpp"
6 #include "boost/variant/variant.hpp"
8 #include <boost/python.hpp>
9 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
16 using namespace boost::python;
37 std::string script = boost::get<std::string>(args[0]);
38 std::vector<double> pargs;
39 for(
size_t i = 1; i < args.size(); i++) {
40 pargs.push_back(boost::get<double>(args[i]));
45 object main_module =
import(
"__main__");
46 object main_namespace = main_module.attr(
"__dict__");
48 boost::python::class_<std::vector<double> >(
"PyVec")
49 .def(boost::python::vector_indexing_suite<std::vector<double> >());
50 main_namespace[
"arguments"] = pargs;
52 object ignored = exec_file(script.c_str(), main_namespace);
53 double res = extract<double>(main_namespace[
"result"]);
56 return boost::make_tuple(res,
true);
58 }
catch (error_already_set) {
60 return boost::make_tuple(0.0,
false);
boost::tuple< double, bool > Result_t
std::vector< argument_t > arguments_t
Expressions::Result_t operator()(client::function::arguments_t args)