35 #ifndef __PYTHON_EXPR_H__
36 #define __PYTHON_EXPR_H__
38 #include "boost/tuple/tuple.hpp"
39 #include "boost/variant/get.hpp"
40 #include "boost/variant/variant.hpp"
42 #include <boost/python.hpp>
43 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
50 using namespace boost::python;
55 std::string script = boost::get<std::string>(args[0]);
56 std::vector<double> pargs;
57 for(
size_t i = 1; i < args.size(); i++) {
58 pargs.push_back(boost::get<double>(args[i]));
63 object main_module =
import(
"__main__");
64 object main_namespace = main_module.attr(
"__dict__");
66 boost::python::class_<std::vector<double> >(
"PyVec")
67 .def(boost::python::vector_indexing_suite<std::vector<double> >());
68 main_namespace[
"arguments"] = pargs;
70 object ignored = exec_file(script.c_str(), main_namespace);
71 double res = extract<double>(main_namespace[
"result"]);
74 return boost::make_tuple(res,
true);
76 }
catch (error_already_set) {
78 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)