stl_iterator.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/object/stl_iterator_core.hpp>
  9. # include <boost/iterator/iterator_facade.hpp>
  10. namespace boost { namespace python
  11. {
  12. // An STL input iterator over a python sequence
  13. template<typename ValueT>
  14. struct stl_input_iterator
  15. : boost::iterator_facade<
  16. stl_input_iterator<ValueT>
  17. , ValueT
  18. , std::input_iterator_tag
  19. , ValueT
  20. >
  21. {
  22. stl_input_iterator()
  23. : impl_()
  24. {
  25. }
  26. // ob is the python sequence
  27. stl_input_iterator(boost::python::object const &ob)
  28. : impl_(ob)
  29. {
  30. }
  31. private:
  32. friend class boost::iterator_core_access;
  33. void increment()
  34. {
  35. this->impl_.increment();
  36. }
  37. ValueT dereference() const
  38. {
  39. return extract<ValueT>(this->impl_.current().get())();
  40. }
  41. bool equal(stl_input_iterator<ValueT> const &that) const
  42. {
  43. return this->impl_.equal(that.impl_);
  44. }
  45. objects::stl_input_iterator_impl impl_;
  46. };
  47. }} // namespace boost::python
  48. #endif // STL_ITERATOR_EAN20051028_HPP