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_PARAMS_BASE_HPP
11  
#ifndef BOOST_URL_IMPL_PARAMS_BASE_HPP
12  
#define BOOST_URL_IMPL_PARAMS_BASE_HPP
12  
#define BOOST_URL_IMPL_PARAMS_BASE_HPP
13  

13  

14  
#include <boost/url/detail/params_iter_impl.hpp>
14  
#include <boost/url/detail/params_iter_impl.hpp>
15  
#include <iterator>
15  
#include <iterator>
16  

16  

17  
namespace boost {
17  
namespace boost {
18  
namespace urls {
18  
namespace urls {
19  

19  

20  
//------------------------------------------------
20  
//------------------------------------------------
21  

21  

22  
class BOOST_URL_DECL params_base::iterator
22  
class BOOST_URL_DECL params_base::iterator
23  
{
23  
{
24  
    detail::params_iter_impl it_;
24  
    detail::params_iter_impl it_;
25  
    bool space_as_plus_ = true;
25  
    bool space_as_plus_ = true;
26  

26  

27  
    friend class params_base;
27  
    friend class params_base;
28  
    friend class params_ref;
28  
    friend class params_ref;
29  

29  

30  
    iterator(
30  
    iterator(
31  
        detail::query_ref const& ref,
31  
        detail::query_ref const& ref,
32  
        encoding_opts opt) noexcept;
32  
        encoding_opts opt) noexcept;
33  

33  

34  
    iterator(
34  
    iterator(
35  
        detail::query_ref const& impl,
35  
        detail::query_ref const& impl,
36  
        encoding_opts opt,
36  
        encoding_opts opt,
37  
        int) noexcept;
37  
        int) noexcept;
38  

38  

39  
    iterator(
39  
    iterator(
40  
        detail::params_iter_impl const& it,
40  
        detail::params_iter_impl const& it,
41  
        encoding_opts opt) noexcept
41  
        encoding_opts opt) noexcept
42  
        : it_(it)
42  
        : it_(it)
43  
        , space_as_plus_(opt.space_as_plus)
43  
        , space_as_plus_(opt.space_as_plus)
44  
    {
44  
    {
45  
    }
45  
    }
46  

46  

47  
public:
47  
public:
48  
    using value_type = params_base::value_type;
48  
    using value_type = params_base::value_type;
49  
    using reference = params_base::reference;
49  
    using reference = params_base::reference;
50  
    using pointer = reference;
50  
    using pointer = reference;
51  
    using difference_type =
51  
    using difference_type =
52  
        params_base::difference_type;
52  
        params_base::difference_type;
53  
    using iterator_category =
53  
    using iterator_category =
54  
        std::bidirectional_iterator_tag;
54  
        std::bidirectional_iterator_tag;
55  

55  

56  
    iterator() = default;
56  
    iterator() = default;
57  
    iterator(iterator const&) = default;
57  
    iterator(iterator const&) = default;
58  
    iterator& operator=(
58  
    iterator& operator=(
59  
        iterator const&) noexcept = default;
59  
        iterator const&) noexcept = default;
60  

60  

61  
    iterator&
61  
    iterator&
62  
    operator++() noexcept
62  
    operator++() noexcept
63  
    {
63  
    {
64  
        it_.increment();
64  
        it_.increment();
65  
        return *this;
65  
        return *this;
66  
    }
66  
    }
67  

67  

68  
    iterator
68  
    iterator
69  
    operator++(int) noexcept
69  
    operator++(int) noexcept
70  
    {
70  
    {
71  
        auto tmp = *this;
71  
        auto tmp = *this;
72  
        ++*this;
72  
        ++*this;
73  
        return tmp;
73  
        return tmp;
74  
    }
74  
    }
75  

75  

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

82  

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

90  

91  
    reference
91  
    reference
92  
    operator*() const;
92  
    operator*() const;
93  

93  

94  
    // the return value is too expensive
94  
    // the return value is too expensive
95  
    pointer operator->() const = delete;
95  
    pointer operator->() const = delete;
96  

96  

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

103  

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

111  

112  

112  

113  
} // urls
113  
} // urls
114  
} // boost
114  
} // boost
115  

115  

116  
#endif
116  
#endif