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 | #ifndef BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP |
15 | #define BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP |
16 | |
17 | |
18 | #include <cstddef> |
19 | |
20 | #include <boost/mpl/assert.hpp> |
21 | #include <boost/mpl/equal_to.hpp> |
22 | #include <boost/static_assert.hpp> |
23 | |
24 | #include <boost/geometry/core/point_type.hpp> |
25 | #include <boost/geometry/util/bare_type.hpp> |
26 | |
27 | namespace boost { namespace geometry |
28 | { |
29 | |
30 | namespace traits |
31 | { |
32 | |
33 | /*! |
34 | \brief Traits class indicating the number of dimensions of a point |
35 | \par Geometries: |
36 | - point |
37 | \par Specializations should provide: |
38 | - value (should be derived from boost::mpl::int_<D> |
39 | \ingroup traits |
40 | */ |
41 | template <typename Point, typename Enable = void> |
42 | struct dimension |
43 | { |
44 | BOOST_MPL_ASSERT_MSG |
45 | ( |
46 | false, NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE, (types<Point>) |
47 | ); |
48 | }; |
49 | |
50 | } // namespace traits |
51 | |
52 | #ifndef DOXYGEN_NO_DISPATCH |
53 | namespace core_dispatch |
54 | { |
55 | |
56 | // Base class derive from its own specialization of point-tag |
57 | template <typename T, typename G> |
58 | struct dimension : dimension<point_tag, typename point_type<T, G>::type> {}; |
59 | |
60 | template <typename P> |
61 | struct dimension<point_tag, P> |
62 | : traits::dimension<typename geometry::util::bare_type<P>::type> |
63 | { |
64 | BOOST_MPL_ASSERT_MSG( |
65 | (traits::dimension<typename geometry::util::bare_type<P>::type>::value > 0), |
66 | INVALID_DIMENSION_VALUE, |
67 | (traits::dimension<typename geometry::util::bare_type<P>::type>) |
68 | ); |
69 | }; |
70 | |
71 | } // namespace core_dispatch |
72 | #endif |
73 | |
74 | /*! |
75 | \brief \brief_meta{value, number of coordinates (the number of axes of any geometry), \meta_point_type} |
76 | \tparam Geometry \tparam_geometry |
77 | \ingroup core |
78 | |
79 | \qbk{[include reference/core/coordinate_dimension.qbk]} |
80 | */ |
81 | template <typename Geometry> |
82 | struct dimension |
83 | : core_dispatch::dimension |
84 | < |
85 | typename tag<Geometry>::type, |
86 | typename geometry::util::bare_type<Geometry>::type |
87 | > |
88 | {}; |
89 | |
90 | /*! |
91 | \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected |
92 | \ingroup utility |
93 | */ |
94 | template <typename Geometry, int Dimensions> |
95 | inline void assert_dimension() |
96 | { |
97 | BOOST_STATIC_ASSERT(( |
98 | boost::mpl::equal_to |
99 | < |
100 | boost::mpl::int_<geometry::dimension<Geometry>::value>, |
101 | boost::mpl::int_<Dimensions> |
102 | >::type::value |
103 | )); |
104 | } |
105 | |
106 | /*! |
107 | \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected |
108 | \ingroup utility |
109 | */ |
110 | template <typename Geometry, int Dimensions> |
111 | inline void assert_dimension_less_equal() |
112 | { |
113 | BOOST_STATIC_ASSERT(( static_cast<int>(dimension<Geometry>::type::value) <= Dimensions )); |
114 | } |
115 | |
116 | template <typename Geometry, int Dimensions> |
117 | inline void assert_dimension_greater_equal() |
118 | { |
119 | BOOST_STATIC_ASSERT(( static_cast<int>(dimension<Geometry>::type::value) >= Dimensions )); |
120 | } |
121 | |
122 | /*! |
123 | \brief assert_dimension_equal, enables compile-time checking if coordinate dimensions of two geometries are equal |
124 | \ingroup utility |
125 | */ |
126 | template <typename G1, typename G2> |
127 | inline void assert_dimension_equal() |
128 | { |
129 | BOOST_STATIC_ASSERT(( static_cast<size_t>(dimension<G1>::type::value) == static_cast<size_t>(dimension<G2>::type::value) )); |
130 | } |
131 | |
132 | }} // namespace boost::geometry |
133 | |
134 | #endif // BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP |
135 | |