boost_fusion.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2011-2015 Akira Takahashi
  3. // Copyright (c) 2011-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2015-2020.
  5. // Modifications copyright (c) 2015-2020, Oracle and/or its affiliates.
  6. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_FUSION_HPP
  12. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_FUSION_HPP
  13. #include <cstddef>
  14. #include <type_traits>
  15. #include <boost/fusion/include/is_sequence.hpp>
  16. #include <boost/fusion/include/size.hpp>
  17. #include <boost/fusion/include/tag_of.hpp>
  18. #include <boost/fusion/include/front.hpp>
  19. #include <boost/fusion/include/at.hpp>
  20. #include <boost/fusion/mpl.hpp>
  21. #include <boost/mpl/and.hpp>
  22. #include <boost/mpl/count_if.hpp>
  23. #include <boost/mpl/front.hpp>
  24. #include <boost/mpl/placeholders.hpp>
  25. #include <boost/mpl/pop_front.hpp>
  26. #include <boost/mpl/size.hpp>
  27. #include <boost/type_traits/is_same.hpp>
  28. #include <boost/geometry/core/access.hpp>
  29. #include <boost/geometry/core/coordinate_dimension.hpp>
  30. #include <boost/geometry/core/coordinate_system.hpp>
  31. #include <boost/geometry/core/coordinate_type.hpp>
  32. #include <boost/geometry/core/point_type.hpp>
  33. #include <boost/geometry/core/tags.hpp>
  34. namespace boost { namespace geometry
  35. {
  36. namespace fusion_adapt_detail
  37. {
  38. template <class Sequence>
  39. struct all_same :
  40. std::integral_constant
  41. <
  42. bool,
  43. boost::mpl::count_if<
  44. Sequence,
  45. boost::is_same<
  46. typename boost::mpl::front<Sequence>::type,
  47. boost::mpl::_
  48. >
  49. >::value == boost::mpl::size<Sequence>::value
  50. >
  51. {};
  52. template <class Sequence>
  53. struct is_coordinate_size
  54. : std::integral_constant
  55. <
  56. bool,
  57. (boost::fusion::result_of::size<Sequence>::value == 2
  58. || boost::fusion::result_of::size<Sequence>::value == 3)
  59. >
  60. {};
  61. template
  62. <
  63. typename Sequence,
  64. bool IsSequence = boost::fusion::traits::is_sequence<Sequence>::value
  65. >
  66. struct is_fusion_sequence
  67. : std::integral_constant
  68. <
  69. bool,
  70. (fusion_adapt_detail::is_coordinate_size<Sequence>::value
  71. && fusion_adapt_detail::all_same<Sequence>::value)
  72. >
  73. {};
  74. template<typename Sequence>
  75. struct is_fusion_sequence<Sequence, false>
  76. : std::false_type
  77. {};
  78. } // namespace fusion_adapt_detail
  79. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  80. namespace traits
  81. {
  82. // Boost Fusion Sequence, 2D or 3D
  83. template <typename Sequence>
  84. struct coordinate_type
  85. <
  86. Sequence,
  87. std::enable_if_t
  88. <
  89. fusion_adapt_detail::is_fusion_sequence<Sequence>::value
  90. >
  91. >
  92. {
  93. typedef typename boost::mpl::front<Sequence>::type type;
  94. };
  95. template <typename Sequence>
  96. struct dimension
  97. <
  98. Sequence,
  99. std::enable_if_t
  100. <
  101. fusion_adapt_detail::is_fusion_sequence<Sequence>::value
  102. >
  103. > : boost::mpl::size<Sequence>
  104. {};
  105. template <typename Sequence, std::size_t Dimension>
  106. struct access
  107. <
  108. Sequence,
  109. Dimension,
  110. std::enable_if_t
  111. <
  112. fusion_adapt_detail::is_fusion_sequence<Sequence>::value
  113. >
  114. >
  115. {
  116. typedef typename coordinate_type<Sequence>::type ctype;
  117. static inline ctype get(Sequence const& point)
  118. {
  119. return boost::fusion::at_c<Dimension>(point);
  120. }
  121. template <class CoordinateType>
  122. static inline void set(Sequence& point, CoordinateType const& value)
  123. {
  124. boost::fusion::at_c<Dimension>(point) = value;
  125. }
  126. };
  127. template <typename Sequence>
  128. struct tag
  129. <
  130. Sequence,
  131. std::enable_if_t
  132. <
  133. fusion_adapt_detail::is_fusion_sequence<Sequence>::value
  134. >
  135. >
  136. {
  137. typedef point_tag type;
  138. };
  139. } // namespace traits
  140. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  141. }} // namespace boost::geometry
  142. // Convenience registration macro to bind a Fusion sequence to a CS
  143. #define BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(CoordinateSystem) \
  144. namespace boost { namespace geometry { namespace traits { \
  145. template <typename Sequence> \
  146. struct coordinate_system \
  147. < \
  148. Sequence, \
  149. std::enable_if_t \
  150. < \
  151. fusion_adapt_detail::is_fusion_sequence<Sequence>::value \
  152. > \
  153. > \
  154. { typedef CoordinateSystem type; }; \
  155. }}}
  156. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_FUSION_HPP