Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@101: // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. Chris@101: // Copyright (c) 2008-2014 Bruno Lalande, Paris, France. Chris@101: // Copyright (c) 2009-2014 Mateusz Loskot, London, UK. Chris@101: // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. Chris@101: Chris@101: // This file was modified by Oracle on 2014. Chris@101: // Modifications copyright (c) 2014, Oracle and/or its affiliates. Chris@101: Chris@101: // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle 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_ALGORITHMS_FOR_EACH_HPP Chris@16: #define BOOST_GEOMETRY_ALGORITHMS_FOR_EACH_HPP Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: Chris@101: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@101: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@101: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: #ifndef DOXYGEN_NO_DETAIL Chris@16: namespace detail { namespace for_each Chris@16: { Chris@16: Chris@16: Chris@16: struct fe_point_per_point Chris@16: { Chris@16: template Chris@16: static inline void apply(Point& point, Functor& f) Chris@16: { Chris@16: f(point); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: struct fe_point_per_segment Chris@16: { Chris@16: template Chris@101: static inline void apply(Point& , Functor& /*f*/) Chris@16: { Chris@16: // TODO: if non-const, we should extract the points from the segment Chris@16: // and call the functor on those two points Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: struct fe_range_per_point Chris@16: { Chris@16: template Chris@16: static inline void apply(Range& range, Functor& f) Chris@16: { Chris@16: // The previous implementation called the std library: Chris@16: // return (std::for_each(boost::begin(range), boost::end(range), f)); Chris@16: // But that is not accepted for capturing lambda's. Chris@16: // It needs to do it like that to return the state of Functor f (f is passed by value in std::for_each). Chris@16: Chris@16: // So we now loop manually. Chris@16: Chris@101: for (typename boost::range_iterator::type Chris@101: it = boost::begin(range); it != boost::end(range); ++it) Chris@16: { Chris@16: f(*it); Chris@16: } Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@101: template Chris@101: struct fe_range_per_segment_with_closure Chris@16: { Chris@16: template Chris@16: static inline void apply(Range& range, Functor& f) Chris@16: { Chris@16: typedef typename add_const_if_c Chris@16: < Chris@16: is_const::value, Chris@16: typename point_type::type Chris@16: >::type point_type; Chris@16: Chris@101: typedef typename boost::range_iterator::type iterator_type; Chris@101: Chris@101: iterator_type it = boost::begin(range); Chris@101: iterator_type previous = it++; Chris@16: while(it != boost::end(range)) Chris@16: { Chris@16: model::referring_segment s(*previous, *it); Chris@16: f(s); Chris@16: previous = it++; Chris@16: } Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@101: template <> Chris@101: struct fe_range_per_segment_with_closure Chris@101: { Chris@101: template Chris@101: static inline void apply(Range& range, Functor& f) Chris@101: { Chris@101: fe_range_per_segment_with_closure::apply(range, f); Chris@101: Chris@101: model::referring_segment Chris@101: < Chris@101: typename add_const_if_c Chris@101: < Chris@101: is_const::value, Chris@101: typename point_type::type Chris@101: >::type Chris@101: > s(range::back(range), range::front(range)); Chris@101: Chris@101: f(s); Chris@101: } Chris@101: }; Chris@101: Chris@101: Chris@101: struct fe_range_per_segment Chris@101: { Chris@101: template Chris@101: static inline void apply(Range& range, Functor& f) Chris@101: { Chris@101: fe_range_per_segment_with_closure Chris@101: < Chris@101: closure::value Chris@101: >::apply(range, f); Chris@101: } Chris@101: }; Chris@101: Chris@101: Chris@16: struct fe_polygon_per_point Chris@16: { Chris@16: template Chris@16: static inline void apply(Polygon& poly, Functor& f) Chris@16: { Chris@16: fe_range_per_point::apply(exterior_ring(poly), f); Chris@16: Chris@101: typename interior_return_type::type Chris@101: rings = interior_rings(poly); Chris@101: Chris@101: for (typename detail::interior_iterator::type Chris@101: it = boost::begin(rings); it != boost::end(rings); ++it) Chris@16: { Chris@16: fe_range_per_point::apply(*it, f); Chris@16: } Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: struct fe_polygon_per_segment Chris@16: { Chris@16: template Chris@16: static inline void apply(Polygon& poly, Functor& f) Chris@16: { Chris@16: fe_range_per_segment::apply(exterior_ring(poly), f); Chris@16: Chris@101: typename interior_return_type::type Chris@101: rings = interior_rings(poly); Chris@101: Chris@101: for (typename detail::interior_iterator::type Chris@101: it = boost::begin(rings); it != boost::end(rings); ++it) Chris@16: { Chris@16: fe_range_per_segment::apply(*it, f); Chris@16: } Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@101: // Implementation of multi, for both point and segment, Chris@101: // just calling the single version. Chris@101: template Chris@101: struct for_each_multi Chris@101: { Chris@101: template Chris@101: static inline void apply(MultiGeometry& multi, Functor& f) Chris@101: { Chris@101: for (typename boost::range_iterator::type Chris@101: it = boost::begin(multi); it != boost::end(multi); ++it) Chris@101: { Chris@101: Policy::apply(*it, f); Chris@101: } Chris@101: } Chris@101: }; Chris@16: Chris@16: }} // namespace detail::for_each Chris@16: #endif // DOXYGEN_NO_DETAIL Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_DISPATCH Chris@16: namespace dispatch Chris@16: { Chris@16: Chris@16: template Chris@16: < Chris@16: typename Geometry, Chris@16: typename Tag = typename tag_cast::type, multi_tag>::type Chris@16: > Chris@16: struct for_each_point: not_implemented Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_point Chris@16: : detail::for_each::fe_point_per_point Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_point Chris@16: : detail::for_each::fe_range_per_point Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_point Chris@16: : detail::for_each::fe_range_per_point Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_point Chris@16: : detail::for_each::fe_polygon_per_point Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: < Chris@16: typename Geometry, Chris@16: typename Tag = typename tag_cast::type, multi_tag>::type Chris@16: > Chris@16: struct for_each_segment: not_implemented Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct for_each_segment Chris@16: : detail::for_each::fe_point_per_segment Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_segment Chris@16: : detail::for_each::fe_range_per_segment Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_segment Chris@16: : detail::for_each::fe_range_per_segment Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: struct for_each_segment Chris@16: : detail::for_each::fe_polygon_per_segment Chris@16: {}; Chris@16: Chris@16: Chris@101: template Chris@101: struct for_each_point Chris@101: : detail::for_each::for_each_multi Chris@101: < Chris@101: // Specify the dispatch of the single-version as policy Chris@101: for_each_point Chris@101: < Chris@101: typename add_const_if_c Chris@101: < Chris@101: is_const::value, Chris@101: typename boost::range_value::type Chris@101: >::type Chris@101: > Chris@101: > Chris@101: {}; Chris@101: Chris@101: Chris@101: template Chris@101: struct for_each_segment Chris@101: : detail::for_each::for_each_multi Chris@101: < Chris@101: // Specify the dispatch of the single-version as policy Chris@101: for_each_segment Chris@101: < Chris@101: typename add_const_if_c Chris@101: < Chris@101: is_const::value, Chris@101: typename boost::range_value::type Chris@101: >::type Chris@101: > Chris@101: > Chris@101: {}; Chris@101: Chris@101: Chris@16: } // namespace dispatch Chris@16: #endif // DOXYGEN_NO_DISPATCH Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief \brf_for_each{point} Chris@16: \details \det_for_each{point} Chris@16: \ingroup for_each Chris@16: \param geometry \param_geometry Chris@16: \param f \par_for_each_f{point} Chris@16: \tparam Geometry \tparam_geometry Chris@16: \tparam Functor \tparam_functor Chris@16: Chris@16: \qbk{[include reference/algorithms/for_each_point.qbk]} Chris@16: \qbk{[heading Example]} Chris@16: \qbk{[for_each_point] [for_each_point_output]} Chris@16: \qbk{[for_each_point_const] [for_each_point_const_output]} Chris@16: */ Chris@16: template Chris@16: inline Functor for_each_point(Geometry& geometry, Functor f) Chris@16: { Chris@16: concept::check(); Chris@16: Chris@16: dispatch::for_each_point::apply(geometry, f); Chris@16: return f; Chris@16: } Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief \brf_for_each{segment} Chris@16: \details \det_for_each{segment} Chris@16: \ingroup for_each Chris@16: \param geometry \param_geometry Chris@16: \param f \par_for_each_f{segment} Chris@16: \tparam Geometry \tparam_geometry Chris@16: \tparam Functor \tparam_functor Chris@16: Chris@16: \qbk{[include reference/algorithms/for_each_segment.qbk]} Chris@16: \qbk{[heading Example]} Chris@16: \qbk{[for_each_segment_const] [for_each_segment_const_output]} Chris@16: */ Chris@16: template Chris@16: inline Functor for_each_segment(Geometry& geometry, Functor f) Chris@16: { Chris@16: concept::check(); Chris@16: Chris@16: dispatch::for_each_segment::apply(geometry, f); Chris@16: return f; Chris@16: } Chris@16: Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: Chris@16: #endif // BOOST_GEOMETRY_ALGORITHMS_FOR_EACH_HPP