Merge branch 'array_iterator_python' into 'master'

array iterator to python



See merge request !15
This commit is contained in:
Matthias Hochsteger 2016-11-15 18:20:59 +01:00
commit d98579fe6b
2 changed files with 5 additions and 0 deletions

View File

@ -60,6 +60,7 @@ namespace netgen
T operator*() const { return ar[ind]; }
T & operator*() { return ar[ind]; }
bool operator != (ArrayIterator d2) { return ind != d2.ind; }
bool operator == (ArrayIterator d2) { return ind == d2.ind; }
};

View File

@ -20,6 +20,7 @@ namespace netgen
template <typename T, int BASE = 0, typename TIND = int>
void ExportArray (py::module &m)
{
using TA = Array<T,BASE,TIND>;
string name = string("Array_") + typeid(T).name();
py::class_<Array<T,BASE,TIND>>(m, name.c_str())
.def ("__len__", [] ( Array<T,BASE,TIND> &self ) { return self.Size(); } )
@ -31,6 +32,9 @@ void ExportArray (py::module &m)
return self[i];
}),
py::return_value_policy::reference)
.def("__iter__", [] ( TA & self) {
return py::make_iterator (self.begin(),self.end());
}, py::keep_alive<0,1>()) // keep array alive while iterator is used
;
}