• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 
11 #ifndef GEOMETRY_TEST_TEST_GEOMETRIES_WRAPPED_BOOST_ARRAY_HPP
12 #define GEOMETRY_TEST_TEST_GEOMETRIES_WRAPPED_BOOST_ARRAY_HPP
13 
14 #include <cstddef>
15 
16 #include <boost/array.hpp>
17 #include <boost/range.hpp>
18 
19 #include <boost/geometry/core/mutable_range.hpp>
20 #include <boost/geometry/core/tag.hpp>
21 #include <boost/geometry/core/tags.hpp>
22 
23 
24 namespace test
25 {
26 
27 template <typename Point, std::size_t Count>
28 struct wrapped_boost_array
29 {
wrapped_boost_arraytest::wrapped_boost_array30     inline wrapped_boost_array() : size(0) {}
31 
32     boost::array<Point, Count> array;
33     std::size_t size;
34 };
35 
36 
37 } // namespace test
38 
39 
40 // 1a: adapt to Boost.Range
41 namespace boost
42 {
43     using namespace test;
44 
45     template <typename Point, std::size_t Count>
46     struct range_mutable_iterator<wrapped_boost_array<Point, Count> >
47         : public range_mutable_iterator<boost::array<Point, Count> >
48     {};
49 
50     template <typename Point, std::size_t Count>
51     struct range_const_iterator<wrapped_boost_array<Point, Count> >
52         : public range_const_iterator<boost::array<Point, Count> >
53     {};
54 
55 
56 } // namespace 'boost'
57 
58 
59 // 1b) adapt to Boost.Range with ADP
60 namespace test
61 {
62     template <typename Point, std::size_t Count>
63     inline typename boost::range_iterator
64         <
65             wrapped_boost_array<Point, Count>
range_begin(wrapped_boost_array<Point,Count> & ar)66         >::type range_begin(wrapped_boost_array<Point, Count>& ar)
67     {
68         return ar.array.begin();
69     }
70 
71     template <typename Point, std::size_t Count>
72     inline typename boost::range_iterator
73         <
74             wrapped_boost_array<Point, Count> const
range_begin(wrapped_boost_array<Point,Count> const & ar)75         >::type range_begin(wrapped_boost_array<Point, Count> const& ar)
76     {
77         return ar.array.begin();
78     }
79 
80     template <typename Point, std::size_t Count>
81     inline typename boost::range_iterator
82         <
83             wrapped_boost_array<Point, Count>
range_end(wrapped_boost_array<Point,Count> & ar)84         >::type range_end(wrapped_boost_array<Point, Count>& ar)
85     {
86         typename boost::range_iterator
87             <
88                 wrapped_boost_array<Point, Count>
89             >::type it = ar.array.begin();
90         return it + ar.size;
91     }
92 
93     template <typename Point, std::size_t Count>
94     inline typename boost::range_iterator
95         <
96             wrapped_boost_array<Point, Count> const
range_end(wrapped_boost_array<Point,Count> const & ar)97         >::type range_end(wrapped_boost_array<Point, Count> const& ar)
98     {
99         typename boost::range_iterator
100             <
101                 wrapped_boost_array<Point, Count> const
102             >::type it = ar.array.begin();
103         return it + ar.size;
104     }
105 
106 }
107 
108 
109 // 2: adapt to Boost.Geometry
110 namespace boost { namespace geometry { namespace traits
111 {
112 
113     template <typename Point, std::size_t Count>
114     struct tag< wrapped_boost_array<Point, Count> >
115     {
116         typedef linestring_tag type;
117     };
118 
119     template <typename Point, std::size_t Count>
120     struct clear< wrapped_boost_array<Point, Count> >
121     {
applyboost::geometry::traits::clear122         static inline void apply(wrapped_boost_array<Point, Count>& ar)
123         {
124             ar.size = 0;
125         }
126     };
127 
128     template <typename Point, std::size_t Count>
129     struct push_back< wrapped_boost_array<Point, Count> >
130     {
applyboost::geometry::traits::push_back131         static inline void apply(wrapped_boost_array<Point, Count>& ar, Point const& point)
132         {
133             // BOOST_ASSERT((ar.size < Count));
134             ar.array[ar.size++] = point;
135         }
136     };
137 
138     template <typename Point, std::size_t Count>
139     struct resize< wrapped_boost_array<Point, Count> >
140     {
applyboost::geometry::traits::resize141         static inline void apply(wrapped_boost_array<Point, Count>& ar, std::size_t new_size)
142         {
143             BOOST_ASSERT(new_size < Count);
144             ar.size = new_size;
145         }
146     };
147 
148 }}} // namespace bg::traits
149 
150 
151 #endif // GEOMETRY_TEST_TEST_GEOMETRIES_WRAPPED_BOOST_ARRAY_HPP
152