2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-22 17:32:55 +00:00

add stl_input_iterator for wrapping a Python iterator in a STL input iterator

[SVN r31513]
This commit is contained in:
Eric Niebler
2005-10-31 18:49:54 +00:00
parent e2f59ef548
commit 6ec4387ea1
2 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
// Copyright Eric Niebler 2005.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef STL_ITERATOR_CORE_EAN20051028_HPP
# define STL_ITERATOR_CORE_EAN20051028_HPP
# include <boost/python/object_fwd.hpp>
# include <boost/python/handle_fwd.hpp>
namespace boost { namespace python { namespace objects {
struct BOOST_PYTHON_DECL stl_input_iterator_impl
{
stl_input_iterator_impl();
stl_input_iterator_impl(boost::python::object const &ob);
void increment();
bool equal(stl_input_iterator_impl const &that) const;
boost::python::handle<> const &current() const;
private:
boost::python::object it_;
boost::python::handle<> ob_;
};
}}} // namespace boost::python::object
#endif // STL_ITERATOR_CORE_EAN20051028_HPP

View File

@@ -0,0 +1,61 @@
// Copyright Eric Niebler 2005.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef STL_ITERATOR_EAN20051028_HPP
# define STL_ITERATOR_EAN20051028_HPP
# include <boost/python/detail/prefix.hpp>
# include <boost/python/object/stl_iterator_core.hpp>
# include <boost/iterator/iterator_facade.hpp>
namespace boost { namespace python
{
// An STL input iterator over a python sequence
template<typename ValueT>
struct stl_input_iterator
: boost::iterator_facade<
stl_input_iterator<ValueT>
, ValueT
, std::input_iterator_tag
, ValueT
>
{
stl_input_iterator()
: impl_()
{
}
// ob is the python sequence
stl_input_iterator(boost::python::object const &ob)
: impl_(ob)
{
}
private:
friend class iterator_core_access;
void increment()
{
this->impl_.increment();
}
ValueT dereference() const
{
return extract<ValueT>(this->impl_.current().get())();
}
bool equal(stl_input_iterator<ValueT> const &that) const
{
return this->impl_.equal(that.impl_);
}
objects::stl_input_iterator_impl impl_;
};
}} // namespace boost::python
#endif // STL_ITERATOR_EAN20051028_HPP