mutable_range.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2020-2023.
  6. // Modifications copyright (c) 2020-2023 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_CORE_MUTABLE_RANGE_HPP
  15. #define BOOST_GEOMETRY_CORE_MUTABLE_RANGE_HPP
  16. #include <type_traits>
  17. #include <boost/range/size_type.hpp>
  18. #include <boost/range/value_type.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. namespace traits
  22. {
  23. /*!
  24. \brief Metafunction to define the argument passed to the three
  25. traits classes clear, push_back and resize
  26. \ingroup mutable_range
  27. */
  28. template <typename Range>
  29. struct rvalue_type
  30. {
  31. typedef typename std::remove_reference<Range>::type& type;
  32. };
  33. /*!
  34. \brief Traits class to clear a geometry
  35. \ingroup mutable_range
  36. */
  37. template <typename Range>
  38. struct clear
  39. {
  40. static inline void apply(typename rvalue_type<Range>::type range)
  41. {
  42. range.clear();
  43. }
  44. };
  45. /*!
  46. \brief Traits class to append a point to a range (ring, linestring, multi*)
  47. \ingroup mutable_range
  48. */
  49. template <typename Range>
  50. struct push_back
  51. {
  52. typedef typename boost::range_value
  53. <
  54. typename std::remove_reference<Range>::type
  55. >::type item_type;
  56. static inline void apply(typename rvalue_type<Range>::type range,
  57. item_type const& item)
  58. {
  59. range.push_back(item);
  60. }
  61. static inline void apply(typename rvalue_type<Range>::type range,
  62. item_type && item)
  63. {
  64. range.push_back(std::move(item));
  65. }
  66. };
  67. /*!
  68. \brief Traits class to append an element of geometry collection
  69. \ingroup mutable_range
  70. */
  71. template <typename Range>
  72. struct emplace_back
  73. {
  74. // When specializing it'd be enough to only implement it for one argument
  75. // because we'll use it to pass one object of type potentially different
  76. // than range_value but which range_value can be constructed from.
  77. template <typename ...Args>
  78. static inline void apply(typename rvalue_type<Range>::type range,
  79. Args&&... args)
  80. {
  81. range.emplace_back(std::forward<Args>(args)...);
  82. }
  83. };
  84. /*!
  85. \brief Traits class to append a point to a range (ring, linestring, multi*)
  86. \ingroup mutable_range
  87. */
  88. template <typename Range>
  89. struct resize
  90. {
  91. using size_type = typename boost::range_size
  92. <
  93. typename std::remove_reference<Range>::type
  94. >::type;
  95. static inline void apply(typename rvalue_type<Range>::type range,
  96. size_type new_size)
  97. {
  98. range.resize(new_size);
  99. }
  100. };
  101. } // namespace traits
  102. }} // namespace boost::geometry
  103. #endif // BOOST_GEOMETRY_CORE_MUTABLE_RANGE_HPP