hole_iterator.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLE_ITERATOR_HPP
  7. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLE_ITERATOR_HPP
  8. // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
  9. // boost::polygon::polygon_with_holes_data -> boost::geometry::polygon
  10. // hole_iterator -> returning ring_proxy's instead of normal polygon_data
  11. #include <boost/polygon/polygon.hpp>
  12. #include <boost/iterator/iterator_facade.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. namespace adapt { namespace bp
  16. {
  17. template <typename Polygon, typename RingProxy>
  18. class hole_iterator
  19. : public ::boost::iterator_facade
  20. <
  21. hole_iterator<Polygon, RingProxy>,
  22. RingProxy, // value type
  23. boost::forward_traversal_tag,
  24. RingProxy // reference type
  25. >
  26. {
  27. public :
  28. typedef typename boost::polygon::polygon_with_holes_traits
  29. <
  30. Polygon
  31. >::iterator_holes_type ith_type;
  32. explicit inline hole_iterator(Polygon& polygon, ith_type const it)
  33. : m_polygon(polygon)
  34. , m_base(it)
  35. {
  36. }
  37. typedef std::ptrdiff_t difference_type;
  38. private:
  39. friend class boost::iterator_core_access;
  40. inline RingProxy dereference() const
  41. {
  42. return RingProxy(m_polygon, this->m_base);
  43. }
  44. inline void increment() { ++m_base; }
  45. inline void decrement() { --m_base; }
  46. inline void advance(difference_type n)
  47. {
  48. for (int i = 0; i < n; i++)
  49. {
  50. ++m_base;
  51. }
  52. }
  53. inline bool equal(hole_iterator<Polygon, RingProxy> const& other) const
  54. {
  55. return this->m_base == other.m_base;
  56. }
  57. Polygon& m_polygon;
  58. ith_type m_base;
  59. };
  60. }}}}
  61. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLE_ITERATOR_HPP