Hi,
I'm stuck at trying to make python bindings for a set of classes that use a
non-c++-standard iteration protocol. I've made a minimal example of what
I'm trying to do:
the python-ized classes look in essence like this:
//-------------------------------------------------------------
class int_range
{
private:
int i, max;
public:
int_range(int m) : i(0), max(m) { }
bool empty(void) const { return i > max; }
int front(void) const { return i; }
void next(void) { ++i; }
};
class range_maker
{
public:
int_range make(void) const { return int_range(10); }
};
//-------------------------------------------------------------
the boost.python module that I've come up with so far:
//-------------------------------------------------------------
using namespace boost::python;
class _py_int_range_iter
{
private:
int_range _range;
public:
_py_int_range_iter(int_range range) : _range(range) { }
_py_int_range_iter self(void) { return *this; }
int next(void)
{
if(_range.empty())
objects::stop_iteration_error();
int result = _range.front();
_range.next();
return result;
}
};
class_<_py_int_range_iter>("_py_int_range_iter", init