Commit 5da176c7 authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Got an interface for the main three types. But some functionalities are not accessible

thourgh the python interface.
parent 63eb852e
......@@ -8,4 +8,4 @@ env.Append(LIBS=['python2.7', 'boost_python-py27', 'core'])
env['SHLIBPREFIX']=''
env.SharedLibrary('../build/alta', ['alta.cpp'])
env.SharedLibrary('alta', ['alta.cpp'])
......@@ -41,10 +41,8 @@ struct my_vec : public vec {
};
// Creating a non purely virtual class for the function
struct Function : function, bp::wrapper<function>
{
vec value(const vec& x) const
{
struct Function : function, bp::wrapper<function> {
vec value(const vec& x) const {
return this->get_override("value")(x);
}
......@@ -53,6 +51,54 @@ struct Function : function, bp::wrapper<function>
}
};
// Creating a non purely virtual class for the data
struct Data : data, bp::wrapper<data> {
// Load data from a file
void load(const std::string& filename) {
this->get_override("load")(filename);
}
void load(const std::string& filename, const arguments& args) {
this->get_override("load")(filename, args);
}
vec get(int i) const {
return this->get_override("get")(i);
}
vec operator[](int i) const {
return this->get_override("operator[]")(i);
}
vec value(vec in) const {
return this->get_override("value")(in);
}
void set(vec x) {
this->get_override("set")(x);
}
int size() const {
return this->get_override("size")();
}
};
ptr<data> load_data(const std::string& plugin_name, const std::string& filename) {
ptr<data> d = plugins_manager::get_data(plugin_name);
d->load(filename);
return d;
}
// Creating a non purely virtual class for the function
struct Fitter : fitter, bp::wrapper<fitter> {
bool fit_data(const ptr<data>& d, ptr<function>& f, const arguments& args) {
return this->get_override("fit_data")(f, args);
}
void set_parameters(const arguments& args) {
this->get_override("set_parameters")(args);
}
};
// Creating functions for the plugins_manager calls
function* get_function(const std::string& filename) {
return plugins_manager::get_function(filename);
......@@ -68,6 +114,19 @@ BOOST_PYTHON_MODULE(alta)
bp::class_<Function, ptr<Function>, boost::noncopyable>("function")
.def("value", bp::pure_virtual(&function::value));
// Function interface
bp::def("get_function", get_function, bp::return_value_policy<bp::manage_new_object>());
// Data interface
bp::class_<Data, ptr<Data>, boost::noncopyable>("data")
// .def("load", bp::pure_virtual(&data::load))
.def("size", bp::pure_virtual(&data::size));
bp::def("get_data", plugins_manager::get_data);
bp::def("load_data", load_data);
bp::register_ptr_to_python< ptr<data> >();
// Fitter interface
bp::class_<Fitter, ptr<Fitter>, boost::noncopyable>("fitter");
bp::def("get_fitter", plugins_manager::get_fitter);
bp::register_ptr_to_python< ptr<fitter> >();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment