boost_array.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2010 Alfredo Correa
  3. // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2020.
  5. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  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. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP
  12. #ifdef BOOST_GEOMETRY_ADAPTED_BOOST_ARRAY_TAG_DEFINED
  13. #error Include either "boost_array_as_point" or \
  14. "boost_array_as_linestring" or "boost_array_as_ring" \
  15. or "boost_array_as_multi_point" to adapt a boost_array
  16. #endif
  17. #define BOOST_GEOMETRY_ADAPTED_BOOST_ARRAY_TAG_DEFINED
  18. #include <cstddef>
  19. #include <type_traits>
  20. #include <boost/geometry/core/access.hpp>
  21. #include <boost/geometry/core/cs.hpp>
  22. #include <boost/geometry/core/coordinate_dimension.hpp>
  23. #include <boost/geometry/core/coordinate_type.hpp>
  24. #include <boost/geometry/core/tags.hpp>
  25. #include <boost/array.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  29. namespace traits
  30. {
  31. #ifndef DOXYGEN_NO_DETAIL
  32. namespace detail
  33. {
  34. // Create class and specialization to indicate the tag
  35. // for normal cases and the case that the type of the c-array is arithmetic
  36. template <bool>
  37. struct boost_array_tag
  38. {
  39. typedef geometry_not_recognized_tag type;
  40. };
  41. template <>
  42. struct boost_array_tag<true>
  43. {
  44. typedef point_tag type;
  45. };
  46. } // namespace detail
  47. #endif // DOXYGEN_NO_DETAIL
  48. // Assign the point-tag, preventing arrays of points getting a point-tag
  49. template <typename CoordinateType, std::size_t DimensionCount>
  50. struct tag<boost::array<CoordinateType, DimensionCount> >
  51. : detail::boost_array_tag<std::is_arithmetic<CoordinateType>::value> {};
  52. template <typename CoordinateType, std::size_t DimensionCount>
  53. struct coordinate_type<boost::array<CoordinateType, DimensionCount> >
  54. {
  55. typedef CoordinateType type;
  56. };
  57. template <typename CoordinateType, std::size_t DimensionCount>
  58. struct dimension<boost::array<CoordinateType, DimensionCount> >
  59. : std::integral_constant<std::size_t, DimensionCount>
  60. {};
  61. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  62. struct access<boost::array<CoordinateType, DimensionCount>, Dimension>
  63. {
  64. static inline CoordinateType get(boost::array<CoordinateType, DimensionCount> const& a)
  65. {
  66. return a[Dimension];
  67. }
  68. static inline void set(boost::array<CoordinateType, DimensionCount>& a,
  69. CoordinateType const& value)
  70. {
  71. a[Dimension] = value;
  72. }
  73. };
  74. } // namespace traits
  75. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  76. }} // namespace boost::geometry
  77. #define BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(CoordinateSystem) \
  78. namespace boost { namespace geometry { namespace traits { \
  79. template <class T, std::size_t N> \
  80. struct coordinate_system<boost::array<T, N> > \
  81. { \
  82. typedef CoordinateSystem type; \
  83. }; \
  84. }}}
  85. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP