#include #include "PyEO.h" #include "valueParam.h" using namespace boost::python; class StatBaseWrapper : public eoStatBase { public: PyObject* self; StatBaseWrapper(PyObject* p) : self(p) {} void operator()(const eoPop& pop) { call_method(self, "__call__", boost::ref(pop)); } }; class SortedStatBaseWrapper : public eoSortedStatBase { public: PyObject* self; SortedStatBaseWrapper(PyObject* p) : self(p) {} void operator()(const std::vector& pop) { call_method(self, "__call__", boost::ref(pop)); } }; typedef std::vector eoPopView; const PyEO& popview_getitem(const std::vector& pop, int it) { unsigned item = unsigned(it); if (item > pop.size()) throw index_error("too much"); return *pop[item]; } void statistics() { class_, StatBaseWrapper, boost::noncopyable> ("eoStatBase", init<>()) .def("lastCall", &eoStatBase::lastCall) .def("__call__", &StatBaseWrapper::operator()) ; class_< eoPopView >("eoPopView") .def("__getitem__", popview_getitem, return_internal_reference<>() ) .def("__len__", &eoPopView::size) ; class_, SortedStatBaseWrapper, boost::noncopyable> ("eoSortedStatBase", init<>()) .def("lastCall", &eoSortedStatBase::lastCall) .def("__call__", &SortedStatBaseWrapper::operator()) ; }