]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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.hpp> | |
19 | #include <boost/iterator/iterator_facade.hpp> | |
20 | ||
21 | ||
22 | namespace boost { namespace geometry | |
23 | { | |
24 | ||
25 | namespace adapt { namespace bp | |
26 | { | |
27 | ||
28 | ||
29 | template <typename Polygon, typename RingProxy> | |
30 | class hole_iterator | |
31 | : public ::boost::iterator_facade | |
32 | < | |
33 | hole_iterator<Polygon, RingProxy>, | |
34 | RingProxy, // value type | |
35 | boost::forward_traversal_tag, | |
36 | RingProxy // reference type | |
37 | > | |
38 | { | |
39 | public : | |
40 | typedef typename boost::polygon::polygon_with_holes_traits | |
41 | < | |
42 | Polygon | |
43 | >::iterator_holes_type ith_type; | |
44 | ||
45 | explicit inline hole_iterator(Polygon& polygon, ith_type const it) | |
46 | : m_polygon(polygon) | |
47 | , m_base(it) | |
48 | { | |
49 | } | |
50 | ||
51 | typedef std::ptrdiff_t difference_type; | |
52 | ||
53 | private: | |
54 | friend class boost::iterator_core_access; | |
55 | ||
56 | inline RingProxy dereference() const | |
57 | { | |
58 | return RingProxy(m_polygon, this->m_base); | |
59 | } | |
60 | ||
61 | inline void increment() { ++m_base; } | |
62 | inline void decrement() { --m_base; } | |
63 | inline void advance(difference_type n) | |
64 | { | |
65 | for (int i = 0; i < n; i++) | |
66 | { | |
67 | ++m_base; | |
68 | } | |
69 | } | |
70 | ||
71 | inline bool equal(hole_iterator<Polygon, RingProxy> const& other) const | |
72 | { | |
73 | return this->m_base == other.m_base; | |
74 | } | |
75 | ||
76 | Polygon& m_polygon; | |
77 | ith_type m_base; | |
78 | }; | |
79 | ||
80 | ||
81 | }}}} | |
82 | ||
83 | #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLE_ITERATOR_HPP | |
84 |