1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. 4 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. 5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. 6 7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library 8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. 9 10 // Use, modification and distribution is subject to the Boost Software License, 11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 12 // http://www.boost.org/LICENSE_1_0.txt) 13 14 15 #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP 16 #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP 17 18 #include <cstddef> 19 20 #include <boost/concept_check.hpp> 21 #include <boost/core/ignore_unused.hpp> 22 23 #include <boost/geometry/core/access.hpp> 24 #include <boost/geometry/core/coordinate_dimension.hpp> 25 #include <boost/geometry/core/point_type.hpp> 26 27 28 namespace boost { namespace geometry { namespace concepts 29 { 30 31 32 /*! 33 \brief Box concept 34 \ingroup concepts 35 \par Formal definition: 36 The box concept is defined as following: 37 - there must be a specialization of traits::tag defining box_tag as type 38 - there must be a specialization of traits::point_type to define the 39 underlying point type (even if it does not consist of points, it should define 40 this type, to indicate the points it can work with) 41 - there must be a specialization of traits::indexed_access, per index 42 (min_corner, max_corner) and per dimension, with two functions: 43 - get to get a coordinate value 44 - set to set a coordinate value (this one is not checked for ConstBox) 45 */ 46 template <typename Geometry> 47 class Box 48 { 49 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS 50 typedef typename point_type<Geometry>::type point_type; 51 52 53 template 54 < 55 std::size_t Index, 56 std::size_t Dimension, 57 std::size_t DimensionCount 58 > 59 struct dimension_checker 60 { applyboost::geometry::concepts::Box::dimension_checker61 static void apply() 62 { 63 Geometry* b = 0; 64 geometry::set<Index, Dimension>(*b, geometry::get<Index, Dimension>(*b)); 65 dimension_checker<Index, Dimension + 1, DimensionCount>::apply(); 66 } 67 }; 68 69 template <std::size_t Index, std::size_t DimensionCount> 70 struct dimension_checker<Index, DimensionCount, DimensionCount> 71 { applyboost::geometry::concepts::Box::dimension_checker72 static void apply() {} 73 }; 74 75 public : BOOST_CONCEPT_USAGE(Box)76 BOOST_CONCEPT_USAGE(Box) 77 { 78 static const std::size_t n = dimension<Geometry>::type::value; 79 dimension_checker<min_corner, 0, n>::apply(); 80 dimension_checker<max_corner, 0, n>::apply(); 81 } 82 #endif 83 }; 84 85 86 /*! 87 \brief Box concept (const version) 88 \ingroup const_concepts 89 \details The ConstBox concept apply the same as the Box concept, 90 but does not apply write access. 91 */ 92 template <typename Geometry> 93 class ConstBox 94 { 95 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS 96 typedef typename point_type<Geometry>::type point_type; 97 typedef typename coordinate_type<Geometry>::type coordinate_type; 98 99 template 100 < 101 std::size_t Index, 102 std::size_t Dimension, 103 std::size_t DimensionCount 104 > 105 struct dimension_checker 106 { applyboost::geometry::concepts::ConstBox::dimension_checker107 static void apply() 108 { 109 const Geometry* b = 0; 110 coordinate_type coord(geometry::get<Index, Dimension>(*b)); 111 boost::ignore_unused(coord); 112 dimension_checker<Index, Dimension + 1, DimensionCount>::apply(); 113 } 114 }; 115 116 template <std::size_t Index, std::size_t DimensionCount> 117 struct dimension_checker<Index, DimensionCount, DimensionCount> 118 { applyboost::geometry::concepts::ConstBox::dimension_checker119 static void apply() {} 120 }; 121 122 public : BOOST_CONCEPT_USAGE(ConstBox)123 BOOST_CONCEPT_USAGE(ConstBox) 124 { 125 static const std::size_t n = dimension<Geometry>::type::value; 126 dimension_checker<min_corner, 0, n>::apply(); 127 dimension_checker<max_corner, 0, n>::apply(); 128 } 129 #endif 130 }; 131 132 }}} // namespace boost::geometry::concepts 133 134 135 #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP 136