ESyS-Particle  2.2.2
IteratorPy.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 #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  "next",
50  boost::python::return_internal_reference<>(),
51  (
52  std::string("Returns the next object in the sequence.\n")
53  +
54  "@rtype: L{" + pythonDocReturnType + "}\n"
55  +
56  "@raise StopIteration: if there is no next element."
57  ).c_str()
58  )
59  .def(
60  "__iter__",
61  boost::python::objects::identity_function(),
62  "Returns self."
63  )
64  ;
65  }
66  }
67 }
Definition: IteratorPy.h:28
TmplIterator Iterator
Definition: IteratorPy.h:31
Iterator::value_type value_type
Definition: IteratorPy.h:32
value_type next()
Definition: IteratorPy.hpp:27
IteratorPy(const Iterator &it)
Definition: IteratorPy.hpp:21
static void exportIterator(const std::string &pythonName, const std::string &pythonDocReturnType="object")
Definition: IteratorPy.hpp:38