segments_encoded_base.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. class segments_encoded_base::iterator
  17. {
  18. detail::segments_iter_impl it_;
  19. friend class url_base;
  20. friend class segments_encoded_base;
  21. friend class segments_encoded_ref;
  22. iterator(detail::path_ref const&) noexcept;
  23. iterator(detail::path_ref const&, int) noexcept;
  24. iterator(
  25. detail::segments_iter_impl const& it) noexcept
  26. : it_(it)
  27. {
  28. }
  29. public:
  30. using value_type =
  31. segments_encoded_base::value_type;
  32. using reference =
  33. segments_encoded_base::reference;
  34. using pointer = reference;
  35. using difference_type = std::ptrdiff_t;
  36. using iterator_category =
  37. std::bidirectional_iterator_tag;
  38. iterator() = default;
  39. iterator(iterator const&) = default;
  40. iterator& operator=(
  41. iterator const&) = default;
  42. reference
  43. operator*() const noexcept
  44. {
  45. return it_.dereference();
  46. }
  47. pointer
  48. operator->() const noexcept
  49. {
  50. return it_.dereference();
  51. }
  52. iterator&
  53. operator++() noexcept
  54. {
  55. it_.increment();
  56. return *this;
  57. }
  58. iterator&
  59. operator--() noexcept
  60. {
  61. it_.decrement();
  62. return *this;
  63. }
  64. iterator
  65. operator++(int) noexcept
  66. {
  67. auto tmp = *this;
  68. ++*this;
  69. return tmp;
  70. }
  71. iterator
  72. operator--(int) noexcept
  73. {
  74. auto tmp = *this;
  75. --*this;
  76. return tmp;
  77. }
  78. bool
  79. operator==(
  80. iterator const& other) const noexcept
  81. {
  82. return it_.equal(other.it_);
  83. }
  84. bool
  85. operator!=(
  86. iterator const& other) const noexcept
  87. {
  88. return ! it_.equal(other.it_);
  89. }
  90. };
  91. //------------------------------------------------
  92. inline
  93. pct_string_view
  94. segments_encoded_base::
  95. front() const noexcept
  96. {
  97. BOOST_ASSERT(! empty());
  98. return *begin();
  99. }
  100. inline
  101. pct_string_view
  102. segments_encoded_base::
  103. back() const noexcept
  104. {
  105. BOOST_ASSERT(! empty());
  106. return *--end();
  107. }
  108. } // urls
  109. } // boost
  110. #endif