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