Line data Source code
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 :
11 : #ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
12 : #define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
13 :
14 : #include <boost/url/detail/segments_iter_impl.hpp>
15 : #include <boost/assert.hpp>
16 :
17 : namespace boost {
18 : namespace urls {
19 : namespace detail {
20 : struct segments_iter_access;
21 : }
22 :
23 : class segments_encoded_base::iterator
24 : {
25 : detail::segments_iter_impl it_;
26 :
27 : friend class url_base;
28 : friend class segments_encoded_base;
29 : friend class segments_encoded_ref;
30 : friend struct detail::segments_iter_access;
31 :
32 : iterator(detail::path_ref const&) noexcept;
33 : iterator(detail::path_ref const&, int) noexcept;
34 :
35 387 : iterator(
36 : detail::segments_iter_impl const& it) noexcept
37 387 : : it_(it)
38 : {
39 387 : }
40 :
41 : public:
42 : using value_type =
43 : segments_encoded_base::value_type;
44 : using reference =
45 : segments_encoded_base::reference;
46 : using pointer = reference;
47 : using difference_type = std::ptrdiff_t;
48 : using iterator_category =
49 : std::bidirectional_iterator_tag;
50 :
51 : iterator() = default;
52 : iterator(iterator const&) = default;
53 : iterator& operator=(
54 : iterator const&) = default;
55 :
56 : reference
57 3869 : operator*() const noexcept
58 : {
59 3869 : return it_.dereference();
60 : }
61 :
62 : pointer
63 21 : operator->() const noexcept
64 : {
65 21 : return it_.dereference();
66 : }
67 :
68 : iterator&
69 1956 : operator++() noexcept
70 : {
71 1956 : it_.increment();
72 1956 : return *this;
73 : }
74 :
75 : iterator&
76 1512 : operator--() noexcept
77 : {
78 1512 : it_.decrement();
79 1512 : return *this;
80 : }
81 :
82 : iterator
83 600 : operator++(int) noexcept
84 : {
85 600 : auto tmp = *this;
86 600 : ++*this;
87 600 : return tmp;
88 : }
89 :
90 : iterator
91 21 : operator--(int) noexcept
92 : {
93 21 : auto tmp = *this;
94 21 : --*this;
95 21 : return tmp;
96 : }
97 :
98 : bool
99 696 : operator==(
100 : iterator const& other) const noexcept
101 : {
102 696 : return it_.equal(other.it_);
103 : }
104 :
105 : bool
106 3471 : operator!=(
107 : iterator const& other) const noexcept
108 : {
109 3471 : return ! it_.equal(other.it_);
110 : }
111 : };
112 :
113 : //------------------------------------------------
114 :
115 : inline
116 : pct_string_view
117 97 : segments_encoded_base::
118 : front() const noexcept
119 : {
120 97 : BOOST_ASSERT(! empty());
121 97 : return *begin();
122 : }
123 :
124 : inline
125 : pct_string_view
126 16 : segments_encoded_base::
127 : back() const noexcept
128 : {
129 16 : BOOST_ASSERT(! empty());
130 16 : return *--end();
131 : }
132 :
133 : } // urls
134 : } // boost
135 :
136 : #endif
|