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