]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2010 Alfredo Correa | |
4 | // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | ||
6 | // Use, modification and distribution is subject to the Boost Software License, | |
7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
8 | // http://www.boost.org/LICENSE_1_0.txt) | |
9 | ||
10 | #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP | |
11 | #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP | |
12 | ||
13 | ||
14 | #ifdef BOOST_GEOMETRY_ADAPTED_BOOST_ARRAY_TAG_DEFINED | |
15 | #error Include either "boost_array_as_point" or \ | |
16 | "boost_array_as_linestring" or "boost_array_as_ring" \ | |
17 | or "boost_array_as_multi_point" to adapt a boost_array | |
18 | #endif | |
19 | ||
20 | #define BOOST_GEOMETRY_ADAPTED_BOOST_ARRAY_TAG_DEFINED | |
21 | ||
22 | ||
23 | #include <cstddef> | |
24 | ||
25 | #include <boost/type_traits/is_arithmetic.hpp> | |
26 | ||
27 | #include <boost/geometry/core/access.hpp> | |
28 | #include <boost/geometry/core/cs.hpp> | |
29 | #include <boost/geometry/core/coordinate_dimension.hpp> | |
30 | #include <boost/geometry/core/coordinate_type.hpp> | |
31 | #include <boost/geometry/core/tags.hpp> | |
32 | ||
33 | #include <boost/array.hpp> | |
34 | ||
35 | namespace boost { namespace geometry | |
36 | { | |
37 | ||
38 | ||
39 | #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS | |
40 | namespace traits | |
41 | { | |
42 | ||
43 | ||
44 | #ifndef DOXYGEN_NO_DETAIL | |
45 | namespace detail | |
46 | { | |
47 | ||
48 | ||
49 | // Create class and specialization to indicate the tag | |
50 | // for normal cases and the case that the type of the c-array is arithmetic | |
51 | template <bool> | |
52 | struct boost_array_tag | |
53 | { | |
54 | typedef geometry_not_recognized_tag type; | |
55 | }; | |
56 | ||
57 | ||
58 | template <> | |
59 | struct boost_array_tag<true> | |
60 | { | |
61 | typedef point_tag type; | |
62 | }; | |
63 | ||
64 | ||
65 | } // namespace detail | |
66 | #endif // DOXYGEN_NO_DETAIL | |
67 | ||
68 | ||
69 | // Assign the point-tag, preventing arrays of points getting a point-tag | |
70 | template <typename CoordinateType, std::size_t DimensionCount> | |
71 | struct tag<boost::array<CoordinateType, DimensionCount> > | |
72 | : detail::boost_array_tag<boost::is_arithmetic<CoordinateType>::value> {}; | |
73 | ||
74 | ||
75 | template <typename CoordinateType, std::size_t DimensionCount> | |
76 | struct coordinate_type<boost::array<CoordinateType, DimensionCount> > | |
77 | { | |
78 | typedef CoordinateType type; | |
79 | }; | |
80 | ||
81 | ||
82 | template <typename CoordinateType, std::size_t DimensionCount> | |
83 | struct dimension<boost::array<CoordinateType, DimensionCount> >: boost::mpl::int_<DimensionCount> {}; | |
84 | ||
85 | ||
86 | template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension> | |
87 | struct access<boost::array<CoordinateType, DimensionCount>, Dimension> | |
88 | { | |
89 | static inline CoordinateType get(boost::array<CoordinateType, DimensionCount> const& a) | |
90 | { | |
91 | return a[Dimension]; | |
92 | } | |
93 | ||
94 | static inline void set(boost::array<CoordinateType, DimensionCount>& a, | |
95 | CoordinateType const& value) | |
96 | { | |
97 | a[Dimension] = value; | |
98 | } | |
99 | }; | |
100 | ||
101 | ||
102 | } // namespace traits | |
103 | #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS | |
104 | ||
105 | ||
106 | }} // namespace boost::geometry | |
107 | ||
108 | ||
109 | #define BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(CoordinateSystem) \ | |
110 | namespace boost { namespace geometry { namespace traits { \ | |
111 | template <class T, std::size_t N> \ | |
112 | struct coordinate_system<boost::array<T, N> > \ | |
113 | { \ | |
114 | typedef CoordinateSystem type; \ | |
115 | }; \ | |
116 | }}} | |
117 | ||
118 | ||
119 | #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP | |
120 |