all_custom_ring.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is 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. #ifndef GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_RING_HPP
  8. #define GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_RING_HPP
  9. #include <cstddef>
  10. #include <boost/range.hpp>
  11. #include <boost/geometry/core/mutable_range.hpp>
  12. #include <boost/geometry/core/tag.hpp>
  13. #include <boost/geometry/core/tags.hpp>
  14. #include <test_geometries/all_custom_container.hpp>
  15. template <typename P>
  16. class all_custom_ring : public all_custom_container<P>
  17. {};
  18. // Note that the things below are nearly all identical to implementation
  19. // in *linestring, but it seems not possible to re-use this (without macro's)
  20. // (the only thing DIFFERENT is the tag)
  21. // 1. Adapt to Boost.Geometry
  22. namespace boost { namespace geometry
  23. {
  24. namespace traits
  25. {
  26. template <typename Point>
  27. struct tag<all_custom_ring<Point> >
  28. {
  29. typedef ring_tag type;
  30. };
  31. // Implement traits for mutable actions
  32. // These are all optional traits (normally / default they are implemented
  33. // conforming std:: functionality)
  34. template <typename Point>
  35. struct clear<all_custom_ring<Point> >
  36. {
  37. static inline void apply(all_custom_ring<Point>& acr)
  38. {
  39. acr.custom_clear();
  40. }
  41. };
  42. template <typename Point>
  43. struct push_back<all_custom_ring<Point> >
  44. {
  45. static inline void apply(all_custom_ring<Point>& acr, Point const& point)
  46. {
  47. acr.custom_push_back(point);
  48. }
  49. };
  50. template <typename Point>
  51. struct resize<all_custom_ring<Point> >
  52. {
  53. static inline void apply(all_custom_ring<Point>& acr, std::size_t new_size)
  54. {
  55. acr.custom_resize(new_size);
  56. }
  57. };
  58. } // namespace traits
  59. }} // namespace boost::geometry
  60. // 2a. Adapt to Boost.Range, meta-functions
  61. namespace boost
  62. {
  63. template<typename Point>
  64. struct range_mutable_iterator<all_custom_ring<Point> >
  65. {
  66. typedef typename all_custom_ring<Point>::custom_iterator_type type;
  67. };
  68. template<typename Point>
  69. struct range_const_iterator<all_custom_ring<Point> >
  70. {
  71. typedef typename all_custom_ring<Point>::custom_const_iterator_type type;
  72. };
  73. } // namespace boost
  74. // 2b. Adapt to Boost.Range, part 2, ADP
  75. template<typename Point>
  76. inline typename all_custom_ring<Point>::custom_iterator_type
  77. range_begin(all_custom_ring<Point>& acr)
  78. {
  79. return acr.custom_begin();
  80. }
  81. template<typename Point>
  82. inline typename all_custom_ring<Point>::custom_const_iterator_type
  83. range_begin(all_custom_ring<Point> const& acr)
  84. {
  85. return acr.custom_begin();
  86. }
  87. template<typename Point>
  88. inline typename all_custom_ring<Point>::custom_iterator_type
  89. range_end(all_custom_ring<Point>& acr)
  90. {
  91. return acr.custom_end();
  92. }
  93. template<typename Point>
  94. inline typename all_custom_ring<Point>::custom_const_iterator_type
  95. range_end(all_custom_ring<Point> const& acr)
  96. {
  97. return acr.custom_end();
  98. }
  99. // (Optional)
  100. template<typename Point>
  101. inline std::size_t range_calculate_size(all_custom_ring<Point> const& acr)
  102. {
  103. return acr.custom_size();
  104. }
  105. #endif // GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_RING_HPP