Developer Documentation
Iterator.hh
1 #ifndef OPENMESH_PYTHON_ITERATOR_HH
2 #define OPENMESH_PYTHON_ITERATOR_HH
3 
4 #include "Python/Bindings.hh"
5 
6 namespace OpenMesh {
7 namespace Python {
8 
20 template<class Iterator, size_t (OpenMesh::ArrayKernel::*n_items)() const>
22  public:
23 
31  IteratorWrapperT(const PolyMesh& _mesh, typename Iterator::value_type _hnd, bool _skip = false) :
32  mesh_(_mesh), n_items_(n_items),
33  iterator_(_mesh, _hnd, _skip),
34  iterator_end_(_mesh, typename Iterator::value_type(int((_mesh.*n_items)()))) {
35  }
36 
44  IteratorWrapperT(const TriMesh& _mesh, typename Iterator::value_type _hnd, bool _skip = false) :
45  mesh_(_mesh), n_items_(n_items),
46  iterator_(_mesh, _hnd, _skip),
47  iterator_end_(_mesh, typename Iterator::value_type(int((_mesh.*n_items)()))) {
48  }
49 
56  return *this;
57  }
58 
65  typename Iterator::value_type next() {
66  if (iterator_ != iterator_end_) {
67  typename Iterator::value_type res = *iterator_;
68  ++iterator_;
69  return res;
70  }
71  else {
72  PyErr_SetString(PyExc_StopIteration, "No more data.");
73  boost::python::throw_error_already_set();
74  }
75  return typename Iterator::value_type();
76  }
77 
83  unsigned int len() const {
84  return (mesh_.*n_items_)();
85  }
86 
87  private:
88  const OpenMesh::PolyConnectivity& mesh_;
89  size_t (OpenMesh::ArrayKernel::*n_items_)() const;
90  Iterator iterator_;
91  Iterator iterator_end_;
92 };
93 
107 template<class Iterator, size_t (OpenMesh::ArrayKernel::*n_items)() const>
108 void expose_iterator(const char *_name) {
109  class_<IteratorWrapperT<Iterator, n_items> >(_name, init<PolyMesh&, typename Iterator::value_type, optional<bool> >())
110  .def(init<TriMesh&, typename Iterator::value_type, optional<bool> >())
115  ;
116 }
117 
118 } // namespace OpenMesh
119 } // namespace Python
120 
121 #endif
IteratorWrapperT(const TriMesh &_mesh, typename Iterator::value_type _hnd, bool _skip=false)
Definition: Iterator.hh:44
Iterator::value_type next()
Definition: Iterator.hh:65
IteratorWrapperT iter() const
Definition: Iterator.hh:55
IteratorWrapperT(const PolyMesh &_mesh, typename Iterator::value_type _hnd, bool _skip=false)
Definition: Iterator.hh:31
Connectivity Class for polygonal meshes.
void expose_iterator(const char *_name)
Definition: Iterator.hh:108
unsigned int len() const
Definition: Iterator.hh:83