boost_array.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP
  8. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP
  9. #ifdef BOOST_GEOMETRY_ADAPTED_BOOST_ARRAY_TAG_DEFINED
  10. #error Include either "boost_array_as_point" or \
  11. "boost_array_as_linestring" or "boost_array_as_ring" \
  12. or "boost_array_as_multi_point" to adapt a boost_array
  13. #endif
  14. #define BOOST_GEOMETRY_ADAPTED_BOOST_ARRAY_TAG_DEFINED
  15. #include <cstddef>
  16. #include <boost/type_traits/is_arithmetic.hpp>
  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. #include <boost/array.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  26. namespace traits
  27. {
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail
  30. {
  31. // Create class and specialization to indicate the tag
  32. // for normal cases and the case that the type of the c-array is arithmetic
  33. template <bool>
  34. struct boost_array_tag
  35. {
  36. typedef geometry_not_recognized_tag type;
  37. };
  38. template <>
  39. struct boost_array_tag<true>
  40. {
  41. typedef point_tag type;
  42. };
  43. } // namespace detail
  44. #endif // DOXYGEN_NO_DETAIL
  45. // Assign the point-tag, preventing arrays of points getting a point-tag
  46. template <typename CoordinateType, std::size_t DimensionCount>
  47. struct tag<boost::array<CoordinateType, DimensionCount> >
  48. : detail::boost_array_tag<boost::is_arithmetic<CoordinateType>::value> {};
  49. template <typename CoordinateType, std::size_t DimensionCount>
  50. struct coordinate_type<boost::array<CoordinateType, DimensionCount> >
  51. {
  52. typedef CoordinateType type;
  53. };
  54. template <typename CoordinateType, std::size_t DimensionCount>
  55. struct dimension<boost::array<CoordinateType, DimensionCount> >: boost::mpl::int_<DimensionCount> {};
  56. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  57. struct access<boost::array<CoordinateType, DimensionCount>, Dimension>
  58. {
  59. static inline CoordinateType get(boost::array<CoordinateType, DimensionCount> const& a)
  60. {
  61. return a[Dimension];
  62. }
  63. static inline void set(boost::array<CoordinateType, DimensionCount>& a,
  64. CoordinateType const& value)
  65. {
  66. a[Dimension] = value;
  67. }
  68. };
  69. } // namespace traits
  70. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  71. }} // namespace boost::geometry
  72. #define BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(CoordinateSystem) \
  73. namespace boost { namespace geometry { namespace traits { \
  74. template <class T, std::size_t N> \
  75. struct coordinate_system<boost::array<T, N> > \
  76. { \
  77. typedef CoordinateSystem type; \
  78. }; \
  79. }}}
  80. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ARRAY_HPP