Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:48:02

0001 /*
0002   Copyright 2008 Intel Corporation
0003 
0004   Use, modification and distribution are subject to the Boost Software License,
0005   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006   http://www.boost.org/LICENSE_1_0.txt).
0007 */
0008 #ifndef BOOST_POLYGON_POLYGON_SET_TRAITS_HPP
0009 #define BOOST_POLYGON_POLYGON_SET_TRAITS_HPP
0010 namespace boost { namespace polygon{
0011 
0012   struct polygon_set_concept {};
0013 
0014   //default definition of polygon set traits works for any model of polygon , polygon with holes or any vector or list thereof
0015   template <typename T>
0016   struct polygon_set_traits {
0017     typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
0018     typedef typename get_iterator_type<T>::type iterator_type;
0019     typedef T operator_arg_type;
0020 
0021     static inline iterator_type begin(const T& polygon_set) {
0022       return get_iterator_type<T>::begin(polygon_set);
0023     }
0024 
0025     static inline iterator_type end(const T& polygon_set) {
0026       return get_iterator_type<T>::end(polygon_set);
0027     }
0028 
0029     static inline bool clean(const T& ) { return false; }
0030 
0031     static inline bool sorted(const T& ) { return false; }
0032   };
0033 
0034   template <typename T>
0035   struct is_polygonal_concept { typedef gtl_no type; };
0036   template <>
0037   struct is_polygonal_concept<polygon_concept> { typedef gtl_yes type; };
0038   template <>
0039   struct is_polygonal_concept<polygon_with_holes_concept> { typedef gtl_yes type; };
0040   template <>
0041   struct is_polygonal_concept<polygon_set_concept> { typedef gtl_yes type; };
0042 
0043   template <typename T>
0044   struct is_polygon_set_type {
0045     typedef typename is_polygonal_concept<typename geometry_concept<T>::type>::type type;
0046   };
0047   template <typename T>
0048   struct is_polygon_set_type<std::list<T> > {
0049     typedef typename gtl_or<
0050       typename is_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type,
0051       typename is_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
0052   };
0053   template <typename T>
0054   struct is_polygon_set_type<std::vector<T> > {
0055     typedef typename gtl_or<
0056       typename is_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type,
0057       typename is_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
0058   };
0059 
0060   template <typename T>
0061   struct is_mutable_polygon_set_type {
0062     typedef typename gtl_same_type<polygon_set_concept, typename geometry_concept<T>::type>::type type;
0063   };
0064   template <typename T>
0065   struct is_mutable_polygon_set_type<std::list<T> > {
0066     typedef typename gtl_or<
0067       typename gtl_same_type<polygon_set_concept, typename geometry_concept<std::list<T> >::type>::type,
0068       typename is_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
0069   };
0070   template <typename T>
0071   struct is_mutable_polygon_set_type<std::vector<T> > {
0072     typedef typename gtl_or<
0073       typename gtl_same_type<polygon_set_concept, typename geometry_concept<std::vector<T> >::type>::type,
0074       typename is_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
0075   };
0076 
0077   template <typename T>
0078   struct polygon_set_mutable_traits {};
0079   template <typename T>
0080   struct polygon_set_mutable_traits<std::list<T> > {
0081     template <typename input_iterator_type>
0082     static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
0083       polygon_set.clear();
0084       polygon_set_data<typename polygon_set_traits<std::list<T> >::coordinate_type> ps;
0085       ps.reserve(std::distance(input_begin, input_end));
0086       ps.insert(input_begin, input_end);
0087       ps.get(polygon_set);
0088     }
0089   };
0090   template <typename T>
0091   struct polygon_set_mutable_traits<std::vector<T> > {
0092     template <typename input_iterator_type>
0093     static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
0094       polygon_set.clear();
0095       size_t num_ele = std::distance(input_begin, input_end);
0096       polygon_set.reserve(num_ele);
0097       polygon_set_data<typename polygon_set_traits<std::list<T> >::coordinate_type> ps;
0098       ps.reserve(num_ele);
0099       ps.insert(input_begin, input_end);
0100       ps.get(polygon_set);
0101     }
0102   };
0103 
0104   template <typename T>
0105   struct polygon_set_mutable_traits<polygon_set_data<T> > {
0106     template <typename input_iterator_type>
0107     static inline void set(polygon_set_data<T>& polygon_set,
0108                            input_iterator_type input_begin, input_iterator_type input_end) {
0109       polygon_set.set(input_begin, input_end);
0110     }
0111   };
0112   template <typename T>
0113   struct polygon_set_traits<polygon_set_data<T> > {
0114     typedef typename polygon_set_data<T>::coordinate_type coordinate_type;
0115     typedef typename polygon_set_data<T>::iterator_type iterator_type;
0116     typedef typename polygon_set_data<T>::operator_arg_type operator_arg_type;
0117 
0118     static inline iterator_type begin(const polygon_set_data<T>& polygon_set) {
0119       return polygon_set.begin();
0120     }
0121 
0122     static inline iterator_type end(const polygon_set_data<T>& polygon_set) {
0123       return polygon_set.end();
0124     }
0125 
0126     static inline bool clean(const polygon_set_data<T>& polygon_set) { polygon_set.clean(); return true; }
0127 
0128     static inline bool sorted(const polygon_set_data<T>& polygon_set) { polygon_set.sort(); return true; }
0129 
0130   };
0131 }
0132 }
0133 #endif