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 -
inline
 
23 -
params_ref::
 
24 -
params_ref(
 
25 -
    url_base& u,
 
26 -
    encoding_opts opt) noexcept
 
27 -
    : params_base(u.impl_, opt)
 
28 -
    , u_(&u)
 
29 -
{
 
30 -
}
 
31 -

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

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

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

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

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

 
72 -
//------------------------------------------------
 
73 -

 
74  

22  

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

39  

92  
    assign(first, last,
40  
    assign(first, last,
93  
        typename std::iterator_traits<
41  
        typename std::iterator_traits<
94 -
}
 
95 -

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

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

44  

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

62  

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

66  

140  
template<class FwdIt>
67  
template<class FwdIt>
141  
auto
68  
auto
142  
params_ref::
69  
params_ref::
143  
insert(
70  
insert(
144  
    iterator before,
71  
    iterator before,
145  
    FwdIt first,
72  
    FwdIt first,
146  
    FwdIt last) ->
73  
    FwdIt last) ->
147  
        iterator
74  
        iterator
148  
{
75  
{
149  
/*  If you get a compile error here, it
76  
/*  If you get a compile error here, it
150  
    means that the iterators you passed
77  
    means that the iterators you passed
151  
    do not meet the requirements stated
78  
    do not meet the requirements stated
152  
    in the documentation.
79  
    in the documentation.
153  
*/
80  
*/
154  
    static_assert(
81  
    static_assert(
155  
        std::is_convertible<
82  
        std::is_convertible<
156  
            typename std::iterator_traits<
83  
            typename std::iterator_traits<
157  
                FwdIt>::reference,
84  
                FwdIt>::reference,
158  
            param_view>::value,
85  
            param_view>::value,
159  
        "Type requirements not met");
86  
        "Type requirements not met");
160  

87  

161  
    return insert(
88  
    return insert(
162  
        before,
89  
        before,
163  
        first,
90  
        first,
164  
        last,
91  
        last,
165  
        typename std::iterator_traits<
92  
        typename std::iterator_traits<
166  
            FwdIt>::iterator_category{});
93  
            FwdIt>::iterator_category{});
167  
}
94  
}
168  

95  

169  
template<class FwdIt>
96  
template<class FwdIt>
170  
auto
97  
auto
171  
params_ref::
98  
params_ref::
172  
replace(
99  
replace(
173  
    iterator from,
100  
    iterator from,
174  
    iterator to,
101  
    iterator to,
175  
    FwdIt first,
102  
    FwdIt first,
176  
    FwdIt last) ->
103  
    FwdIt last) ->
177  
        iterator
104  
        iterator
178  
{
105  
{
179  
/*  If you get a compile error here, it
106  
/*  If you get a compile error here, it
180  
    means that the iterators you passed
107  
    means that the iterators you passed
181  
    do not meet the requirements stated
108  
    do not meet the requirements stated
182  
    in the documentation.
109  
    in the documentation.
183  
*/
110  
*/
184  
    static_assert(
111  
    static_assert(
185  
        std::is_convertible<
112  
        std::is_convertible<
186  
            typename std::iterator_traits<
113  
            typename std::iterator_traits<
187  
                FwdIt>::reference,
114  
                FwdIt>::reference,
188  
            param_view>::value,
115  
            param_view>::value,
189  
        "Type requirements not met");
116  
        "Type requirements not met");
190  

117  

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

125  

199  
//------------------------------------------------
126  
//------------------------------------------------
200  
//
127  
//
201  
// implementation
128  
// implementation
202  
//
129  
//
203  
//------------------------------------------------
130  
//------------------------------------------------
204  

131  

205  
template<class FwdIt>
132  
template<class FwdIt>
206  
void
133  
void
207  
params_ref::
134  
params_ref::
208  
assign(FwdIt first, FwdIt last,
135  
assign(FwdIt first, FwdIt last,
209  
    std::forward_iterator_tag)
136  
    std::forward_iterator_tag)
210  
{
137  
{
211  
    u_->edit_params(
138  
    u_->edit_params(
212  
        begin().it_,
139  
        begin().it_,
213  
        end().it_,
140  
        end().it_,
214  
        detail::make_params_iter(
141  
        detail::make_params_iter(
215  
            first, last, opt_.space_as_plus));
142  
            first, last, opt_.space_as_plus));
216  
}
143  
}
217  

144  

218  
template<class FwdIt>
145  
template<class FwdIt>
219  
auto
146  
auto
220  
params_ref::
147  
params_ref::
221  
insert(
148  
insert(
222  
    iterator before,
149  
    iterator before,
223  
    FwdIt first,
150  
    FwdIt first,
224  
    FwdIt last,
151  
    FwdIt last,
225  
    std::forward_iterator_tag) ->
152  
    std::forward_iterator_tag) ->
226  
        iterator
153  
        iterator
227  
{
154  
{
228  
    return iterator(
155  
    return iterator(
229  
        u_->edit_params(
156  
        u_->edit_params(
230  
            before.it_,
157  
            before.it_,
231  
            before.it_,
158  
            before.it_,
232  
            detail::make_params_iter(
159  
            detail::make_params_iter(
233  
                first, last, opt_.space_as_plus)),
160  
                first, last, opt_.space_as_plus)),
234  
        opt_);
161  
        opt_);
235  
}
162  
}
236  

163  

237  
} // urls
164  
} // urls
238  
} // boost
165  
} // boost
239  

166  

240  
#endif
167  
#endif