Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@16: // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. Chris@16: // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. 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_CORE_ACCESS_HPP Chris@16: #define BOOST_GEOMETRY_CORE_ACCESS_HPP Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: /// Index of minimum corner of the box. Chris@16: int const min_corner = 0; Chris@16: Chris@16: /// Index of maximum corner of the box. Chris@16: int const max_corner = 1; Chris@16: Chris@16: namespace traits Chris@16: { Chris@16: Chris@16: /*! Chris@16: \brief Traits class which gives access (get,set) to points. Chris@16: \ingroup traits Chris@16: \par Geometries: Chris@16: /// @li point Chris@16: \par Specializations should provide, per Dimension Chris@16: /// @li static inline T get(G const&) Chris@16: /// @li static inline void set(G&, T const&) Chris@16: \tparam Geometry geometry-type Chris@16: \tparam Dimension dimension to access Chris@16: */ Chris@16: template Chris@16: struct access Chris@16: { Chris@16: BOOST_MPL_ASSERT_MSG Chris@16: ( Chris@16: false, NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE, (types) Chris@16: ); Chris@16: }; Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief Traits class defining "get" and "set" to get Chris@16: and set point coordinate values Chris@16: \tparam Geometry geometry (box, segment) Chris@16: \tparam Index index (min_corner/max_corner for box, 0/1 for segment) Chris@16: \tparam Dimension dimension Chris@16: \par Geometries: Chris@16: - box Chris@16: - segment Chris@16: \par Specializations should provide: Chris@16: - static inline T get(G const&) Chris@16: - static inline void set(G&, T const&) Chris@16: \ingroup traits Chris@16: */ Chris@16: template Chris@16: struct indexed_access {}; Chris@16: Chris@16: Chris@16: } // namespace traits Chris@16: Chris@16: #ifndef DOXYGEN_NO_DETAIL Chris@16: namespace detail Chris@16: { Chris@16: Chris@16: template Chris@16: < Chris@16: typename Geometry, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension Chris@16: > Chris@16: struct indexed_access_non_pointer Chris@16: { Chris@16: static inline CoordinateType get(Geometry const& geometry) Chris@16: { Chris@16: return traits::indexed_access::get(geometry); Chris@16: } Chris@16: static inline void set(Geometry& b, CoordinateType const& value) Chris@16: { Chris@16: traits::indexed_access::set(b, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: < Chris@16: typename Geometry, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension Chris@16: > Chris@16: struct indexed_access_pointer Chris@16: { Chris@16: static inline CoordinateType get(Geometry const* geometry) Chris@16: { Chris@16: return traits::indexed_access::type, Index, Dimension>::get(*geometry); Chris@16: } Chris@16: static inline void set(Geometry* geometry, CoordinateType const& value) Chris@16: { Chris@16: traits::indexed_access::type, Index, Dimension>::set(*geometry, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: } // namespace detail Chris@16: #endif // DOXYGEN_NO_DETAIL Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_DISPATCH Chris@16: namespace core_dispatch Chris@16: { Chris@16: Chris@16: template Chris@16: < Chris@16: typename Tag, Chris@16: typename Geometry, Chris@16: typename Chris@16: CoordinateType, Chris@16: std::size_t Dimension, Chris@16: typename IsPointer Chris@16: > Chris@16: struct access Chris@16: { Chris@16: //static inline T get(G const&) {} Chris@16: //static inline void set(G& g, T const& value) {} Chris@16: }; Chris@16: Chris@16: template Chris@16: < Chris@16: typename Tag, Chris@16: typename Geometry, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension, Chris@16: typename IsPointer Chris@16: > Chris@16: struct indexed_access Chris@16: { Chris@16: //static inline T get(G const&) {} Chris@16: //static inline void set(G& g, T const& value) {} Chris@16: }; Chris@16: Chris@16: template Chris@16: struct access Chris@16: { Chris@16: static inline CoordinateType get(Point const& point) Chris@16: { Chris@16: return traits::access::get(point); Chris@16: } Chris@16: static inline void set(Point& p, CoordinateType const& value) Chris@16: { Chris@16: traits::access::set(p, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct access Chris@16: { Chris@16: static inline CoordinateType get(Point const* point) Chris@16: { Chris@16: return traits::access::type, Dimension>::get(*point); Chris@16: } Chris@16: static inline void set(Point* p, CoordinateType const& value) Chris@16: { Chris@16: traits::access::type, Dimension>::set(*p, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: < Chris@16: typename Box, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension Chris@16: > Chris@16: struct indexed_access Chris@16: : detail::indexed_access_non_pointer Chris@16: {}; Chris@16: Chris@16: template Chris@16: < Chris@16: typename Box, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension Chris@16: > Chris@16: struct indexed_access Chris@16: : detail::indexed_access_pointer Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: < Chris@16: typename Segment, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension Chris@16: > Chris@16: struct indexed_access Chris@16: : detail::indexed_access_non_pointer Chris@16: {}; Chris@16: Chris@16: Chris@16: template Chris@16: < Chris@16: typename Segment, Chris@16: typename CoordinateType, Chris@16: std::size_t Index, Chris@16: std::size_t Dimension Chris@16: > Chris@16: struct indexed_access Chris@16: : detail::indexed_access_pointer Chris@16: {}; Chris@16: Chris@16: } // namespace core_dispatch Chris@16: #endif // DOXYGEN_NO_DISPATCH Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_DETAIL Chris@16: namespace detail Chris@16: { Chris@16: Chris@16: // Two dummy tags to distinguish get/set variants below. Chris@16: // They don't have to be specified by the user. The functions are distinguished Chris@16: // by template signature also, but for e.g. GCC this is not enough. So give them Chris@16: // a different signature. Chris@16: struct signature_getset_dimension {}; Chris@16: struct signature_getset_index_dimension {}; Chris@16: Chris@16: } // namespace detail Chris@16: #endif // DOXYGEN_NO_DETAIL Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief Get coordinate value of a geometry (usually a point) Chris@16: \details \details_get_set Chris@16: \ingroup get Chris@16: \tparam Dimension \tparam_dimension_required Chris@16: \tparam Geometry \tparam_geometry (usually a Point Concept) Chris@16: \param geometry \param_geometry (usually a point) Chris@16: \return The coordinate value of specified dimension of specified geometry Chris@16: Chris@16: \qbk{[include reference/core/get_point.qbk]} Chris@16: */ Chris@16: template Chris@16: inline typename coordinate_type::type get(Geometry const& geometry Chris@16: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@16: , detail::signature_getset_dimension* dummy = 0 Chris@16: #endif Chris@16: ) Chris@16: { Chris@16: boost::ignore_unused_variable_warning(dummy); Chris@16: Chris@16: typedef core_dispatch::access Chris@16: < Chris@16: typename tag::type, Chris@16: typename geometry::util::bare_type::type, Chris@16: typename coordinate_type::type, Chris@16: Dimension, Chris@16: typename boost::is_pointer::type Chris@16: > coord_access_type; Chris@16: Chris@16: return coord_access_type::get(geometry); Chris@16: } Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief Set coordinate value of a geometry (usually a point) Chris@16: \details \details_get_set Chris@16: \tparam Dimension \tparam_dimension_required Chris@16: \tparam Geometry \tparam_geometry (usually a Point Concept) Chris@16: \param geometry geometry to assign coordinate to Chris@16: \param geometry \param_geometry (usually a point) Chris@16: \param value The coordinate value to set Chris@16: \ingroup set Chris@16: Chris@16: \qbk{[include reference/core/set_point.qbk]} Chris@16: */ Chris@16: template Chris@16: inline void set(Geometry& geometry Chris@16: , typename coordinate_type::type const& value Chris@16: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@16: , detail::signature_getset_dimension* dummy = 0 Chris@101: #endif Chris@16: ) Chris@16: { Chris@16: boost::ignore_unused_variable_warning(dummy); Chris@16: Chris@16: typedef core_dispatch::access Chris@16: < Chris@16: typename tag::type, Chris@16: typename geometry::util::bare_type::type, Chris@16: typename coordinate_type::type, Chris@16: Dimension, Chris@16: typename boost::is_pointer::type Chris@16: > coord_access_type; Chris@16: Chris@16: coord_access_type::set(geometry, value); Chris@16: } Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief get coordinate value of a Box or Segment Chris@16: \details \details_get_set Chris@16: \tparam Index \tparam_index_required Chris@16: \tparam Dimension \tparam_dimension_required Chris@16: \tparam Geometry \tparam_box_or_segment Chris@16: \param geometry \param_geometry Chris@16: \return coordinate value Chris@16: \ingroup get Chris@16: Chris@16: \qbk{distinguish,with index} Chris@16: \qbk{[include reference/core/get_box.qbk]} Chris@16: */ Chris@16: template Chris@16: inline typename coordinate_type::type get(Geometry const& geometry Chris@16: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@16: , detail::signature_getset_index_dimension* dummy = 0 Chris@101: #endif Chris@16: ) Chris@16: { Chris@16: boost::ignore_unused_variable_warning(dummy); Chris@16: Chris@16: typedef core_dispatch::indexed_access Chris@16: < Chris@16: typename tag::type, Chris@16: typename geometry::util::bare_type::type, Chris@16: typename coordinate_type::type, Chris@16: Index, Chris@16: Dimension, Chris@16: typename boost::is_pointer::type Chris@16: > coord_access_type; Chris@16: Chris@16: return coord_access_type::get(geometry); Chris@16: } Chris@16: Chris@16: /*! Chris@16: \brief set coordinate value of a Box / Segment Chris@16: \details \details_get_set Chris@16: \tparam Index \tparam_index_required Chris@16: \tparam Dimension \tparam_dimension_required Chris@16: \tparam Geometry \tparam_box_or_segment Chris@16: \param geometry geometry to assign coordinate to Chris@16: \param geometry \param_geometry Chris@16: \param value The coordinate value to set Chris@16: \ingroup set Chris@16: Chris@16: \qbk{distinguish,with index} Chris@16: \qbk{[include reference/core/set_box.qbk]} Chris@16: */ Chris@16: template Chris@16: inline void set(Geometry& geometry Chris@16: , typename coordinate_type::type const& value Chris@16: #ifndef DOXYGEN_SHOULD_SKIP_THIS Chris@16: , detail::signature_getset_index_dimension* dummy = 0 Chris@16: #endif Chris@16: ) Chris@16: { Chris@16: boost::ignore_unused_variable_warning(dummy); Chris@16: Chris@16: typedef core_dispatch::indexed_access Chris@16: < Chris@101: typename tag::type, Chris@16: typename geometry::util::bare_type::type, Chris@16: typename coordinate_type::type, Chris@16: Index, Chris@16: Dimension, Chris@16: typename boost::is_pointer::type Chris@16: > coord_access_type; Chris@16: Chris@16: coord_access_type::set(geometry, value); Chris@16: } Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: #endif // BOOST_GEOMETRY_CORE_ACCESS_HPP