]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/views/detail/points_view.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / geometry / views / detail / points_view.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
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.
6
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
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)
13
14 #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
15 #define BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP
16
17
18 #include <boost/range.hpp>
19 #include <boost/iterator/iterator_facade.hpp>
20 #include <boost/iterator/iterator_categories.hpp>
21
22 #include <boost/geometry/core/exception.hpp>
23
24 namespace boost { namespace geometry
25 {
26
27 namespace detail
28 {
29
30 // Adapts pointer, on points, to a Boost.Range
31 template <typename Point, int MaxSize>
32 class points_view
33 {
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
41 <
42 points_iterator,
43 Point const,
44 boost::random_access_traversal_tag
45 >
46 {
47 // Constructor: Begin iterator
48 inline points_iterator(Point const* p)
49 : m_points(p)
50 , m_index(0)
51 {}
52
53 // Constructor: End iterator
54 inline points_iterator(Point const* p, bool)
55 : m_points(p)
56 , m_index(MaxSize)
57 {}
58
59 // Constructor: default (for Range Concept checking).
60 inline points_iterator()
61 : m_points(NULL)
62 , m_index(MaxSize)
63 {}
64
65 typedef std::ptrdiff_t difference_type;
66
67 private:
68 friend class boost::iterator_core_access;
69
70 inline Point const& dereference() const
71 {
72 if (m_index >= 0 && m_index < MaxSize)
73 {
74 return m_points[m_index];
75 }
76
77 // If it index larger (or smaller) return first point
78 // (assuming initialized)
79 return m_points[0];
80 }
81
82 inline bool equal(points_iterator const& other) const
83 {
84 return other.m_index == this->m_index;
85 }
86
87 inline void increment()
88 {
89 m_index++;
90 }
91
92 inline void decrement()
93 {
94 m_index--;
95 }
96
97 inline difference_type distance_to(points_iterator const& other) const
98 {
99 return other.m_index - this->m_index;
100 }
101
102 inline void advance(difference_type n)
103 {
104 m_index += n;
105 }
106
107 Point const* m_points;
108 difference_type m_index;
109 };
110
111 public :
112
113 typedef points_iterator const_iterator;
114 typedef points_iterator iterator; // must be defined
115
116 const_iterator begin() const { return const_iterator(m_points); }
117 const_iterator end() const { return const_iterator(m_points, true); }
118
119 // It may NOT be used non-const, so commented:
120 //iterator begin() { return m_begin; }
121 //iterator end() { return m_end; }
122
123 protected :
124
125 template <typename CopyPolicy>
126 explicit points_view(CopyPolicy const& copy)
127 {
128 copy.apply(m_points);
129 }
130
131 private :
132 // Copy points here - box might define them otherwise
133 Point m_points[MaxSize];
134 };
135
136 }
137
138 }} // namespace boost::geometry
139
140
141 #endif // BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP