c_array.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2020.
  6. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_C_ARRAY_HPP
  14. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_C_ARRAY_HPP
  15. #include <cstddef>
  16. #include <type_traits>
  17. #include <boost/geometry/core/access.hpp>
  18. #include <boost/geometry/core/cs.hpp>
  19. #include <boost/geometry/core/coordinate_dimension.hpp>
  20. #include <boost/geometry/core/coordinate_type.hpp>
  21. #include <boost/geometry/core/tags.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  25. namespace traits
  26. {
  27. #ifndef DOXYGEN_NO_DETAIL
  28. namespace detail
  29. {
  30. // Create class and specialization to indicate the tag
  31. // for normal cases and the case that the type of the c-array is arithmetic
  32. template <bool>
  33. struct c_array_tag
  34. {
  35. typedef geometry_not_recognized_tag type;
  36. };
  37. template <>
  38. struct c_array_tag<true>
  39. {
  40. typedef point_tag type;
  41. };
  42. } // namespace detail
  43. #endif // DOXYGEN_NO_DETAIL
  44. // Assign the point-tag, preventing arrays of points getting a point-tag
  45. template <typename CoordinateType, std::size_t DimensionCount>
  46. struct tag<CoordinateType[DimensionCount]>
  47. : detail::c_array_tag<std::is_arithmetic<CoordinateType>::value> {};
  48. template <typename CoordinateType, std::size_t DimensionCount>
  49. struct coordinate_type<CoordinateType[DimensionCount]>
  50. {
  51. typedef CoordinateType type;
  52. };
  53. template <typename CoordinateType, std::size_t DimensionCount>
  54. struct dimension<CoordinateType[DimensionCount]>
  55. : std::integral_constant<std::size_t, DimensionCount>
  56. {};
  57. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  58. struct access<CoordinateType[DimensionCount], Dimension>
  59. {
  60. static inline CoordinateType get(CoordinateType const p[DimensionCount])
  61. {
  62. return p[Dimension];
  63. }
  64. static inline void set(CoordinateType p[DimensionCount],
  65. CoordinateType const& value)
  66. {
  67. p[Dimension] = value;
  68. }
  69. };
  70. } // namespace traits
  71. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  72. }} // namespace boost::geometry
  73. #define BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(CoordinateSystem) \
  74. namespace boost { namespace geometry { namespace traits { \
  75. template <typename T, std::size_t N> \
  76. struct coordinate_system<T[N]> \
  77. { \
  78. typedef CoordinateSystem type; \
  79. }; \
  80. }}}
  81. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_C_ARRAY_HPP