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/iterator_facade.hpp>
20 #include <boost/iterator/iterator_categories.hpp>
22 #include <boost/geometry/core/exception.hpp>
24 namespace boost { namespace geometry
30 // Adapts pointer, on points, to a Boost.Range
31 template <typename Point, int MaxSize>
34 // Iterates over a series of points (indicated by pointer
35 // to have it lightweight). Probably there is already an
36 // equivalent of this within Boost. If so, TODO: use that one.
37 // This used to be "box_iterator" and "segment_iterator".
38 // ALTERNATIVE: use boost:array and its iterators
39 struct points_iterator
40 : public boost::iterator_facade
44 boost::random_access_traversal_tag
47 // Constructor: Begin iterator
48 inline points_iterator(Point const* p)
53 // Constructor: End iterator
54 inline points_iterator(Point const* p, bool)
59 // Constructor: default (for Range Concept checking).
60 inline points_iterator()
65 typedef std::ptrdiff_t difference_type;
68 friend class boost::iterator_core_access;
70 inline Point const& dereference() const
72 if (m_index >= 0 && m_index < MaxSize)
74 return m_points[m_index];
77 // If it index larger (or smaller) return first point
78 // (assuming initialized)
82 inline bool equal(points_iterator const& other) const
84 return other.m_index == this->m_index;
87 inline void increment()
92 inline void decrement()
97 inline difference_type distance_to(points_iterator const& other) const
99 return other.m_index - this->m_index;
102 inline void advance(difference_type n)
107 Point const* m_points;
108 difference_type m_index;
113 typedef points_iterator const_iterator;
114 typedef points_iterator iterator; // must be defined
116 const_iterator begin() const { return const_iterator(m_points); }
117 const_iterator end() const { return const_iterator(m_points, true); }
119 // It may NOT be used non-const, so commented:
120 //iterator begin() { return m_begin; }
121 //iterator end() { return m_end; }
125 template <typename CopyPolicy>
126 explicit points_view(CopyPolicy const& copy)
128 copy.apply(m_points);
132 // Copy points here - box might define them otherwise
133 Point m_points[MaxSize];
138 }} // namespace boost::geometry
141 #endif // BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP