Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@16: // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@16: // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. Chris@16: // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. Chris@16: Chris@16: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@16: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP Chris@16: #define BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: Chris@16: // Adapts pointer, on points, to a Boost.Range Chris@16: template Chris@16: class points_view Chris@16: { Chris@16: // Iterates over a series of points (indicated by pointer Chris@16: // to have it lightweight). Probably there is already an Chris@16: // equivalent of this within Boost. If so, TODO: use that one. Chris@16: // This used to be "box_iterator" and "segment_iterator". Chris@101: // ALTERNATIVE: use boost:array and its iterators Chris@16: struct points_iterator Chris@16: : public boost::iterator_facade Chris@16: < Chris@16: points_iterator, Chris@16: Point const, Chris@16: boost::random_access_traversal_tag Chris@16: > Chris@16: { Chris@16: // Constructor: Begin iterator Chris@16: inline points_iterator(Point const* p) Chris@16: : m_points(p) Chris@101: , m_index(0) Chris@16: {} Chris@16: Chris@16: // Constructor: End iterator Chris@16: inline points_iterator(Point const* p, bool) Chris@16: : m_points(p) Chris@101: , m_index(MaxSize) Chris@16: {} Chris@16: Chris@16: // Constructor: default (for Range Concept checking). Chris@16: inline points_iterator() Chris@16: : m_points(NULL) Chris@101: , m_index(MaxSize) Chris@16: {} Chris@101: Chris@16: typedef std::ptrdiff_t difference_type; Chris@16: Chris@16: private: Chris@16: friend class boost::iterator_core_access; Chris@16: Chris@16: inline Point const& dereference() const Chris@16: { Chris@16: if (m_index >= 0 && m_index < MaxSize) Chris@16: { Chris@16: return m_points[m_index]; Chris@16: } Chris@101: Chris@16: // If it index larger (or smaller) return first point Chris@16: // (assuming initialized) Chris@16: return m_points[0]; Chris@16: } Chris@16: Chris@16: inline bool equal(points_iterator const& other) const Chris@16: { Chris@16: return other.m_index == this->m_index; Chris@16: } Chris@16: Chris@16: inline void increment() Chris@16: { Chris@16: m_index++; Chris@16: } Chris@16: Chris@16: inline void decrement() Chris@16: { Chris@16: m_index--; Chris@16: } Chris@16: Chris@16: inline difference_type distance_to(points_iterator const& other) const Chris@16: { Chris@16: return other.m_index - this->m_index; Chris@16: } Chris@101: Chris@16: inline void advance(difference_type n) Chris@16: { Chris@16: m_index += n; Chris@16: } Chris@16: Chris@16: Point const* m_points; Chris@101: difference_type m_index; Chris@16: }; Chris@16: Chris@16: public : Chris@16: Chris@16: typedef points_iterator const_iterator; Chris@16: typedef points_iterator iterator; // must be defined Chris@16: Chris@16: const_iterator begin() const { return const_iterator(m_points); } Chris@16: const_iterator end() const { return const_iterator(m_points, true); } Chris@16: Chris@16: // It may NOT be used non-const, so commented: Chris@16: //iterator begin() { return m_begin; } Chris@16: //iterator end() { return m_end; } Chris@16: Chris@16: protected : Chris@16: Chris@16: template Chris@16: explicit points_view(CopyPolicy const& copy) Chris@16: { Chris@16: copy.apply(m_points); Chris@16: } Chris@101: Chris@101: private : Chris@16: // Copy points here - box might define them otherwise Chris@16: Point m_points[MaxSize]; Chris@16: }; Chris@16: Chris@16: } Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: Chris@16: #endif // BOOST_GEOMETRY_VIEWS_DETAIL_POINTS_VIEW_HPP