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_REF_HPP
11  
#ifndef BOOST_URL_IMPL_PARAMS_REF_HPP
12  
#define BOOST_URL_IMPL_PARAMS_REF_HPP
12  
#define BOOST_URL_IMPL_PARAMS_REF_HPP
13  

13  

14  
#include <boost/url/params_view.hpp>
14  
#include <boost/url/params_view.hpp>
15  
#include <boost/url/detail/any_params_iter.hpp>
15  
#include <boost/url/detail/any_params_iter.hpp>
16  
#include <boost/url/detail/except.hpp>
16  
#include <boost/url/detail/except.hpp>
17  
#include <boost/url/grammar/recycled.hpp>
17  
#include <boost/url/grammar/recycled.hpp>
18  
#include <boost/assert.hpp>
18  
#include <boost/assert.hpp>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace urls {
21  
namespace urls {
22  

22  

23  
inline
23  
inline
24  
params_ref::
24  
params_ref::
25  
params_ref(
25  
params_ref(
26  
    url_base& u,
26  
    url_base& u,
27  
    encoding_opts opt) noexcept
27  
    encoding_opts opt) noexcept
28  
    : params_base(u.impl_, opt)
28  
    : params_base(u.impl_, opt)
29  
    , u_(&u)
29  
    , u_(&u)
30  
{
30  
{
31  
}
31  
}
32  

32  

33  
//------------------------------------------------
33  
//------------------------------------------------
34  
//
34  
//
35  
// Special Members
35  
// Special Members
36  
//
36  
//
37  
//------------------------------------------------
37  
//------------------------------------------------
38  

38  

39  
inline
39  
inline
40  
params_ref::
40  
params_ref::
41  
params_ref(
41  
params_ref(
42  
    params_ref const& other,
42  
    params_ref const& other,
43  
    encoding_opts opt) noexcept
43  
    encoding_opts opt) noexcept
44  
    : params_ref(*other.u_, opt)
44  
    : params_ref(*other.u_, opt)
45  
{
45  
{
46  
}
46  
}
47  

47  

48  
inline
48  
inline
49  
auto
49  
auto
50  
params_ref::
50  
params_ref::
51  
operator=(std::initializer_list<
51  
operator=(std::initializer_list<
52  
    param_view> init) ->
52  
    param_view> init) ->
53  
        params_ref&
53  
        params_ref&
54  
{
54  
{
55  
    assign(init);
55  
    assign(init);
56  
    return *this;
56  
    return *this;
57  
}
57  
}
58  

58  

59  
//------------------------------------------------
59  
//------------------------------------------------
60  
//
60  
//
61  
// Modifiers
61  
// Modifiers
62  
//
62  
//
63  
//------------------------------------------------
63  
//------------------------------------------------
64  

64  

65  
inline
65  
inline
66  
void
66  
void
67  
params_ref::
67  
params_ref::
68  
clear() noexcept
68  
clear() noexcept
69  
{
69  
{
70  
    u_->remove_query();
70  
    u_->remove_query();
71  
}
71  
}
72  

72  

73  
//------------------------------------------------
73  
//------------------------------------------------
74  

74  

75  
template<class FwdIt>
75  
template<class FwdIt>
76  
void
76  
void
77  
params_ref::
77  
params_ref::
78  
assign(FwdIt first, FwdIt last)
78  
assign(FwdIt first, FwdIt last)
79  
{
79  
{
80  
/*  If you get a compile error here, it
80  
/*  If you get a compile error here, it
81  
    means that the iterators you passed
81  
    means that the iterators you passed
82  
    do not meet the requirements stated
82  
    do not meet the requirements stated
83  
    in the documentation.
83  
    in the documentation.
84  
*/
84  
*/
85  
    static_assert(
85  
    static_assert(
86  
        std::is_convertible<
86  
        std::is_convertible<
87  
            typename std::iterator_traits<
87  
            typename std::iterator_traits<
88  
                FwdIt>::reference,
88  
                FwdIt>::reference,
89  
            param_view>::value,
89  
            param_view>::value,
90  
        "Type requirements not met");
90  
        "Type requirements not met");
91  

91  

92  
    assign(first, last,
92  
    assign(first, last,
93  
        typename std::iterator_traits<
93  
        typename std::iterator_traits<
94  
            FwdIt>::iterator_category{});
94  
            FwdIt>::iterator_category{});
95  
}
95  
}
96  

96  

97  
inline
97  
inline
98  
auto
98  
auto
99  
params_ref::
99  
params_ref::
100  
append(
100  
append(
101  
    param_view const& p) ->
101  
    param_view const& p) ->
102  
        iterator
102  
        iterator
103  
{
103  
{
104  
    return insert(end(), p);
104  
    return insert(end(), p);
105  
}
105  
}
106  

106  

107  
inline
107  
inline
108  
auto
108  
auto
109  
params_ref::
109  
params_ref::
110  
append(
110  
append(
111  
    std::initializer_list<
111  
    std::initializer_list<
112  
        param_view> init) ->
112  
        param_view> init) ->
113  
    iterator
113  
    iterator
114  
{
114  
{
115  
    return insert(end(), init);
115  
    return insert(end(), init);
116  
}
116  
}
117  

117  

118  
template<class FwdIt>
118  
template<class FwdIt>
119  
auto
119  
auto
120  
params_ref::
120  
params_ref::
121  
append(FwdIt first, FwdIt last) ->
121  
append(FwdIt first, FwdIt last) ->
122  
    iterator
122  
    iterator
123  
{
123  
{
124  
/*  If you get a compile error here, it
124  
/*  If you get a compile error here, it
125  
    means that the iterators you passed
125  
    means that the iterators you passed
126  
    do not meet the requirements stated
126  
    do not meet the requirements stated
127  
    in the documentation.
127  
    in the documentation.
128  
*/
128  
*/
129  
    static_assert(
129  
    static_assert(
130  
        std::is_convertible<
130  
        std::is_convertible<
131  
            typename std::iterator_traits<
131  
            typename std::iterator_traits<
132  
                FwdIt>::reference,
132  
                FwdIt>::reference,
133  
            param_view>::value,
133  
            param_view>::value,
134  
        "Type requirements not met");
134  
        "Type requirements not met");
135  

135  

136  
    return insert(
136  
    return insert(
137  
        end(), first, last);
137  
        end(), first, last);
138  
}
138  
}
139  

139  

140  
template<class FwdIt>
140  
template<class FwdIt>
141  
auto
141  
auto
142  
params_ref::
142  
params_ref::
143  
insert(
143  
insert(
144  
    iterator before,
144  
    iterator before,
145  
    FwdIt first,
145  
    FwdIt first,
146  
    FwdIt last) ->
146  
    FwdIt last) ->
147  
        iterator
147  
        iterator
148  
{
148  
{
149  
/*  If you get a compile error here, it
149  
/*  If you get a compile error here, it
150  
    means that the iterators you passed
150  
    means that the iterators you passed
151  
    do not meet the requirements stated
151  
    do not meet the requirements stated
152  
    in the documentation.
152  
    in the documentation.
153  
*/
153  
*/
154  
    static_assert(
154  
    static_assert(
155  
        std::is_convertible<
155  
        std::is_convertible<
156  
            typename std::iterator_traits<
156  
            typename std::iterator_traits<
157  
                FwdIt>::reference,
157  
                FwdIt>::reference,
158  
            param_view>::value,
158  
            param_view>::value,
159  
        "Type requirements not met");
159  
        "Type requirements not met");
160  

160  

161  
    return insert(
161  
    return insert(
162  
        before,
162  
        before,
163  
        first,
163  
        first,
164  
        last,
164  
        last,
165  
        typename std::iterator_traits<
165  
        typename std::iterator_traits<
166  
            FwdIt>::iterator_category{});
166  
            FwdIt>::iterator_category{});
167  
}
167  
}
168  

168  

169  
template<class FwdIt>
169  
template<class FwdIt>
170  
auto
170  
auto
171  
params_ref::
171  
params_ref::
172  
replace(
172  
replace(
173  
    iterator from,
173  
    iterator from,
174  
    iterator to,
174  
    iterator to,
175  
    FwdIt first,
175  
    FwdIt first,
176  
    FwdIt last) ->
176  
    FwdIt last) ->
177  
        iterator
177  
        iterator
178  
{
178  
{
179  
/*  If you get a compile error here, it
179  
/*  If you get a compile error here, it
180  
    means that the iterators you passed
180  
    means that the iterators you passed
181  
    do not meet the requirements stated
181  
    do not meet the requirements stated
182  
    in the documentation.
182  
    in the documentation.
183  
*/
183  
*/
184  
    static_assert(
184  
    static_assert(
185  
        std::is_convertible<
185  
        std::is_convertible<
186  
            typename std::iterator_traits<
186  
            typename std::iterator_traits<
187  
                FwdIt>::reference,
187  
                FwdIt>::reference,
188  
            param_view>::value,
188  
            param_view>::value,
189  
        "Type requirements not met");
189  
        "Type requirements not met");
190  

190  

191  
    return iterator(
191  
    return iterator(
192  
        u_->edit_params(
192  
        u_->edit_params(
193  
            from.it_, to.it_,
193  
            from.it_, to.it_,
194  
            detail::make_params_iter(
194  
            detail::make_params_iter(
195  
                first, last, opt_.space_as_plus)),
195  
                first, last, opt_.space_as_plus)),
196  
        opt_);
196  
        opt_);
197  
}
197  
}
198  

198  

199  
//------------------------------------------------
199  
//------------------------------------------------
200  
//
200  
//
201  
// implementation
201  
// implementation
202  
//
202  
//
203  
//------------------------------------------------
203  
//------------------------------------------------
204  

204  

205  
template<class FwdIt>
205  
template<class FwdIt>
206  
void
206  
void
207  
params_ref::
207  
params_ref::
208  
assign(FwdIt first, FwdIt last,
208  
assign(FwdIt first, FwdIt last,
209  
    std::forward_iterator_tag)
209  
    std::forward_iterator_tag)
210  
{
210  
{
211  
    u_->edit_params(
211  
    u_->edit_params(
212  
        begin().it_,
212  
        begin().it_,
213  
        end().it_,
213  
        end().it_,
214  
        detail::make_params_iter(
214  
        detail::make_params_iter(
215  
            first, last, opt_.space_as_plus));
215  
            first, last, opt_.space_as_plus));
216  
}
216  
}
217  

217  

218  
template<class FwdIt>
218  
template<class FwdIt>
219  
auto
219  
auto
220  
params_ref::
220  
params_ref::
221  
insert(
221  
insert(
222  
    iterator before,
222  
    iterator before,
223  
    FwdIt first,
223  
    FwdIt first,
224  
    FwdIt last,
224  
    FwdIt last,
225  
    std::forward_iterator_tag) ->
225  
    std::forward_iterator_tag) ->
226  
        iterator
226  
        iterator
227  
{
227  
{
228  
    return iterator(
228  
    return iterator(
229  
        u_->edit_params(
229  
        u_->edit_params(
230  
            before.it_,
230  
            before.it_,
231  
            before.it_,
231  
            before.it_,
232  
            detail::make_params_iter(
232  
            detail::make_params_iter(
233  
                first, last, opt_.space_as_plus)),
233  
                first, last, opt_.space_as_plus)),
234  
        opt_);
234  
        opt_);
235  
}
235  
}
236  

236  

237  
} // urls
237  
} // urls
238  
} // boost
238  
} // boost
239  

239  

240  
#endif
240  
#endif