c_array.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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_C_ARRAY_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_C_ARRAY_HPP
  12. #include <cstddef>
  13. #include <boost/type_traits/is_arithmetic.hpp>
  14. #include <boost/geometry/core/access.hpp>
  15. #include <boost/geometry/core/cs.hpp>
  16. #include <boost/geometry/core/coordinate_dimension.hpp>
  17. #include <boost/geometry/core/coordinate_type.hpp>
  18. #include <boost/geometry/core/tags.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  22. namespace traits
  23. {
  24. #ifndef DOXYGEN_NO_DETAIL
  25. namespace detail
  26. {
  27. // Create class and specialization to indicate the tag
  28. // for normal cases and the case that the type of the c-array is arithmetic
  29. template <bool>
  30. struct c_array_tag
  31. {
  32. typedef geometry_not_recognized_tag type;
  33. };
  34. template <>
  35. struct c_array_tag<true>
  36. {
  37. typedef point_tag type;
  38. };
  39. } // namespace detail
  40. #endif // DOXYGEN_NO_DETAIL
  41. // Assign the point-tag, preventing arrays of points getting a point-tag
  42. template <typename CoordinateType, std::size_t DimensionCount>
  43. struct tag<CoordinateType[DimensionCount]>
  44. : detail::c_array_tag<boost::is_arithmetic<CoordinateType>::value> {};
  45. template <typename CoordinateType, std::size_t DimensionCount>
  46. struct coordinate_type<CoordinateType[DimensionCount]>
  47. {
  48. typedef CoordinateType type;
  49. };
  50. template <typename CoordinateType, std::size_t DimensionCount>
  51. struct dimension<CoordinateType[DimensionCount]>: boost::mpl::int_<DimensionCount> {};
  52. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  53. struct access<CoordinateType[DimensionCount], Dimension>
  54. {
  55. static inline CoordinateType get(CoordinateType const p[DimensionCount])
  56. {
  57. return p[Dimension];
  58. }
  59. static inline void set(CoordinateType p[DimensionCount],
  60. CoordinateType const& value)
  61. {
  62. p[Dimension] = value;
  63. }
  64. };
  65. } // namespace traits
  66. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  67. }} // namespace boost::geometry
  68. #define BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(CoordinateSystem) \
  69. namespace boost { namespace geometry { namespace traits { \
  70. template <typename T, std::size_t N> \
  71. struct coordinate_system<T[N]> \
  72. { \
  73. typedef CoordinateSystem type; \
  74. }; \
  75. }}}
  76. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_C_ARRAY_HPP