Kris Thielemans
2015-05-31 18:35:23 UTC
Hi
I want to wrap some forward iterators (at present in Python). In my code, I
have n-dimensional arrays which have "flat" iterators (constructed using
begin_all(), end_all()) that go through all elements. Inspired by other
code, I did
%extend Array{
// add "flat" iterator, using begin_all()
%newobject flat(PyObject **PYTHON_SELF);
swig::SwigPyIterator* flat(PyObject **PYTHON_SELF) {
return swig::make_iterator(self->begin_all(), self->begin_all(),
self->end_all(), *PYTHON_SELF);
}
This fails, as my "flat" iterator is only a forward iterator at present.
I've solved this by (almost) copying SwigPyIteratorClosed_T from
pyiterator.swg to my own interface file to make a new type
SwigPyForwardIteratorClosed_T (which doesn't implement decr()).
I guess others could use this as well, but it then seems to make sense to
derive SwigPyIteratorClosed_T from SwigPyForwardIteratorClosed_T (and
similar for the open case).
Any opinions?
Kris
------------------------------------------------------------------------------
I want to wrap some forward iterators (at present in Python). In my code, I
have n-dimensional arrays which have "flat" iterators (constructed using
begin_all(), end_all()) that go through all elements. Inspired by other
code, I did
%extend Array{
// add "flat" iterator, using begin_all()
%newobject flat(PyObject **PYTHON_SELF);
swig::SwigPyIterator* flat(PyObject **PYTHON_SELF) {
return swig::make_iterator(self->begin_all(), self->begin_all(),
self->end_all(), *PYTHON_SELF);
}
This fails, as my "flat" iterator is only a forward iterator at present.
I've solved this by (almost) copying SwigPyIteratorClosed_T from
pyiterator.swg to my own interface file to make a new type
SwigPyForwardIteratorClosed_T (which doesn't implement decr()).
I guess others could use this as well, but it then seems to make sense to
derive SwigPyIteratorClosed_T from SwigPyForwardIteratorClosed_T (and
similar for the open case).
Any opinions?
Kris
------------------------------------------------------------------------------