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_BASE_HPP
12 : #define BOOST_URL_IMPL_SEGMENTS_BASE_HPP
13 :
14 : #include <boost/url/detail/segments_iter_impl.hpp>
15 : #include <boost/assert.hpp>
16 : #include <iterator>
17 :
18 : namespace boost {
19 : namespace urls {
20 : namespace detail {
21 : struct segments_iter_access;
22 : }
23 :
24 : class segments_base::iterator
25 : {
26 : detail::segments_iter_impl it_;
27 :
28 : friend class segments_base;
29 : friend class segments_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 156 : iterator(
36 : detail::segments_iter_impl const& it) noexcept
37 156 : : it_(it)
38 : {
39 156 : }
40 :
41 : public:
42 : using value_type = segments_base::value_type;
43 : using reference = segments_base::reference;
44 : using pointer = reference;
45 : using difference_type =
46 : segments_base::difference_type;
47 : using iterator_category =
48 : std::bidirectional_iterator_tag;
49 :
50 : iterator() = default;
51 : iterator(iterator const&) = default;
52 : iterator& operator=(
53 : iterator const&) noexcept = default;
54 :
55 : BOOST_URL_DECL
56 : reference
57 : operator*() const;
58 :
59 : // the return value is too expensive
60 : pointer operator->() const = delete;
61 :
62 : iterator&
63 819 : operator++() noexcept
64 : {
65 819 : it_.increment();
66 819 : return *this;
67 : }
68 :
69 : iterator&
70 72 : operator--() noexcept
71 : {
72 72 : it_.decrement();
73 72 : return *this;
74 : }
75 :
76 : iterator
77 36 : operator++(int) noexcept
78 : {
79 36 : auto tmp = *this;
80 36 : ++*this;
81 36 : return tmp;
82 : }
83 :
84 : iterator
85 21 : operator--(int) noexcept
86 : {
87 21 : auto tmp = *this;
88 21 : --*this;
89 21 : return tmp;
90 : }
91 :
92 : bool
93 64 : operator==(
94 : iterator const& other) const noexcept
95 : {
96 64 : return it_.equal(other.it_);
97 : }
98 :
99 : bool
100 906 : operator!=(
101 : iterator const& other) const noexcept
102 : {
103 906 : return ! it_.equal(other.it_);
104 : }
105 : };
106 :
107 : //------------------------------------------------
108 :
109 : inline
110 : std::string
111 27 : segments_base::
112 : front() const noexcept
113 : {
114 27 : BOOST_ASSERT(! empty());
115 27 : return *begin();
116 : }
117 :
118 : inline
119 : std::string
120 20 : segments_base::
121 : back() const noexcept
122 : {
123 20 : BOOST_ASSERT(! empty());
124 20 : return *--end();
125 : }
126 :
127 : } // urls
128 : } // boost
129 :
130 : #endif
|