Skip to content

Commit ee83f57

Browse files
committed
[test] add custom, non copiable, non indexable geometries
1 parent 83dab2d commit ee83f57

23 files changed

+1908
-2
lines changed

include/boost/geometry/geometries/concepts/multi_linestring_concept.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public :
4949
traits::clear<Geometry>::apply(*mls);
5050
traits::resize<Geometry>::apply(*mls, 0);
5151
linestring_type* ls = 0;
52-
traits::push_back<Geometry>::apply(*mls, *ls);
52+
traits::push_back<Geometry>::apply(*mls, std::move(*ls));
5353
}
5454
#endif
5555
};

include/boost/geometry/geometries/concepts/multi_polygon_concept.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public :
4848
Geometry* mp = 0;
4949
traits::clear<Geometry>::apply(*mp);
5050
traits::resize<Geometry>::apply(*mp, 0);
51+
// The concept should support the second version of push_back, using &&
5152
polygon_type* poly = 0;
52-
traits::push_back<Geometry>::apply(*mp, *poly);
53+
traits::push_back<Geometry>::apply(*mp, std::move(*poly));
5354
}
5455
#endif
5556
};

include/boost/geometry/geometry.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,7 @@
131131
#include <boost/geometry/io/wkt/read.hpp>
132132
#include <boost/geometry/io/wkt/write.hpp>
133133

134+
#include <boost/geometry/algorithms/is_convex.hpp>
135+
#include <boost/geometry/algorithms/point_on_surface.hpp>
136+
134137
#endif // BOOST_GEOMETRY_GEOMETRY_HPP

test/geometries/Jamfile

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ test-suite boost-geometry-geometries
3838
[ run segment.cpp : : : : geometries_segment ]
3939
[ run infinite_line.cpp : : : : geometries_infinite_line ]
4040
;
41+
42+
build-project custom_non_copiable ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Boost.Geometry
2+
#
3+
# Copyright (c) 2023 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+
test-suite boost-geometry-geometries-custom-non-copiable
10+
:
11+
[ run custom_ring.cpp : : : : cnc_ring ]
12+
[ run custom_polygon.cpp : : : : cnc_polygon ]
13+
[ run custom_multi_polygon.cpp : : : : cnc_multi_polygon ]
14+
[ run custom_linestring.cpp : : : : cnc_linestring ]
15+
[ run custom_multi_linestring.cpp : : : : cnc_multi_linestring ]
16+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Boost.Geometry
2+
3+
// Copyright (c) 2023 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+
10+
#ifndef GEOMETRY_TEST_ADAPT_CNC_CONTAINER_HPP
11+
#define GEOMETRY_TEST_ADAPT_CNC_CONTAINER_HPP
12+
13+
#include "cnc_container.hpp"
14+
15+
// 1. Adapt to Boost.Geometry
16+
namespace boost { namespace geometry { namespace traits
17+
{
18+
19+
template <typename Item>
20+
struct clear<cnc_container<Item> >
21+
{
22+
static void apply(cnc_container<Item>& container)
23+
{
24+
container.custom_clear();
25+
}
26+
};
27+
28+
template <typename Item>
29+
struct push_back<cnc_container<Item> >
30+
{
31+
static void apply(cnc_container<Item>& container, Item const& item)
32+
{
33+
container.custom_push_back(item);
34+
}
35+
static void apply(cnc_container<Item>& container, Item&& item)
36+
{
37+
container.custom_push_back(std::move(item));
38+
}
39+
};
40+
41+
template <typename Item>
42+
struct resize<cnc_container<Item> >
43+
{
44+
static void apply(cnc_container<Item>& container, std::size_t new_size)
45+
{
46+
container.custom_resize(new_size);
47+
}
48+
};
49+
50+
}}} // namespace boost::geometry::traits
51+
52+
53+
// 2a. Adapt to Boost.Range, meta-functions
54+
namespace boost
55+
{
56+
template<typename Item>
57+
struct range_mutable_iterator<cnc_container<Item> >
58+
{
59+
using type = decltype(std::declval<cnc_container<Item>>().custom_begin());
60+
};
61+
62+
template<typename Item>
63+
struct range_const_iterator<cnc_container<Item> >
64+
{
65+
using type = decltype(std::declval<cnc_container<Item>>().const_custom_begin());
66+
};
67+
68+
69+
} // namespace boost
70+
71+
72+
// 2b. Adapt to Boost.Range, part 2, ADP
73+
template<typename Item>
74+
auto range_begin(cnc_container<Item>& container) { return container.custom_begin(); }
75+
76+
template<typename Item>
77+
auto range_begin(cnc_container<Item> const& container) { return container.const_custom_begin(); }
78+
79+
template<typename Item>
80+
auto range_end(cnc_container<Item>& container) { return container.custom_end(); }
81+
82+
template<typename Item>
83+
auto range_end(cnc_container<Item> const& container) { return container.const_custom_end(); }
84+
85+
template<typename Item>
86+
std::size_t range_calculate_size(cnc_container<Item> const& container) { return container.custom_size(); }
87+
88+
89+
90+
91+
92+
#endif // GEOMETRY_TEST_ADAPT_CNC_CONTAINER_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Boost.Geometry
2+
3+
// Copyright (c) 2023 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+
10+
#ifndef GEOMETRY_TEST_ADAPT_CNC_LINESTRING_HPP
11+
#define GEOMETRY_TEST_ADAPT_CNC_LINESTRING_HPP
12+
13+
#include "cnc_linestring.hpp"
14+
15+
// 1. Adapt to Boost.Geometry
16+
namespace boost { namespace geometry { namespace traits
17+
{
18+
19+
template <typename Point>
20+
struct tag<cnc_linestring<Point>>
21+
{
22+
using type = linestring_tag;
23+
};
24+
25+
// Implement traits for mutable actions
26+
// These are all optional traits (normally / default they are implemented
27+
// conforming std:: functionality)
28+
29+
template <typename Point>
30+
struct clear<cnc_linestring<Point> >
31+
{
32+
static void apply(cnc_linestring<Point>& geo)
33+
{
34+
geo.custom_clear();
35+
}
36+
};
37+
38+
template <typename Point>
39+
struct push_back<cnc_linestring<Point> >
40+
{
41+
static void apply(cnc_linestring<Point>& geo, Point const& point)
42+
{
43+
geo.custom_push_back(point);
44+
}
45+
};
46+
47+
template <typename Point>
48+
struct resize<cnc_linestring<Point> >
49+
{
50+
static void apply(cnc_linestring<Point>& geo, std::size_t new_size)
51+
{
52+
geo.custom_resize(new_size);
53+
}
54+
};
55+
56+
57+
}}}
58+
59+
// 2a. Adapt to Boost.Range, meta-functions
60+
namespace boost
61+
{
62+
63+
template<typename Point>
64+
struct range_mutable_iterator<cnc_linestring<Point> >
65+
{
66+
using type = decltype(std::declval<cnc_linestring<Point>>().custom_begin());
67+
};
68+
69+
template<typename Point>
70+
struct range_const_iterator<cnc_linestring<Point> >
71+
{
72+
using type = decltype(std::declval<cnc_linestring<Point>>().const_custom_begin());
73+
};
74+
75+
}
76+
77+
// 2b. Adapt to Boost.Range, part 2, ADP
78+
template<typename Point>
79+
auto range_begin(cnc_linestring<Point>& geo) { return geo.custom_begin(); }
80+
81+
template<typename Point>
82+
auto range_begin(cnc_linestring<Point> const& geo) { return geo.const_custom_begin(); }
83+
84+
template<typename Point>
85+
auto range_end(cnc_linestring<Point>& geo) { return geo.custom_end(); }
86+
87+
template<typename Point>
88+
auto range_end(cnc_linestring<Point> const& geo) { return geo.const_custom_end(); }
89+
90+
template<typename Point>
91+
std::size_t range_calculate_size(cnc_linestring<Point> const& geo) { return geo.custom_size(); }
92+
93+
#endif // GEOMETRY_TEST_ADAPT_CNC_LINESTRING_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Boost.Geometry
2+
3+
// Copyright (c) 2023 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+
10+
#ifndef GEOMETRY_TEST_ADAPT_CNC_MULTI_LINESTRING_HPP
11+
#define GEOMETRY_TEST_ADAPT_CNC_MULTI_LINESTRING_HPP
12+
13+
#include "cnc_multi_linestring.hpp"
14+
15+
// 1. Adapt to Boost.Geometry
16+
namespace boost { namespace geometry { namespace traits
17+
{
18+
19+
template <typename Linestring>
20+
struct tag<cnc_multi_linestring<Linestring>>
21+
{
22+
using type = multi_linestring_tag;
23+
};
24+
25+
template <typename Linestring>
26+
struct clear<cnc_multi_linestring<Linestring> >
27+
{
28+
static void apply(cnc_multi_linestring<Linestring>& multi)
29+
{
30+
multi.custom_clear();
31+
}
32+
};
33+
34+
template <typename Linestring>
35+
struct push_back<cnc_multi_linestring<Linestring> >
36+
{
37+
static void apply(cnc_multi_linestring<Linestring>& multi, Linestring const& item)
38+
{
39+
multi.custom_push_back(item);
40+
}
41+
static inline void apply(cnc_multi_linestring<Linestring>& multi, Linestring&& item)
42+
{
43+
multi.custom_push_back_move(std::move(item));
44+
}
45+
};
46+
47+
template <typename Linestring>
48+
struct resize<cnc_multi_linestring<Linestring> >
49+
{
50+
static void apply(cnc_multi_linestring<Linestring>& multi, std::size_t new_size)
51+
{
52+
multi.custom_resize(new_size);
53+
}
54+
};
55+
56+
57+
}}}
58+
59+
// 2a. Adapt to Boost.Range, meta-functions
60+
namespace boost
61+
{
62+
63+
template<typename Linestring>
64+
struct range_mutable_iterator<cnc_multi_linestring<Linestring> >
65+
{
66+
using type = decltype(std::declval<cnc_multi_linestring<Linestring>>().custom_begin());
67+
};
68+
69+
template<typename Linestring>
70+
struct range_const_iterator<cnc_multi_linestring<Linestring> >
71+
{
72+
using type = decltype(std::declval<cnc_multi_linestring<Linestring>>().const_custom_begin());
73+
};
74+
75+
}
76+
77+
// 2b. Adapt to Boost.Range, part 2, ADP
78+
template<typename Linestring>
79+
auto range_begin(cnc_multi_linestring<Linestring>& geo) { return geo.custom_begin(); }
80+
81+
template<typename Linestring>
82+
auto range_begin(cnc_multi_linestring<Linestring> const& geo) { return geo.const_custom_begin(); }
83+
84+
template<typename Linestring>
85+
auto range_end(cnc_multi_linestring<Linestring>& geo) { return geo.custom_end(); }
86+
87+
template<typename Linestring>
88+
auto range_end(cnc_multi_linestring<Linestring> const& geo) { return geo.const_custom_end(); }
89+
90+
template<typename Linestring>
91+
std::size_t range_calculate_size(cnc_multi_linestring<Linestring> const& geo) { return geo.custom_size(); }
92+
93+
#endif // GEOMETRY_TEST_ADAPT_CNC_MULTI_LINESTRING_HPP

0 commit comments

Comments
 (0)