123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- // 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
|