diff --git a/include/boost/python/object/stl_iterator_core.hpp b/include/boost/python/object/stl_iterator_core.hpp new file mode 100755 index 00000000..68e0c244 --- /dev/null +++ b/include/boost/python/object/stl_iterator_core.hpp @@ -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 +# include + +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 ¤t() const; +private: + boost::python::object it_; + boost::python::handle<> ob_; +}; + +}}} // namespace boost::python::object + +#endif // STL_ITERATOR_CORE_EAN20051028_HPP diff --git a/include/boost/python/stl_iterator.hpp b/include/boost/python/stl_iterator.hpp new file mode 100755 index 00000000..87456d1f --- /dev/null +++ b/include/boost/python/stl_iterator.hpp @@ -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 + +# include + +# include + +namespace boost { namespace python +{ + +// An STL input iterator over a python sequence +template +struct stl_input_iterator + : boost::iterator_facade< + stl_input_iterator + , 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(this->impl_.current().get())(); + } + + bool equal(stl_input_iterator const &that) const + { + return this->impl_.equal(that.impl_); + } + + objects::stl_input_iterator_impl impl_; +}; + +}} // namespace boost::python + +#endif // STL_ITERATOR_EAN20051028_HPP