Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64114 - sandbox/geometry/libs/geometry/test/test_geometries
From: barend.gehrels_at_[hidden]
Date: 2010-07-17 16:30:05


Author: barendgehrels
Date: 2010-07-17 16:30:04 EDT (Sat, 17 Jul 2010)
New Revision: 64114
URL: http://svn.boost.org/trac/boost/changeset/64114

Log:
Added folder test_geometries with geometries which should fulfill the concepts
Added:
   sandbox/geometry/libs/geometry/test/test_geometries/
   sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp (contents, props changed)

Added: sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp 2010-07-17 16:30:04 EDT (Sat, 17 Jul 2010)
@@ -0,0 +1,175 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library) test file
+//
+// Copyright Barend Gehrels 2010, Geodan, 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 ar
+// 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 <vector>
+#include <boost/array.hpp>
+
+
+#include <boost/array.hpp>
+#include <boost/range.hpp>
+
+#include <boost/geometry/core/container_access.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;
+ int 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;
+ }
+ };
+
+
+}}} // namespace boost::geometry::traits
+
+
+
+namespace std
+{
+
+template <typename Point, std::size_t Count>
+class back_insert_iterator< test::wrapped_boost_array<Point, Count> >
+ : public std::iterator<std::output_iterator_tag, void, void, void, void>
+{
+public:
+
+ typedef test::wrapped_boost_array<Point, Count> container_type;
+ typedef back_insert_iterator<container_type> this_type;
+
+ explicit back_insert_iterator(container_type& ar)
+ : m_current(boost::begin(ar) + ar.size)
+ , m_array(ar)
+ {}
+
+ inline this_type& operator=(Point const& value)
+ {
+ // Check if not passed beyond
+ if (m_array.size < Count)
+ {
+ *m_current++ = value;
+ m_array.size++;
+ }
+ return *this;
+ }
+
+ // Boiler-plate
+ inline this_type& operator*() { return *this; }
+ inline this_type& operator++() { return *this; }
+ inline this_type& operator++(int) { return *this; }
+
+private:
+ typename boost::range_iterator<container_type>::type m_current;
+ container_type& m_array;
+};
+
+} // namespace std
+
+
+#endif // GEOMETRY_TEST_TEST_GEOMETRIES_WRAPPED_BOOST_ARRAY_HPP


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk