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 | |
19 | #include <cstddef> |
20 | |
21 | #include <boost/concept_check.hpp> |
22 | |
23 | |
24 | #include <boost/geometry/core/access.hpp> |
25 | #include <boost/geometry/core/coordinate_dimension.hpp> |
26 | #include <boost/geometry/core/point_type.hpp> |
27 | |
28 | |
29 | namespace boost { namespace geometry { namespace concept |
30 | { |
31 | |
32 | |
33 | /*! |
34 | \brief Box concept |
35 | \ingroup concepts |
36 | \par Formal definition: |
37 | The box concept is defined as following: |
38 | - there must be a specialization of traits::tag defining box_tag as type |
39 | - there must be a specialization of traits::point_type to define the |
40 | underlying point type (even if it does not consist of points, it should define |
41 | this type, to indicate the points it can work with) |
42 | - there must be a specialization of traits::indexed_access, per index |
43 | (min_corner, max_corner) and per dimension, with two functions: |
44 | - get to get a coordinate value |
45 | - set to set a coordinate value (this one is not checked for ConstBox) |
46 | */ |
47 | template <typename Geometry> |
48 | class Box |
49 | { |
50 | #ifndef DOXYGEN_NO_CONCEPT_MEMBERS |
51 | typedef typename point_type<Geometry>::type point_type; |
52 | |
53 | |
54 | template |
55 | < |
56 | std::size_t Index, |
57 | std::size_t Dimension, |
58 | std::size_t DimensionCount |
59 | > |
60 | struct dimension_checker |
61 | { |
62 | static void apply() |
63 | { |
64 | Geometry* b = 0; |
65 | geometry::set<Index, Dimension>(*b, geometry::get<Index, Dimension>(*b)); |
66 | dimension_checker<Index, Dimension + 1, DimensionCount>::apply(); |
67 | } |
68 | }; |
69 | |
70 | template <std::size_t Index, std::size_t DimensionCount> |
71 | struct dimension_checker<Index, DimensionCount, DimensionCount> |
72 | { |
73 | static void apply() {} |
74 | }; |
75 | |
76 | public : |
77 | BOOST_CONCEPT_USAGE(Box) |
78 | { |
79 | static const std::size_t n = dimension<Geometry>::type::value; |
80 | dimension_checker<min_corner, 0, n>::apply(); |
81 | dimension_checker<max_corner, 0, n>::apply(); |
82 | } |
83 | #endif |
84 | }; |
85 | |
86 | |
87 | /*! |
88 | \brief Box concept (const version) |
89 | \ingroup const_concepts |
90 | \details The ConstBox concept apply the same as the Box concept, |
91 | but does not apply write access. |
92 | */ |
93 | template <typename Geometry> |
94 | class ConstBox |
95 | { |
96 | #ifndef DOXYGEN_NO_CONCEPT_MEMBERS |
97 | typedef typename point_type<Geometry>::type point_type; |
98 | typedef typename coordinate_type<Geometry>::type coordinate_type; |
99 | |
100 | template |
101 | < |
102 | std::size_t Index, |
103 | std::size_t Dimension, |
104 | std::size_t DimensionCount |
105 | > |
106 | struct dimension_checker |
107 | { |
108 | static void apply() |
109 | { |
110 | const Geometry* b = 0; |
111 | coordinate_type coord(geometry::get<Index, Dimension>(*b)); |
112 | boost::ignore_unused_variable_warning(coord); |
113 | dimension_checker<Index, Dimension + 1, DimensionCount>::apply(); |
114 | } |
115 | }; |
116 | |
117 | template <std::size_t Index, std::size_t DimensionCount> |
118 | struct dimension_checker<Index, DimensionCount, DimensionCount> |
119 | { |
120 | static void apply() {} |
121 | }; |
122 | |
123 | public : |
124 | BOOST_CONCEPT_USAGE(ConstBox) |
125 | { |
126 | static const std::size_t n = dimension<Geometry>::type::value; |
127 | dimension_checker<min_corner, 0, n>::apply(); |
128 | dimension_checker<max_corner, 0, n>::apply(); |
129 | } |
130 | #endif |
131 | }; |
132 | |
133 | }}} // namespace boost::geometry::concept |
134 | |
135 | |
136 | #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP |
137 | |