1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
15 #define BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
18 #include <boost/range.hpp>
19 #include <boost/iterator.hpp>
20 #include <boost/iterator/iterator_facade.hpp>
21 #include <boost/iterator/iterator_categories.hpp>
23 #include <boost/geometry/core/exception.hpp>
25 namespace boost { namespace geometry
31 // Adapts pointer, on points, to a Boost.Range
32 template <typename Point, int MaxSize>
35 // Iterates over a series of points (indicated by pointer
36 // to have it lightweight). Probably there is already an
37 // equivalent of this within Boost. If so, TODO: use that one.
38 // This used to be "box_iterator" and "segment_iterator".
39 // ALTERNATIVE: use boost:array and its iterators
40 struct points_iterator
41 : public boost::iterator_facade
45 boost::random_access_traversal_tag
48 // Constructor: Begin iterator
49 inline points_iterator(Point const* p)
54 // Constructor: End iterator
55 inline points_iterator(Point const* p, bool)
60 // Constructor: default (for Range Concept checking).
61 inline points_iterator()
66 typedef std::ptrdiff_t difference_type;
69 friend class boost::iterator_core_access;
71 inline Point const& dereference() const
73 if (m_index >= 0 && m_index < MaxSize)
75 return m_points[m_index];
78 // If it index larger (or smaller) return first point
79 // (assuming initialized)
83 inline bool equal(points_iterator const& other) const
85 return other.m_index == this->m_index;
88 inline void increment()
93 inline void decrement()
98 inline difference_type distance_to(points_iterator const& other) const
100 return other.m_index - this->m_index;
103 inline void advance(difference_type n)
108 Point const* m_points;
109 difference_type m_index;
114 typedef points_iterator const_iterator;
115 typedef points_iterator iterator; // must be defined
117 const_iterator begin() const { return const_iterator(m_points); }
118 const_iterator end() const { return const_iterator(m_points, true); }
120 // It may NOT be used non-const, so commented:
121 //iterator begin() { return m_begin; }
122 //iterator end() { return m_end; }
126 template <typename CopyPolicy>
127 explicit points_view(CopyPolicy const& copy)
129 copy.apply(m_points);
133 // Copy points here - box might define them otherwise
134 Point m_points[MaxSize];
139 }} // namespace boost::geometry
142 #endif // BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP