Skip to content

Commit 6ec4387

Browse files
author
Eric Niebler
committed
add stl_input_iterator for wrapping a Python iterator in a STL input iterator
[SVN r31513]
1 parent e2f59ef commit 6ec4387

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright Eric Niebler 2005.
2+
// Distributed under the Boost Software License, Version 1.0. (See
3+
// accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
#ifndef STL_ITERATOR_CORE_EAN20051028_HPP
6+
# define STL_ITERATOR_CORE_EAN20051028_HPP
7+
8+
# include <boost/python/object_fwd.hpp>
9+
# include <boost/python/handle_fwd.hpp>
10+
11+
namespace boost { namespace python { namespace objects {
12+
13+
struct BOOST_PYTHON_DECL stl_input_iterator_impl
14+
{
15+
stl_input_iterator_impl();
16+
stl_input_iterator_impl(boost::python::object const &ob);
17+
void increment();
18+
bool equal(stl_input_iterator_impl const &that) const;
19+
boost::python::handle<> const &current() const;
20+
private:
21+
boost::python::object it_;
22+
boost::python::handle<> ob_;
23+
};
24+
25+
}}} // namespace boost::python::object
26+
27+
#endif // STL_ITERATOR_CORE_EAN20051028_HPP
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright Eric Niebler 2005.
2+
// Distributed under the Boost Software License, Version 1.0. (See
3+
// accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
#ifndef STL_ITERATOR_EAN20051028_HPP
6+
# define STL_ITERATOR_EAN20051028_HPP
7+
8+
# include <boost/python/detail/prefix.hpp>
9+
10+
# include <boost/python/object/stl_iterator_core.hpp>
11+
12+
# include <boost/iterator/iterator_facade.hpp>
13+
14+
namespace boost { namespace python
15+
{
16+
17+
// An STL input iterator over a python sequence
18+
template<typename ValueT>
19+
struct stl_input_iterator
20+
: boost::iterator_facade<
21+
stl_input_iterator<ValueT>
22+
, ValueT
23+
, std::input_iterator_tag
24+
, ValueT
25+
>
26+
{
27+
stl_input_iterator()
28+
: impl_()
29+
{
30+
}
31+
32+
// ob is the python sequence
33+
stl_input_iterator(boost::python::object const &ob)
34+
: impl_(ob)
35+
{
36+
}
37+
38+
private:
39+
friend class iterator_core_access;
40+
41+
void increment()
42+
{
43+
this->impl_.increment();
44+
}
45+
46+
ValueT dereference() const
47+
{
48+
return extract<ValueT>(this->impl_.current().get())();
49+
}
50+
51+
bool equal(stl_input_iterator<ValueT> const &that) const
52+
{
53+
return this->impl_.equal(that.impl_);
54+
}
55+
56+
objects::stl_input_iterator_impl impl_;
57+
};
58+
59+
}} // namespace boost::python
60+
61+
#endif // STL_ITERATOR_EAN20051028_HPP

0 commit comments

Comments
 (0)