Skip to content

Commit

Permalink
[test] add custom, non copiable, non indexable geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
barendgehrels committed Apr 23, 2023
1 parent 83dab2d commit ee83f57
Show file tree
Hide file tree
Showing 23 changed files with 1,908 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public :
traits::clear<Geometry>::apply(*mls);
traits::resize<Geometry>::apply(*mls, 0);
linestring_type* ls = 0;
traits::push_back<Geometry>::apply(*mls, *ls);
traits::push_back<Geometry>::apply(*mls, std::move(*ls));
}
#endif
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public :
Geometry* mp = 0;
traits::clear<Geometry>::apply(*mp);
traits::resize<Geometry>::apply(*mp, 0);
// The concept should support the second version of push_back, using &&
polygon_type* poly = 0;
traits::push_back<Geometry>::apply(*mp, *poly);
traits::push_back<Geometry>::apply(*mp, std::move(*poly));
}
#endif
};
Expand Down
3 changes: 3 additions & 0 deletions include/boost/geometry/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,7 @@
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/io/wkt/write.hpp>

#include <boost/geometry/algorithms/is_convex.hpp>
#include <boost/geometry/algorithms/point_on_surface.hpp>

#endif // BOOST_GEOMETRY_GEOMETRY_HPP
2 changes: 2 additions & 0 deletions test/geometries/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ test-suite boost-geometry-geometries
[ run segment.cpp : : : : geometries_segment ]
[ run infinite_line.cpp : : : : geometries_infinite_line ]
;

build-project custom_non_copiable ;
16 changes: 16 additions & 0 deletions test/geometries/custom_non_copiable/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Boost.Geometry
#
# Copyright (c) 2023 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)

test-suite boost-geometry-geometries-custom-non-copiable
:
[ run custom_ring.cpp : : : : cnc_ring ]
[ run custom_polygon.cpp : : : : cnc_polygon ]
[ run custom_multi_polygon.cpp : : : : cnc_multi_polygon ]
[ run custom_linestring.cpp : : : : cnc_linestring ]
[ run custom_multi_linestring.cpp : : : : cnc_multi_linestring ]
;
92 changes: 92 additions & 0 deletions test/geometries/custom_non_copiable/adapt_cnc_container.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Boost.Geometry

// Copyright (c) 2023 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_ADAPT_CNC_CONTAINER_HPP
#define GEOMETRY_TEST_ADAPT_CNC_CONTAINER_HPP

#include "cnc_container.hpp"

// 1. Adapt to Boost.Geometry
namespace boost { namespace geometry { namespace traits
{

template <typename Item>
struct clear<cnc_container<Item> >
{
static void apply(cnc_container<Item>& container)
{
container.custom_clear();
}
};

template <typename Item>
struct push_back<cnc_container<Item> >
{
static void apply(cnc_container<Item>& container, Item const& item)
{
container.custom_push_back(item);
}
static void apply(cnc_container<Item>& container, Item&& item)
{
container.custom_push_back(std::move(item));
}
};

template <typename Item>
struct resize<cnc_container<Item> >
{
static void apply(cnc_container<Item>& container, std::size_t new_size)
{
container.custom_resize(new_size);
}
};

}}} // namespace boost::geometry::traits


// 2a. Adapt to Boost.Range, meta-functions
namespace boost
{
template<typename Item>
struct range_mutable_iterator<cnc_container<Item> >
{
using type = decltype(std::declval<cnc_container<Item>>().custom_begin());
};

template<typename Item>
struct range_const_iterator<cnc_container<Item> >
{
using type = decltype(std::declval<cnc_container<Item>>().const_custom_begin());
};


} // namespace boost


// 2b. Adapt to Boost.Range, part 2, ADP
template<typename Item>
auto range_begin(cnc_container<Item>& container) { return container.custom_begin(); }

template<typename Item>
auto range_begin(cnc_container<Item> const& container) { return container.const_custom_begin(); }

template<typename Item>
auto range_end(cnc_container<Item>& container) { return container.custom_end(); }

template<typename Item>
auto range_end(cnc_container<Item> const& container) { return container.const_custom_end(); }

template<typename Item>
std::size_t range_calculate_size(cnc_container<Item> const& container) { return container.custom_size(); }





#endif // GEOMETRY_TEST_ADAPT_CNC_CONTAINER_HPP
93 changes: 93 additions & 0 deletions test/geometries/custom_non_copiable/adapt_cnc_linestring.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Boost.Geometry

// Copyright (c) 2023 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_ADAPT_CNC_LINESTRING_HPP
#define GEOMETRY_TEST_ADAPT_CNC_LINESTRING_HPP

#include "cnc_linestring.hpp"

// 1. Adapt to Boost.Geometry
namespace boost { namespace geometry { namespace traits
{

template <typename Point>
struct tag<cnc_linestring<Point>>
{
using type = linestring_tag;
};

// Implement traits for mutable actions
// These are all optional traits (normally / default they are implemented
// conforming std:: functionality)

template <typename Point>
struct clear<cnc_linestring<Point> >
{
static void apply(cnc_linestring<Point>& geo)
{
geo.custom_clear();
}
};

template <typename Point>
struct push_back<cnc_linestring<Point> >
{
static void apply(cnc_linestring<Point>& geo, Point const& point)
{
geo.custom_push_back(point);
}
};

template <typename Point>
struct resize<cnc_linestring<Point> >
{
static void apply(cnc_linestring<Point>& geo, std::size_t new_size)
{
geo.custom_resize(new_size);
}
};


}}}

// 2a. Adapt to Boost.Range, meta-functions
namespace boost
{

template<typename Point>
struct range_mutable_iterator<cnc_linestring<Point> >
{
using type = decltype(std::declval<cnc_linestring<Point>>().custom_begin());
};

template<typename Point>
struct range_const_iterator<cnc_linestring<Point> >
{
using type = decltype(std::declval<cnc_linestring<Point>>().const_custom_begin());
};

}

// 2b. Adapt to Boost.Range, part 2, ADP
template<typename Point>
auto range_begin(cnc_linestring<Point>& geo) { return geo.custom_begin(); }

template<typename Point>
auto range_begin(cnc_linestring<Point> const& geo) { return geo.const_custom_begin(); }

template<typename Point>
auto range_end(cnc_linestring<Point>& geo) { return geo.custom_end(); }

template<typename Point>
auto range_end(cnc_linestring<Point> const& geo) { return geo.const_custom_end(); }

template<typename Point>
std::size_t range_calculate_size(cnc_linestring<Point> const& geo) { return geo.custom_size(); }

#endif // GEOMETRY_TEST_ADAPT_CNC_LINESTRING_HPP
93 changes: 93 additions & 0 deletions test/geometries/custom_non_copiable/adapt_cnc_multi_linestring.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Boost.Geometry

// Copyright (c) 2023 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_ADAPT_CNC_MULTI_LINESTRING_HPP
#define GEOMETRY_TEST_ADAPT_CNC_MULTI_LINESTRING_HPP

#include "cnc_multi_linestring.hpp"

// 1. Adapt to Boost.Geometry
namespace boost { namespace geometry { namespace traits
{

template <typename Linestring>
struct tag<cnc_multi_linestring<Linestring>>
{
using type = multi_linestring_tag;
};

template <typename Linestring>
struct clear<cnc_multi_linestring<Linestring> >
{
static void apply(cnc_multi_linestring<Linestring>& multi)
{
multi.custom_clear();
}
};

template <typename Linestring>
struct push_back<cnc_multi_linestring<Linestring> >
{
static void apply(cnc_multi_linestring<Linestring>& multi, Linestring const& item)
{
multi.custom_push_back(item);
}
static inline void apply(cnc_multi_linestring<Linestring>& multi, Linestring&& item)
{
multi.custom_push_back_move(std::move(item));
}
};

template <typename Linestring>
struct resize<cnc_multi_linestring<Linestring> >
{
static void apply(cnc_multi_linestring<Linestring>& multi, std::size_t new_size)
{
multi.custom_resize(new_size);
}
};


}}}

// 2a. Adapt to Boost.Range, meta-functions
namespace boost
{

template<typename Linestring>
struct range_mutable_iterator<cnc_multi_linestring<Linestring> >
{
using type = decltype(std::declval<cnc_multi_linestring<Linestring>>().custom_begin());
};

template<typename Linestring>
struct range_const_iterator<cnc_multi_linestring<Linestring> >
{
using type = decltype(std::declval<cnc_multi_linestring<Linestring>>().const_custom_begin());
};

}

// 2b. Adapt to Boost.Range, part 2, ADP
template<typename Linestring>
auto range_begin(cnc_multi_linestring<Linestring>& geo) { return geo.custom_begin(); }

template<typename Linestring>
auto range_begin(cnc_multi_linestring<Linestring> const& geo) { return geo.const_custom_begin(); }

template<typename Linestring>
auto range_end(cnc_multi_linestring<Linestring>& geo) { return geo.custom_end(); }

template<typename Linestring>
auto range_end(cnc_multi_linestring<Linestring> const& geo) { return geo.const_custom_end(); }

template<typename Linestring>
std::size_t range_calculate_size(cnc_multi_linestring<Linestring> const& geo) { return geo.custom_size(); }

#endif // GEOMETRY_TEST_ADAPT_CNC_MULTI_LINESTRING_HPP
Loading

0 comments on commit ee83f57

Please sign in to comment.