Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / geometry / geometries / adapted / boost_polygon / ring.hpp
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_RING_HPP
10 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP
11
12 // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
13 // boost::polygon::polygon_data -> boost::geometry::ring
14
15 #include <cstddef>
16 #include <boost/polygon/polygon.hpp>
17
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/cs.hpp>
20 #include <boost/geometry/core/coordinate_dimension.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/core/mutable_range.hpp>
23 #include <boost/geometry/core/tags.hpp>
24
25
26 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
27
28 namespace boost { namespace geometry
29 {
30
31 namespace traits
32 {
33
34 template <typename CoordinateType>
35 struct tag<boost::polygon::polygon_data<CoordinateType> >
36 {
37     typedef ring_tag type;
38 };
39
40 template <typename CoordinateType>
41 struct clear<boost::polygon::polygon_data<CoordinateType> >
42 {
43     static inline void apply(boost::polygon::polygon_data<CoordinateType>& data)
44     {
45         // There is no "clear" function but we can assign
46         // a newly (and therefore empty) constructed polygon
47         boost::polygon::assign(data, boost::polygon::polygon_data<CoordinateType>());
48     }
49 };
50
51 template <typename CoordinateType>
52 struct push_back<boost::polygon::polygon_data<CoordinateType> >
53 {
54     typedef boost::polygon::point_data<CoordinateType> point_type;
55
56     static inline void apply(boost::polygon::polygon_data<CoordinateType>& data,
57          point_type const& point)
58     {
59         // Boost.Polygon's polygons are not appendable. So create a temporary vector,
60         // add a record and set it to the original. Of course: this is not efficient.
61         // But there seems no other way (without using a wrapper)
62         std::vector<point_type> temporary_vector
63             (
64                 boost::polygon::begin_points(data),
65                 boost::polygon::end_points(data)
66             );
67         temporary_vector.push_back(point);
68         data.set(temporary_vector.begin(), temporary_vector.end());
69     }
70 };
71
72 template <typename CoordinateType>
73 struct resize<boost::polygon::polygon_data<CoordinateType> >
74 {
75     typedef boost::polygon::point_data<CoordinateType> point_type;
76
77     static inline void apply(boost::polygon::polygon_data<CoordinateType>& data,
78                              std::size_t new_size)
79     {
80         // Boost.Polygon's polygons are not resizable. So create a temporary vector,
81         // resize it and set it to the original. Of course: this is not efficient.
82         // But there seems no other way (without using a wrapper)
83         std::vector<point_type> temporary_vector
84             (
85                 boost::polygon::begin_points(data),
86                 boost::polygon::end_points(data)
87             );
88         temporary_vector.resize(new_size);
89         data.set(temporary_vector.begin(), temporary_vector.end());
90     }
91 };
92
93
94 } // namespace traits
95
96 }} // namespace boost::geometry
97
98
99 // Adapt Boost.Polygon's polygon_data to Boost.Range
100 // This just translates to
101 // polygon_data.begin() and polygon_data.end()
102 namespace boost
103 {
104     template<typename CoordinateType>
105     struct range_mutable_iterator<boost::polygon::polygon_data<CoordinateType> >
106     {
107         typedef typename boost::polygon::polygon_traits
108             <
109                 boost::polygon::polygon_data<CoordinateType>
110             >::iterator_type type;
111     };
112
113     template<typename CoordinateType>
114     struct range_const_iterator<boost::polygon::polygon_data<CoordinateType> >
115     {
116         typedef typename boost::polygon::polygon_traits
117             <
118                 boost::polygon::polygon_data<CoordinateType>
119             >::iterator_type type;
120     };
121
122     template<typename CoordinateType>
123     struct range_size<boost::polygon::polygon_data<CoordinateType> >
124     {
125         typedef std::size_t type;
126     };
127
128 } // namespace boost
129
130
131 // Support Boost.Polygon's polygon_data for Boost.Range ADP
132 namespace boost { namespace polygon
133 {
134
135 template<typename CoordinateType>
136 inline typename polygon_traits
137         <
138             polygon_data<CoordinateType>
139         >::iterator_type range_begin(polygon_data<CoordinateType>& polygon)
140 {
141     return polygon.begin();
142 }
143
144 template<typename CoordinateType>
145 inline typename polygon_traits
146         <
147             polygon_data<CoordinateType>
148         >::iterator_type range_begin(polygon_data<CoordinateType> const& polygon)
149 {
150     return polygon.begin();
151 }
152
153 template<typename CoordinateType>
154 inline typename polygon_traits
155         <
156             polygon_data<CoordinateType>
157         >::iterator_type range_end(polygon_data<CoordinateType>& polygon)
158 {
159     return polygon.end();
160 }
161
162 template<typename CoordinateType>
163 inline typename polygon_traits
164         <
165             polygon_data<CoordinateType>
166         >::iterator_type range_end(polygon_data<CoordinateType> const& polygon)
167 {
168     return polygon.end();
169 }
170
171 template<typename CoordinateType>
172 inline std::size_t range_calculate_size(polygon_data<CoordinateType> const& polygon)
173 {
174     return polygon.size();
175 }
176
177 }}
178
179 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
180
181
182 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP