segments_encoded_base.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Official repository: https://github.com/boostorg/url
  9. //
  10. #ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
  11. #define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
  12. #include <boost/url/detail/segments_iter_impl.hpp>
  13. #include <boost/assert.hpp>
  14. namespace boost {
  15. namespace urls {
  16. namespace detail {
  17. struct segments_iter_access;
  18. }
  19. class segments_encoded_base::iterator
  20. {
  21. detail::segments_iter_impl it_;
  22. friend class url_base;
  23. friend class segments_encoded_base;
  24. friend class segments_encoded_ref;
  25. friend struct detail::segments_iter_access;
  26. iterator(detail::path_ref const&) noexcept;
  27. iterator(detail::path_ref const&, int) noexcept;
  28. iterator(
  29. detail::segments_iter_impl const& it) noexcept
  30. : it_(it)
  31. {
  32. }
  33. public:
  34. using value_type =
  35. segments_encoded_base::value_type;
  36. using reference =
  37. segments_encoded_base::reference;
  38. using pointer = reference;
  39. using difference_type = std::ptrdiff_t;
  40. using iterator_category =
  41. std::bidirectional_iterator_tag;
  42. iterator() = default;
  43. iterator(iterator const&) = default;
  44. iterator& operator=(
  45. iterator const&) = default;
  46. reference
  47. operator*() const noexcept
  48. {
  49. return it_.dereference();
  50. }
  51. pointer
  52. operator->() const noexcept
  53. {
  54. return it_.dereference();
  55. }
  56. iterator&
  57. operator++() noexcept
  58. {
  59. it_.increment();
  60. return *this;
  61. }
  62. iterator&
  63. operator--() noexcept
  64. {
  65. it_.decrement();
  66. return *this;
  67. }
  68. iterator
  69. operator++(int) noexcept
  70. {
  71. auto tmp = *this;
  72. ++*this;
  73. return tmp;
  74. }
  75. iterator
  76. operator--(int) noexcept
  77. {
  78. auto tmp = *this;
  79. --*this;
  80. return tmp;
  81. }
  82. bool
  83. operator==(
  84. iterator const& other) const noexcept
  85. {
  86. return it_.equal(other.it_);
  87. }
  88. bool
  89. operator!=(
  90. iterator const& other) const noexcept
  91. {
  92. return ! it_.equal(other.it_);
  93. }
  94. };
  95. //------------------------------------------------
  96. inline
  97. pct_string_view
  98. segments_encoded_base::
  99. front() const noexcept
  100. {
  101. BOOST_ASSERT(! empty());
  102. return *begin();
  103. }
  104. inline
  105. pct_string_view
  106. segments_encoded_base::
  107. back() const noexcept
  108. {
  109. BOOST_ASSERT(! empty());
  110. return *--end();
  111. }
  112. } // urls
  113. } // boost
  114. #endif