ESyS-Particle  2.3.4
IteratorPy.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 
14 #include <boost/python/iterator.hpp>
15 
16 namespace esys
17 {
18  namespace lsm
19  {
20  template<typename TmplIterator>
22  {
23  }
24 
25  template<typename TmplIterator>
28  {
29  if (m_it.hasNext())
30  {
31  return m_it.next();
32  }
33  boost::python::objects::stop_iteration_error();
34  return m_it.next(); // to avoid compiler warning
35  }
36 
37  template <typename TmplIterator>
39  const std::string &pythonName,
40  const std::string &pythonDocReturnType
41  )
42  {
43  boost::python::class_<IteratorPy<TmplIterator> >(
44  pythonName.c_str(),
45  boost::python::no_init
46  )
47  .def(
48 #if PY_VERSION_HEX >= 0x03000000
49  "__next__",
50 #else
51  "next",
52 #endif
54  boost::python::return_internal_reference<>(),
55  (
56  std::string("Returns the next object in the sequence.\n")
57  +
58  "@rtype: L{" + pythonDocReturnType + "}\n"
59  +
60  "@raise StopIteration: if there is no next element."
61  ).c_str()
62  )
63  .def(
64  "__iter__",
65  boost::python::objects::identity_function(),
66  "Returns self."
67  )
68  ;
69  }
70  }
71 }
esys::lsm::IteratorPy::exportIterator
static void exportIterator(const std::string &pythonName, const std::string &pythonDocReturnType="object")
Definition: IteratorPy.hpp:38
esys
Definition: CheckPointable.cpp:17
esys::lsm::IteratorPy::next
value_type next()
Definition: IteratorPy.hpp:27
esys::lsm::IteratorPy::Iterator
TmplIterator Iterator
Definition: IteratorPy.h:31
esys::lsm::IteratorPy::value_type
Iterator::value_type value_type
Definition: IteratorPy.h:32
esys::lsm::IteratorPy
Definition: IteratorPy.h:29
esys::lsm::IteratorPy::IteratorPy
IteratorPy(const Iterator &it)
Definition: IteratorPy.hpp:21