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 // 6 // Credits: 7 // Andreas Kl\:ockner for fixing increment() to handle 8 // error conditions. 9 10 #include <boost/python/object.hpp> 11 #include <boost/python/handle.hpp> 12 #include <boost/python/object/stl_iterator_core.hpp> 13 14 namespace boost { namespace python { namespace objects 15 { 16 stl_input_iterator_impl()17stl_input_iterator_impl::stl_input_iterator_impl() 18 : it_() 19 , ob_() 20 { 21 } 22 stl_input_iterator_impl(boost::python::object const & ob)23stl_input_iterator_impl::stl_input_iterator_impl(boost::python::object const &ob) 24 : it_(ob.attr("__iter__")()) 25 , ob_() 26 { 27 this->increment(); 28 } 29 increment()30void stl_input_iterator_impl::increment() 31 { 32 this->ob_ = boost::python::handle<>( 33 boost::python::allow_null(PyIter_Next(this->it_.ptr()))); 34 if (PyErr_Occurred()) 35 throw boost::python::error_already_set(); 36 } 37 equal(stl_input_iterator_impl const & that) const38bool stl_input_iterator_impl::equal(stl_input_iterator_impl const &that) const 39 { 40 return !this->ob_ == !that.ob_; 41 } 42 current() const43boost::python::handle<> const &stl_input_iterator_impl::current() const 44 { 45 return this->ob_; 46 } 47 48 }}} // namespace boost::python::objects 49