ESyS-Particle  2.3.4
PythonIterIterator.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 namespace esys
15 {
16  namespace lsm
17  {
18  namespace bpu
19  {
20  template <typename TmplExtractType>
22  boost::python::object &iteratable
23  )
24  : m_hasNext(true),
25  m_next(),
26  m_iter(iteratable.attr("__iter__")())
27  {
28  update();
29  }
30 
31  template <typename TmplExtractType>
33  {
34  return m_hasNext;
35  }
36 
37  template <typename TmplExtractType>
39  {
40  boost::python::object next = m_next;
41  update();
42  return boost::python::extract<TmplExtractType>(next);
43  }
44 
45  template <typename TmplExtractType>
47  {
48  try
49  {
50 #if PY_VERSION_HEX >= 0x03000000
51  m_next = m_iter.attr("__next__")();
52 #else
53  m_next = m_iter.attr("next")();
54 #endif
55  }
56  catch (boost::python::error_already_set &e)
57  {
58  if (!PyErr_ExceptionMatches(PyExc_StopIteration))
59  {
60  throw;
61  }
62  PyErr_Clear();
63  m_hasNext = false;
64  }
65  }
66  }
67  }
68 }
esys::lsm::bpu::PythonIterIterator::PythonIterIterator
PythonIterIterator(boost::python::object &iteratable)
Definition: PythonIterIterator.hpp:21
esys::lsm::bpu::PythonIterIterator::hasNext
bool hasNext() const
Definition: PythonIterIterator.hpp:32
esys::lsm::bpu::PythonIterIterator::update
void update()
Definition: PythonIterIterator.hpp:46
esys
Definition: CheckPointable.cpp:17
esys::lsm::bpu::PythonIterIterator::next
value_type next()
Definition: PythonIterIterator.hpp:38