ESyS-Particle  2.2.2
PythonIterIterator.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2013 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
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  m_next = m_iter.attr("next")();
51  }
52  catch (boost::python::error_already_set &e)
53  {
54  if (!PyErr_ExceptionMatches(PyExc_StopIteration))
55  {
56  throw;
57  }
58  PyErr_Clear();
59  m_hasNext = false;
60  }
61  }
62  }
63  }
64 }
bool hasNext() const
Definition: PythonIterIterator.hpp:32
value_type next()
Definition: PythonIterIterator.hpp:38
void update()
Definition: PythonIterIterator.hpp:46
PythonIterIterator(boost::python::object &iteratable)
Definition: PythonIterIterator.hpp:21