1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
3  
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
11  
#ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
12  
#define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
12  
#define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP
13  

13  

14  
#include <boost/url/detail/segments_iter_impl.hpp>
14  
#include <boost/url/detail/segments_iter_impl.hpp>
15  
#include <boost/assert.hpp>
15  
#include <boost/assert.hpp>
16  

16  

17  
namespace boost {
17  
namespace boost {
18  
namespace urls {
18  
namespace urls {
19  
namespace detail {
19  
namespace detail {
20  
struct segments_iter_access;
20  
struct segments_iter_access;
21  
}
21  
}
22  

22  

23  
class segments_encoded_base::iterator
23  
class segments_encoded_base::iterator
24  
{
24  
{
25  
    detail::segments_iter_impl it_;
25  
    detail::segments_iter_impl it_;
26  

26  

27  
    friend class url_base;
27  
    friend class url_base;
28  
    friend class segments_encoded_base;
28  
    friend class segments_encoded_base;
29  
    friend class segments_encoded_ref;
29  
    friend class segments_encoded_ref;
30  
    friend struct detail::segments_iter_access;
30  
    friend struct detail::segments_iter_access;
31  

31  

32  
    iterator(detail::path_ref const&) noexcept;
32  
    iterator(detail::path_ref const&) noexcept;
33  
    iterator(detail::path_ref const&, int) noexcept;
33  
    iterator(detail::path_ref const&, int) noexcept;
34  

34  

35  
    iterator(
35  
    iterator(
36  
        detail::segments_iter_impl const& it) noexcept
36  
        detail::segments_iter_impl const& it) noexcept
37  
        : it_(it)
37  
        : it_(it)
38  
    {
38  
    {
39  
    }
39  
    }
40  

40  

41  
public:
41  
public:
42  
    using value_type =
42  
    using value_type =
43  
        segments_encoded_base::value_type;
43  
        segments_encoded_base::value_type;
44  
    using reference =
44  
    using reference =
45  
        segments_encoded_base::reference;
45  
        segments_encoded_base::reference;
46  
    using pointer = reference;
46  
    using pointer = reference;
47  
    using difference_type = std::ptrdiff_t;
47  
    using difference_type = std::ptrdiff_t;
48  
    using iterator_category =
48  
    using iterator_category =
49  
        std::bidirectional_iterator_tag;
49  
        std::bidirectional_iterator_tag;
50  

50  

51  
    iterator() = default;
51  
    iterator() = default;
52  
    iterator(iterator const&) = default;
52  
    iterator(iterator const&) = default;
53  
    iterator& operator=(
53  
    iterator& operator=(
54  
        iterator const&) = default;
54  
        iterator const&) = default;
55  

55  

56  
    reference
56  
    reference
57  
    operator*() const noexcept
57  
    operator*() const noexcept
58  
    {
58  
    {
59  
        return it_.dereference();
59  
        return it_.dereference();
60  
    }
60  
    }
61  

61  

62  
    pointer
62  
    pointer
63  
    operator->() const noexcept
63  
    operator->() const noexcept
64  
    {
64  
    {
65  
        return it_.dereference();
65  
        return it_.dereference();
66  
    }
66  
    }
67  

67  

68  
    iterator&
68  
    iterator&
69  
    operator++() noexcept
69  
    operator++() noexcept
70  
    {
70  
    {
71  
        it_.increment();
71  
        it_.increment();
72  
        return *this;
72  
        return *this;
73  
    }
73  
    }
74  

74  

75  
    iterator&
75  
    iterator&
76  
    operator--() noexcept
76  
    operator--() noexcept
77  
    {
77  
    {
78  
        it_.decrement();
78  
        it_.decrement();
79  
        return *this;
79  
        return *this;
80  
    }
80  
    }
81  

81  

82  
    iterator
82  
    iterator
83  
    operator++(int) noexcept
83  
    operator++(int) noexcept
84  
    {
84  
    {
85  
        auto tmp = *this;
85  
        auto tmp = *this;
86  
        ++*this;
86  
        ++*this;
87  
        return tmp;
87  
        return tmp;
88  
    }
88  
    }
89  

89  

90  
    iterator
90  
    iterator
91  
    operator--(int) noexcept
91  
    operator--(int) noexcept
92  
    {
92  
    {
93  
        auto tmp = *this;
93  
        auto tmp = *this;
94  
        --*this;
94  
        --*this;
95  
        return tmp;
95  
        return tmp;
96  
    }
96  
    }
97  

97  

98  
    bool
98  
    bool
99  
    operator==(
99  
    operator==(
100  
        iterator const& other) const noexcept
100  
        iterator const& other) const noexcept
101  
    {
101  
    {
102  
        return it_.equal(other.it_);
102  
        return it_.equal(other.it_);
103  
    }
103  
    }
104  

104  

105  
    bool
105  
    bool
106  
    operator!=(
106  
    operator!=(
107  
        iterator const& other) const noexcept
107  
        iterator const& other) const noexcept
108  
    {
108  
    {
109  
        return ! it_.equal(other.it_);
109  
        return ! it_.equal(other.it_);
110  
    }
110  
    }
111  
};
111  
};
112  

112  

113  
//------------------------------------------------
113  
//------------------------------------------------
114  

114  

115  
inline
115  
inline
116  
pct_string_view
116  
pct_string_view
117  
segments_encoded_base::
117  
segments_encoded_base::
118  
front() const noexcept
118  
front() const noexcept
119  
{
119  
{
120  
    BOOST_ASSERT(! empty());
120  
    BOOST_ASSERT(! empty());
121  
    return *begin();
121  
    return *begin();
122  
}
122  
}
123  

123  

124  
inline
124  
inline
125  
pct_string_view
125  
pct_string_view
126  
segments_encoded_base::
126  
segments_encoded_base::
127  
back() const noexcept
127  
back() const noexcept
128  
{
128  
{
129  
    BOOST_ASSERT(! empty());
129  
    BOOST_ASSERT(! empty());
130  
    return *--end();
130  
    return *--end();
131  
}
131  
}
132  

132  

133  
} // urls
133  
} // urls
134  
} // boost
134  
} // boost
135  

135  

136  
#endif
136  
#endif