polygon_set_traits.hpp 5.3 KB

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