Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/range.hpp>
|
Chris@16
|
19 #include <boost/iterator.hpp>
|
Chris@16
|
20 #include <boost/iterator/iterator_facade.hpp>
|
Chris@16
|
21 #include <boost/iterator/iterator_categories.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/geometry/core/exception.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace geometry
|
Chris@16
|
26 {
|
Chris@16
|
27
|
Chris@16
|
28 namespace detail
|
Chris@16
|
29 {
|
Chris@16
|
30
|
Chris@16
|
31 // Adapts pointer, on points, to a Boost.Range
|
Chris@16
|
32 template <typename Point, int MaxSize>
|
Chris@16
|
33 class points_view
|
Chris@16
|
34 {
|
Chris@16
|
35 // Iterates over a series of points (indicated by pointer
|
Chris@16
|
36 // to have it lightweight). Probably there is already an
|
Chris@16
|
37 // equivalent of this within Boost. If so, TODO: use that one.
|
Chris@16
|
38 // This used to be "box_iterator" and "segment_iterator".
|
Chris@101
|
39 // ALTERNATIVE: use boost:array and its iterators
|
Chris@16
|
40 struct points_iterator
|
Chris@16
|
41 : public boost::iterator_facade
|
Chris@16
|
42 <
|
Chris@16
|
43 points_iterator,
|
Chris@16
|
44 Point const,
|
Chris@16
|
45 boost::random_access_traversal_tag
|
Chris@16
|
46 >
|
Chris@16
|
47 {
|
Chris@16
|
48 // Constructor: Begin iterator
|
Chris@16
|
49 inline points_iterator(Point const* p)
|
Chris@16
|
50 : m_points(p)
|
Chris@101
|
51 , m_index(0)
|
Chris@16
|
52 {}
|
Chris@16
|
53
|
Chris@16
|
54 // Constructor: End iterator
|
Chris@16
|
55 inline points_iterator(Point const* p, bool)
|
Chris@16
|
56 : m_points(p)
|
Chris@101
|
57 , m_index(MaxSize)
|
Chris@16
|
58 {}
|
Chris@16
|
59
|
Chris@16
|
60 // Constructor: default (for Range Concept checking).
|
Chris@16
|
61 inline points_iterator()
|
Chris@16
|
62 : m_points(NULL)
|
Chris@101
|
63 , m_index(MaxSize)
|
Chris@16
|
64 {}
|
Chris@101
|
65
|
Chris@16
|
66 typedef std::ptrdiff_t difference_type;
|
Chris@16
|
67
|
Chris@16
|
68 private:
|
Chris@16
|
69 friend class boost::iterator_core_access;
|
Chris@16
|
70
|
Chris@16
|
71 inline Point const& dereference() const
|
Chris@16
|
72 {
|
Chris@16
|
73 if (m_index >= 0 && m_index < MaxSize)
|
Chris@16
|
74 {
|
Chris@16
|
75 return m_points[m_index];
|
Chris@16
|
76 }
|
Chris@101
|
77
|
Chris@16
|
78 // If it index larger (or smaller) return first point
|
Chris@16
|
79 // (assuming initialized)
|
Chris@16
|
80 return m_points[0];
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@16
|
83 inline bool equal(points_iterator const& other) const
|
Chris@16
|
84 {
|
Chris@16
|
85 return other.m_index == this->m_index;
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 inline void increment()
|
Chris@16
|
89 {
|
Chris@16
|
90 m_index++;
|
Chris@16
|
91 }
|
Chris@16
|
92
|
Chris@16
|
93 inline void decrement()
|
Chris@16
|
94 {
|
Chris@16
|
95 m_index--;
|
Chris@16
|
96 }
|
Chris@16
|
97
|
Chris@16
|
98 inline difference_type distance_to(points_iterator const& other) const
|
Chris@16
|
99 {
|
Chris@16
|
100 return other.m_index - this->m_index;
|
Chris@16
|
101 }
|
Chris@101
|
102
|
Chris@16
|
103 inline void advance(difference_type n)
|
Chris@16
|
104 {
|
Chris@16
|
105 m_index += n;
|
Chris@16
|
106 }
|
Chris@16
|
107
|
Chris@16
|
108 Point const* m_points;
|
Chris@101
|
109 difference_type m_index;
|
Chris@16
|
110 };
|
Chris@16
|
111
|
Chris@16
|
112 public :
|
Chris@16
|
113
|
Chris@16
|
114 typedef points_iterator const_iterator;
|
Chris@16
|
115 typedef points_iterator iterator; // must be defined
|
Chris@16
|
116
|
Chris@16
|
117 const_iterator begin() const { return const_iterator(m_points); }
|
Chris@16
|
118 const_iterator end() const { return const_iterator(m_points, true); }
|
Chris@16
|
119
|
Chris@16
|
120 // It may NOT be used non-const, so commented:
|
Chris@16
|
121 //iterator begin() { return m_begin; }
|
Chris@16
|
122 //iterator end() { return m_end; }
|
Chris@16
|
123
|
Chris@16
|
124 protected :
|
Chris@16
|
125
|
Chris@16
|
126 template <typename CopyPolicy>
|
Chris@16
|
127 explicit points_view(CopyPolicy const& copy)
|
Chris@16
|
128 {
|
Chris@16
|
129 copy.apply(m_points);
|
Chris@16
|
130 }
|
Chris@101
|
131
|
Chris@101
|
132 private :
|
Chris@16
|
133 // Copy points here - box might define them otherwise
|
Chris@16
|
134 Point m_points[MaxSize];
|
Chris@16
|
135 };
|
Chris@16
|
136
|
Chris@16
|
137 }
|
Chris@16
|
138
|
Chris@16
|
139 }} // namespace boost::geometry
|
Chris@16
|
140
|
Chris@16
|
141
|
Chris@16
|
142 #endif // BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
|