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 // Copyright (c) 2016 Norbert Wenzel 6 7 // Use, modification and distribution is subject to the Boost Software License, 8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 // http://www.boost.org/LICENSE_1_0.txt) 10 11 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP 12 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP 13 14 15 #include <boost/config.hpp> 16 17 18 #ifndef BOOST_NO_CXX11_HDR_ARRAY 19 20 21 #define BOOST_GEOMETRY_ADAPTED_STD_ARRAY_TAG_DEFINED 22 23 24 #include <cstddef> 25 26 #include <boost/type_traits/is_arithmetic.hpp> 27 28 #include <boost/geometry/core/access.hpp> 29 #include <boost/geometry/core/cs.hpp> 30 #include <boost/geometry/core/coordinate_dimension.hpp> 31 #include <boost/geometry/core/coordinate_type.hpp> 32 #include <boost/geometry/core/tags.hpp> 33 34 #include <array> 35 36 namespace boost { namespace geometry 37 { 38 39 40 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS 41 namespace traits 42 { 43 44 45 #ifndef DOXYGEN_NO_DETAIL 46 namespace detail 47 { 48 49 50 // Create class and specialization to indicate the tag 51 // for normal cases and the case that the type of the std-array is arithmetic 52 template <bool> 53 struct std_array_tag 54 { 55 typedef geometry_not_recognized_tag type; 56 }; 57 58 59 template <> 60 struct std_array_tag<true> 61 { 62 typedef point_tag type; 63 }; 64 65 66 } // namespace detail 67 #endif // DOXYGEN_NO_DETAIL 68 69 70 // Assign the point-tag, preventing arrays of points getting a point-tag 71 template <typename CoordinateType, std::size_t DimensionCount> 72 struct tag<std::array<CoordinateType, DimensionCount> > 73 : detail::std_array_tag<boost::is_arithmetic<CoordinateType>::value> {}; 74 75 76 template <typename CoordinateType, std::size_t DimensionCount> 77 struct coordinate_type<std::array<CoordinateType, DimensionCount> > 78 { 79 typedef CoordinateType type; 80 }; 81 82 83 template <typename CoordinateType, std::size_t DimensionCount> 84 struct dimension<std::array<CoordinateType, DimensionCount> >: boost::mpl::int_<DimensionCount> {}; 85 86 87 template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension> 88 struct access<std::array<CoordinateType, DimensionCount>, Dimension> 89 { getboost::geometry::traits::access90 static inline CoordinateType get(std::array<CoordinateType, DimensionCount> const& a) 91 { 92 return a[Dimension]; 93 } 94 setboost::geometry::traits::access95 static inline void set(std::array<CoordinateType, DimensionCount>& a, 96 CoordinateType const& value) 97 { 98 a[Dimension] = value; 99 } 100 }; 101 102 103 } // namespace traits 104 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS 105 106 107 }} // namespace boost::geometry 108 109 110 #define BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(CoordinateSystem) \ 111 namespace boost { namespace geometry { namespace traits { \ 112 template <class T, std::size_t N> \ 113 struct coordinate_system<std::array<T, N> > \ 114 { \ 115 typedef CoordinateSystem type; \ 116 }; \ 117 }}} 118 119 120 #else 121 122 123 #warning "This file requires compiler and library support for the ISO C++ 2011 standard." 124 125 126 #endif // BOOST_NO_CXX11_HDR_ARRAY 127 128 129 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP 130 131