2 Copyright 2008 Intel Corporation
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).
8 #ifndef BOOST_POLYGON_POLYGON_SET_TRAITS_HPP
9 #define BOOST_POLYGON_POLYGON_SET_TRAITS_HPP
10 namespace boost { namespace polygon{
12 struct polygon_set_concept {};
14 //default definition of polygon set traits works for any model of polygon , polygon with holes or any vector or list thereof
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;
21 static inline iterator_type begin(const T& polygon_set) {
22 return get_iterator_type<T>::begin(polygon_set);
25 static inline iterator_type end(const T& polygon_set) {
26 return get_iterator_type<T>::end(polygon_set);
29 static inline bool clean(const T& ) { return false; }
31 static inline bool sorted(const T& ) { return false; }
35 struct is_polygonal_concept { typedef gtl_no type; };
37 struct is_polygonal_concept<polygon_concept> { typedef gtl_yes type; };
39 struct is_polygonal_concept<polygon_with_holes_concept> { typedef gtl_yes type; };
41 struct is_polygonal_concept<polygon_set_concept> { typedef gtl_yes type; };
44 struct is_polygon_set_type {
45 typedef typename is_polygonal_concept<typename geometry_concept<T>::type>::type type;
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;
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;
61 struct is_mutable_polygon_set_type {
62 typedef typename gtl_same_type<polygon_set_concept, typename geometry_concept<T>::type>::type type;
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;
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;
78 struct polygon_set_mutable_traits {};
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) {
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);
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) {
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;
99 ps.insert(input_begin, input_end);
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);
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;
118 static inline iterator_type begin(const polygon_set_data<T>& polygon_set) {
119 return polygon_set.begin();
122 static inline iterator_type end(const polygon_set_data<T>& polygon_set) {
123 return polygon_set.end();
126 static inline bool clean(const polygon_set_data<T>& polygon_set) { polygon_set.clean(); return true; }
128 static inline bool sorted(const polygon_set_data<T>& polygon_set) { polygon_set.sort(); return true; }