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