1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2011-2015 Akira Takahashi
4 // Copyright (c) 2011-2015 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2015.
7 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
9 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_FUSION_HPP
16 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_FUSION_HPP
21 #include <boost/core/enable_if.hpp>
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>
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>
37 #include <boost/type_traits/is_same.hpp>
38 #include <boost/type_traits/remove_reference.hpp>
40 #include <boost/geometry/core/access.hpp>
41 #include <boost/geometry/core/coordinate_dimension.hpp>
42 #include <boost/geometry/core/coordinate_system.hpp>
43 #include <boost/geometry/core/coordinate_type.hpp>
44 #include <boost/geometry/core/point_type.hpp>
45 #include <boost/geometry/core/tags.hpp>
48 namespace boost { namespace geometry
51 namespace fusion_adapt_detail
54 template <class Sequence>
60 typename boost::mpl::front<Sequence>::type,
63 >::value == boost::mpl::size<Sequence>::value
67 template <class Sequence>
68 struct is_coordinate_size : boost::mpl::bool_<
69 boost::fusion::result_of::size<Sequence>::value == 2 ||
70 boost::fusion::result_of::size<Sequence>::value == 3> {};
72 template<typename Sequence>
73 struct is_fusion_sequence
74 : boost::mpl::and_<boost::fusion::traits::is_sequence<Sequence>,
75 fusion_adapt_detail::is_coordinate_size<Sequence>,
76 fusion_adapt_detail::all_same<Sequence> >
80 } // namespace fusion_adapt_detail
83 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
87 // Boost Fusion Sequence, 2D or 3D
88 template <typename Sequence>
89 struct coordinate_type
92 typename boost::enable_if
94 fusion_adapt_detail::is_fusion_sequence<Sequence>
98 typedef typename boost::mpl::front<Sequence>::type type;
102 template <typename Sequence>
106 typename boost::enable_if
108 fusion_adapt_detail::is_fusion_sequence<Sequence>
110 > : boost::mpl::size<Sequence>
114 template <typename Sequence, std::size_t Dimension>
119 typename boost::enable_if
121 fusion_adapt_detail::is_fusion_sequence<Sequence>
125 typedef typename coordinate_type<Sequence>::type ctype;
127 static inline ctype get(Sequence const& point)
129 return boost::fusion::at_c<Dimension>(point);
132 template <class CoordinateType>
133 static inline void set(Sequence& point, CoordinateType const& value)
135 boost::fusion::at_c<Dimension>(point) = value;
140 template <typename Sequence>
144 typename boost::enable_if
146 fusion_adapt_detail::is_fusion_sequence<Sequence>
150 typedef point_tag type;
154 } // namespace traits
156 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
159 }} // namespace boost::geometry
162 // Convenience registration macro to bind a Fusion sequence to a CS
163 #define BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(CoordinateSystem) \
164 namespace boost { namespace geometry { namespace traits { \
165 template <typename Sequence> \
166 struct coordinate_system \
169 typename boost::enable_if \
171 fusion_adapt_detail::is_fusion_sequence<Sequence> \
174 { typedef CoordinateSystem type; }; \
178 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_FUSION_HPP