1 | /* |
2 | Copyright 2008 Intel Corporation |
3 | |
4 | Use, modification and distribution are 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 | */ |
8 | #ifndef BOOST_POLYGON_POLYGON_SET_TRAITS_HPP |
9 | #define BOOST_POLYGON_POLYGON_SET_TRAITS_HPP |
10 | namespace boost { namespace polygon{ |
11 | |
12 | struct polygon_set_concept {}; |
13 | |
14 | //default definition of polygon set traits works for any model of polygon , polygon with holes or any vector or list thereof |
15 | template <typename T> |
16 | struct polygon_set_traits { |
17 | typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type; |
18 | typedef typename get_iterator_type<T>::type iterator_type; |
19 | typedef T operator_arg_type; |
20 | |
21 | static inline iterator_type begin(const T& polygon_set) { |
22 | return get_iterator_type<T>::begin(polygon_set); |
23 | } |
24 | |
25 | static inline iterator_type end(const T& polygon_set) { |
26 | return get_iterator_type<T>::end(polygon_set); |
27 | } |
28 | |
29 | static inline bool clean(const T& ) { return false; } |
30 | |
31 | static inline bool sorted(const T& ) { return false; } |
32 | }; |
33 | |
34 | template <typename T> |
35 | struct is_polygonal_concept { typedef gtl_no type; }; |
36 | template <> |
37 | struct is_polygonal_concept<polygon_concept> { typedef gtl_yes type; }; |
38 | template <> |
39 | struct is_polygonal_concept<polygon_with_holes_concept> { typedef gtl_yes type; }; |
40 | template <> |
41 | struct is_polygonal_concept<polygon_set_concept> { typedef gtl_yes type; }; |
42 | |
43 | template <typename T> |
44 | struct is_polygon_set_type { |
45 | typedef typename is_polygonal_concept<typename geometry_concept<T>::type>::type type; |
46 | }; |
47 | template <typename T> |
48 | struct is_polygon_set_type<std::list<T> > { |
49 | typedef typename gtl_or< |
50 | typename is_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type, |
51 | typename is_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type; |
52 | }; |
53 | template <typename T> |
54 | struct is_polygon_set_type<std::vector<T> > { |
55 | typedef typename gtl_or< |
56 | typename is_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type, |
57 | typename is_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type; |
58 | }; |
59 | |
60 | template <typename T> |
61 | struct is_mutable_polygon_set_type { |
62 | typedef typename gtl_same_type<polygon_set_concept, typename geometry_concept<T>::type>::type type; |
63 | }; |
64 | template <typename T> |
65 | struct is_mutable_polygon_set_type<std::list<T> > { |
66 | typedef typename gtl_or< |
67 | typename gtl_same_type<polygon_set_concept, typename geometry_concept<std::list<T> >::type>::type, |
68 | typename is_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type; |
69 | }; |
70 | template <typename T> |
71 | struct is_mutable_polygon_set_type<std::vector<T> > { |
72 | typedef typename gtl_or< |
73 | typename gtl_same_type<polygon_set_concept, typename geometry_concept<std::vector<T> >::type>::type, |
74 | typename is_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type; |
75 | }; |
76 | |
77 | template <typename T> |
78 | struct polygon_set_mutable_traits {}; |
79 | template <typename T> |
80 | struct polygon_set_mutable_traits<std::list<T> > { |
81 | template <typename input_iterator_type> |
82 | static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) { |
83 | polygon_set.clear(); |
84 | polygon_set_data<typename polygon_set_traits<std::list<T> >::coordinate_type> ps; |
85 | ps.reserve(std::distance(input_begin, input_end)); |
86 | ps.insert(input_begin, input_end); |
87 | ps.get(polygon_set); |
88 | } |
89 | }; |
90 | template <typename T> |
91 | struct polygon_set_mutable_traits<std::vector<T> > { |
92 | template <typename input_iterator_type> |
93 | static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) { |
94 | polygon_set.clear(); |
95 | size_t num_ele = std::distance(input_begin, input_end); |
96 | polygon_set.reserve(num_ele); |
97 | polygon_set_data<typename polygon_set_traits<std::list<T> >::coordinate_type> ps; |
98 | ps.reserve(num_ele); |
99 | ps.insert(input_begin, input_end); |
100 | ps.get(polygon_set); |
101 | } |
102 | }; |
103 | |
104 | template <typename T> |
105 | struct polygon_set_mutable_traits<polygon_set_data<T> > { |
106 | template <typename input_iterator_type> |
107 | static inline void set(polygon_set_data<T>& polygon_set, |
108 | input_iterator_type input_begin, input_iterator_type input_end) { |
109 | polygon_set.set(input_begin, input_end); |
110 | } |
111 | }; |
112 | template <typename T> |
113 | struct polygon_set_traits<polygon_set_data<T> > { |
114 | typedef typename polygon_set_data<T>::coordinate_type coordinate_type; |
115 | typedef typename polygon_set_data<T>::iterator_type iterator_type; |
116 | typedef typename polygon_set_data<T>::operator_arg_type operator_arg_type; |
117 | |
118 | static inline iterator_type begin(const polygon_set_data<T>& polygon_set) { |
119 | return polygon_set.begin(); |
120 | } |
121 | |
122 | static inline iterator_type end(const polygon_set_data<T>& polygon_set) { |
123 | return polygon_set.end(); |
124 | } |
125 | |
126 | static inline bool clean(const polygon_set_data<T>& polygon_set) { polygon_set.clean(); return true; } |
127 | |
128 | static inline bool sorted(const polygon_set_data<T>& polygon_set) { polygon_set.sort(); return true; } |
129 | |
130 | }; |
131 | } |
132 | } |
133 | #endif |
134 | |