params_base.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_PARAMS_BASE_HPP
  11. #define BOOST_URL_IMPL_PARAMS_BASE_HPP
  12. #include <boost/url/detail/params_iter_impl.hpp>
  13. #include <iterator>
  14. namespace boost {
  15. namespace urls {
  16. //------------------------------------------------
  17. class BOOST_URL_DECL params_base::iterator
  18. {
  19. detail::params_iter_impl it_;
  20. bool space_as_plus_ = true;
  21. friend class params_base;
  22. friend class params_ref;
  23. iterator(
  24. detail::query_ref const& ref,
  25. encoding_opts opt) noexcept;
  26. iterator(
  27. detail::query_ref const& impl,
  28. encoding_opts opt,
  29. int) noexcept;
  30. iterator(
  31. detail::params_iter_impl const& it,
  32. encoding_opts opt) noexcept
  33. : it_(it)
  34. , space_as_plus_(opt.space_as_plus)
  35. {
  36. }
  37. public:
  38. using value_type = params_base::value_type;
  39. using reference = params_base::reference;
  40. using pointer = reference;
  41. using difference_type =
  42. params_base::difference_type;
  43. using iterator_category =
  44. std::bidirectional_iterator_tag;
  45. iterator() = default;
  46. iterator(iterator const&) = default;
  47. iterator& operator=(
  48. iterator const&) noexcept = default;
  49. iterator&
  50. operator++() noexcept
  51. {
  52. it_.increment();
  53. return *this;
  54. }
  55. iterator
  56. operator++(int) noexcept
  57. {
  58. auto tmp = *this;
  59. ++*this;
  60. return tmp;
  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. reference
  76. operator*() const;
  77. // the return value is too expensive
  78. pointer operator->() const = delete;
  79. bool
  80. operator==(
  81. iterator const& other) const noexcept
  82. {
  83. return it_.equal(other.it_);
  84. }
  85. bool
  86. operator!=(
  87. iterator const& other) const noexcept
  88. {
  89. return ! it_.equal(other.it_);
  90. }
  91. };
  92. } // urls
  93. } // boost
  94. #endif