summaryrefslogtreecommitdiff
path: root/boost/geometry/algorithms/detail/select_geometry_type.hpp
blob: 5592fa5c4b4d37069767cc869bfe7263d0cf28f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Boost.Geometry

// Copyright (c) 2021, Oracle and/or its affiliates.

// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html

#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SELECT_GEOMETRY_TYPE_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SELECT_GEOMETRY_TYPE_HPP

#include <boost/geometry/core/geometry_types.hpp>
#include <boost/geometry/core/static_assert.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/util/sequence.hpp>
#include <boost/geometry/util/type_traits.hpp>

namespace boost { namespace geometry
{

#ifndef DOXYGEN_NO_DETAIL
namespace detail
{


template <typename Geometry, typename Tag = typename tag<Geometry>::type>
struct first_geometry_type
{
    using type = Geometry;
};

template <typename Geometry>
struct first_geometry_type<Geometry, geometry_collection_tag>
{
    template <typename T>
    using pred = util::bool_constant
        <
            ! util::is_dynamic_geometry<T>::value
            && ! util::is_geometry_collection<T>::value
        >;

    using type = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry>::type,
            pred
        >::type;
};

template <typename Geometry>
struct first_geometry_type<Geometry, dynamic_geometry_tag>
    : first_geometry_type<Geometry, geometry_collection_tag>
{};


template
<
    typename Geometry,
    bool IsDynamicOrCollection = util::is_dynamic_geometry<Geometry>::value
                              || util::is_geometry_collection<Geometry>::value
>
struct geometry_types
{
    using type = util::type_sequence<std::remove_const_t<Geometry>>;
};

template <typename Geometry>
struct geometry_types<Geometry, true>
{
    using type = typename traits::geometry_types<std::remove_const_t<Geometry>>::type;
};


template
<
    typename Geometry,
    template <typename, typename> class LessPred,
    bool IsDynamicOrCollection = util::is_dynamic_geometry<Geometry>::value
                              || util::is_geometry_collection<Geometry>::value
>
struct select_geometry_type
{
    using type = Geometry;
};

template
<
    typename Geometry,
    template <typename, typename> class LessPred
>
struct select_geometry_type<Geometry, LessPred, true>
    : util::sequence_min_element
        <
            typename traits::geometry_types<std::remove_const_t<Geometry>>::type,
            LessPred
        >
{};


template
<
    typename Geometry1, typename Geometry2,
    template <typename, typename> class LessPred,
    bool IsDynamicOrCollection = util::is_dynamic_geometry<Geometry1>::value
                              || util::is_dynamic_geometry<Geometry2>::value
                              || util::is_geometry_collection<Geometry1>::value
                              || util::is_geometry_collection<Geometry2>::value
>
struct select_geometry_types
{
    using type = util::type_sequence
        <
            std::remove_const_t<Geometry1>,
            std::remove_const_t<Geometry2>
        >;
};

template
<
    typename Geometry1, typename Geometry2,
    template <typename, typename> class LessPred
>
struct select_geometry_types<Geometry1, Geometry2, LessPred, true>
    : util::sequence_min_element
        <
            typename util::sequence_combine
                <
                    typename geometry_types<Geometry1>::type,
                    typename geometry_types<Geometry2>::type
                >::type,
            LessPred
        >
{};


} // namespace detail
#endif // DOXYGEN_NO_DETAIL

}} // namespace boost::geometry

#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SELECT_GEOMETRY_TYPE_HPP