all_custom_linestring.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_LINESTRING_HPP
  8. #define GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_LINESTRING_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_linestring : public all_custom_container<P>
  17. {};
  18. // 1. Adapt to Boost.Geometry
  19. namespace boost { namespace geometry
  20. {
  21. namespace traits
  22. {
  23. template <typename Point>
  24. struct tag<all_custom_linestring<Point> >
  25. {
  26. typedef linestring_tag type;
  27. };
  28. // Implement traits for the mutable als
  29. // These are all optional traits (normally / default they are implemented
  30. // conforming std:: functionality)
  31. template <typename Point>
  32. struct clear<all_custom_linestring<Point> >
  33. {
  34. static inline void apply(all_custom_linestring<Point>& als)
  35. {
  36. als.custom_clear();
  37. }
  38. };
  39. template <typename Point>
  40. struct push_back<all_custom_linestring<Point> >
  41. {
  42. static inline void apply(all_custom_linestring<Point>& als, Point const& point)
  43. {
  44. als.custom_push_back(point);
  45. }
  46. };
  47. template <typename Point>
  48. struct resize<all_custom_linestring<Point> >
  49. {
  50. static inline void apply(all_custom_linestring<Point>& als, std::size_t new_size)
  51. {
  52. als.custom_resize(new_size);
  53. }
  54. };
  55. } // namespace traits
  56. }} // namespace boost::geometry
  57. // 2a. Adapt to Boost.Range, meta-functions
  58. namespace boost
  59. {
  60. template<typename Point>
  61. struct range_mutable_iterator<all_custom_linestring<Point> >
  62. {
  63. typedef typename all_custom_linestring<Point>::custom_iterator_type type;
  64. };
  65. template<typename Point>
  66. struct range_const_iterator<all_custom_linestring<Point> >
  67. {
  68. typedef typename all_custom_linestring<Point>::custom_const_iterator_type type;
  69. };
  70. } // namespace boost
  71. // 2b. Adapt to Boost.Range, part 2, ADP
  72. template<typename Point>
  73. inline typename all_custom_linestring<Point>::custom_iterator_type
  74. range_begin(all_custom_linestring<Point>& als)
  75. {
  76. return als.custom_begin();
  77. }
  78. template<typename Point>
  79. inline typename all_custom_linestring<Point>::custom_const_iterator_type
  80. range_begin(all_custom_linestring<Point> const& als)
  81. {
  82. return als.custom_begin();
  83. }
  84. template<typename Point>
  85. inline typename all_custom_linestring<Point>::custom_iterator_type
  86. range_end(all_custom_linestring<Point>& als)
  87. {
  88. return als.custom_end();
  89. }
  90. template<typename Point>
  91. inline typename all_custom_linestring<Point>::custom_const_iterator_type
  92. range_end(all_custom_linestring<Point> const& als)
  93. {
  94. return als.custom_end();
  95. }
  96. // (Optional)
  97. template<typename Point>
  98. inline std::size_t range_calculate_size(all_custom_linestring<Point> const& als)
  99. {
  100. return als.custom_size();
  101. }
  102. // 3. There used to be a std::back_insert adaption but that is now done using push_back
  103. #endif // GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_LINESTRING_HPP