Skip to content

Commit 21015f7

Browse files
committed
Updated the builder directives & tests; added a very short example.
1 parent a1242bf commit 21015f7

File tree

14 files changed

+189
-165
lines changed

14 files changed

+189
-165
lines changed

boost/network/uri/decode.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ template <
5959
class InputIterator,
6060
class OutputIterator
6161
>
62-
OutputIterator decode(const InputIterator &in_begin, const InputIterator &in_end, const OutputIterator &out_begin) {
62+
OutputIterator decode(const InputIterator &in_begin,
63+
const InputIterator &in_end,
64+
const OutputIterator &out_begin) {
6365
typedef typename boost::iterator_value<InputIterator>::type value_type;
6466

6567
InputIterator it = in_begin;
@@ -87,7 +89,8 @@ template <
8789
class OutputIterator
8890
>
8991
inline
90-
OutputIterator decode(const SinglePassRange &range, const OutputIterator &out) {
92+
OutputIterator decode(const SinglePassRange &range,
93+
const OutputIterator &out) {
9194
return decode(boost::begin(range), boost::end(range), out);
9295
}
9396
} // namespace uri

boost/network/uri/directives/authority.hpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_AUTHORITY_INC__
33

44

5-
# include <boost/network/support/is_pod.hpp>
6-
# include <boost/utility/enable_if.hpp>
7-
# include <boost/mpl/if.hpp>
8-
# include <boost/mpl/or.hpp>
5+
# include <boost/range/as_literal.hpp>
6+
97

108

119
namespace boost {
@@ -24,17 +22,7 @@ struct authority_directive {
2422
class Tag
2523
, template <class> class Uri
2624
>
27-
typename enable_if<is_pod<Tag>, void>::type
28-
operator () (Uri<Tag> &uri) const {
29-
uri.append(value);
30-
}
31-
32-
template <
33-
class Tag
34-
, template <class> class Uri
35-
>
36-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
37-
operator () (Uri<Tag> &uri) const {
25+
void operator () (Uri<Tag> &uri) const {
3826
uri.append(value);
3927
}
4028

boost/network/uri/directives/fragment.hpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_FRAGMENT_INC__
33

44

5-
# include <boost/network/support/is_pod.hpp>
6-
# include <boost/utility/enable_if.hpp>
7-
# include <boost/mpl/if.hpp>
8-
# include <boost/mpl/or.hpp>
5+
# include <boost/network/uri/encode.hpp>
6+
# include <boost/range/begin.hpp>
7+
# include <boost/range/end.hpp>
98

109

1110
namespace boost {
@@ -24,22 +23,12 @@ struct fragment_directive {
2423
class Tag
2524
, template <class> class Uri
2625
>
27-
typename enable_if<is_pod<Tag>, void>::type
28-
operator () (Uri<Tag> &uri) const {
26+
void operator () (Uri<Tag> &uri) const {
27+
typename string<Tag>::type encoded_value;
2928
static const char separator[] = {'#'};
3029
uri.append(boost::begin(separator), boost::end(separator));
31-
uri.append(value);
32-
}
33-
34-
template <
35-
class Tag
36-
, template <class> class Uri
37-
>
38-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
39-
operator () (Uri<Tag> &uri) const {
40-
static const char separator[] = {'#'};
41-
uri.append(boost::begin(separator), boost::end(separator));
42-
uri.append(value);
30+
encode(boost::as_literal(value), std::back_inserter(encoded_value));
31+
uri.append(encoded_value);
4332
}
4433

4534
const ValueType &value;

boost/network/uri/directives/host.hpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_HOST_INC__
33

44

5-
# include <boost/network/support/is_pod.hpp>
6-
# include <boost/utility/enable_if.hpp>
7-
# include <boost/mpl/if.hpp>
8-
# include <boost/mpl/or.hpp>
5+
# include <boost/range/begin.hpp>
6+
# include <boost/range/end.hpp>
97

108

119
namespace boost {
@@ -24,17 +22,7 @@ struct host_directive {
2422
class Tag
2523
, template <class> class Uri
2624
>
27-
typename enable_if<is_pod<Tag>, void>::type
28-
operator () (Uri<Tag> &uri) const {
29-
uri.append(value);
30-
}
31-
32-
template <
33-
class Tag
34-
, template <class> class Uri
35-
>
36-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
37-
operator () (Uri<Tag> &uri) const {
25+
void operator () (Uri<Tag> &uri) const {
3826
uri.append(value);
3927
}
4028

boost/network/uri/directives/path.hpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44

55
# include <boost/network/uri/encode.hpp>
6-
# include <boost/network/support/is_pod.hpp>
7-
# include <boost/utility/enable_if.hpp>
8-
# include <boost/mpl/if.hpp>
9-
# include <boost/mpl/or.hpp>
6+
# include <boost/range/as_literal.hpp>
107

118

129
namespace boost {
@@ -25,21 +22,39 @@ struct path_directive {
2522
class Tag
2623
, template <class> class Uri
2724
>
28-
typename enable_if<is_pod<Tag>, void>::type
29-
operator () (Uri<Tag> &uri) const {
30-
typename string<Tag>::type encoded_value;
31-
encode(boost::begin(value), boost::end(value), std::back_inserter(encoded_value));
32-
uri.append(encoded_value);
25+
void operator () (Uri<Tag> &uri) const {
26+
(*this)(boost::as_literal(value), uri);
27+
}
28+
29+
template <
30+
class Rng
31+
, class Tag
32+
, template <class> class Uri
33+
>
34+
void operator () (const Rng &rng, Uri<Tag> &uri) const {
35+
uri.append(boost::begin(rng), boost::end(rng));
3336
}
3437

38+
const ValueType &value;
39+
40+
};
41+
42+
template <
43+
class ValueType
44+
>
45+
struct encoded_path_directive {
46+
47+
explicit encoded_path_directive(const ValueType &value)
48+
: value(value)
49+
{}
50+
3551
template <
3652
class Tag
3753
, template <class> class Uri
3854
>
39-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
40-
operator () (Uri<Tag> &uri) const {
55+
void operator () (Uri<Tag> &uri) const {
4156
typename string<Tag>::type encoded_value;
42-
encode(boost::begin(value), boost::end(value), std::back_inserter(encoded_value));
57+
encode(boost::as_literal(value), std::back_inserter(encoded_value));
4358
uri.append(encoded_value);
4459
}
4560

@@ -54,6 +69,14 @@ inline
5469
path_directive<T> path(const T &value) {
5570
return path_directive<T>(value);
5671
}
72+
73+
template <
74+
class T
75+
>
76+
inline
77+
encoded_path_directive<T> encoded_path(const T &value) {
78+
return encoded_path_directive<T>(value);
79+
}
5780
} // namespace uri
5881
} // namespace network
5982
} // namespace boost

boost/network/uri/directives/port.hpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_PORT_INC__
33

44

5-
# include <boost/network/support/is_pod.hpp>
65
# include <boost/utility/enable_if.hpp>
7-
# include <boost/mpl/if.hpp>
8-
# include <boost/mpl/or.hpp>
96
# include <boost/type_traits/is_integral.hpp>
107
# include <boost/cstdint.hpp>
8+
# include <boost/range/begin.hpp>
9+
# include <boost/range/end.hpp>
1110

1211

1312
namespace boost {
@@ -26,19 +25,7 @@ struct port_directive {
2625
class Tag
2726
, template <class> class Uri
2827
>
29-
typename enable_if<is_pod<Tag>, void>::type
30-
operator () (Uri<Tag> &uri) const {
31-
static const char separator[] = {':'};
32-
uri.append(boost::begin(separator), boost::end(separator));
33-
uri.append(value);
34-
}
35-
36-
template <
37-
class Tag
38-
, template <class> class Uri
39-
>
40-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
41-
operator () (Uri<Tag> &uri) const {
28+
void operator () (Uri<Tag> &uri) const {
4229
static const char separator[] = {':'};
4330
uri.append(boost::begin(separator), boost::end(separator));
4431
uri.append(value);

boost/network/uri/directives/query.hpp

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_QUERY_INC__
33

44

5-
# include <boost/network/support/is_pod.hpp>
6-
# include <boost/utility/enable_if.hpp>
7-
# include <boost/mpl/if.hpp>
8-
# include <boost/mpl/or.hpp>
5+
# include <boost/network/uri/encode.hpp>
6+
# include <boost/range/begin.hpp>
7+
# include <boost/range/end.hpp>
98

109

1110
namespace boost {
@@ -24,19 +23,8 @@ struct query_directive {
2423
class Tag
2524
, template <class> class Uri
2625
>
27-
typename enable_if<is_pod<Tag>, void>::type
28-
operator () (Uri<Tag> &uri) const {
29-
static const char separator[] = {'?'};
30-
uri.append(boost::begin(separator), boost::end(separator));
31-
uri.append(value);
32-
}
33-
34-
template <
35-
class Tag
36-
, template <class> class Uri
37-
>
38-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
39-
operator () (Uri<Tag> &uri) const {
26+
void operator () (Uri<Tag> &uri) const {
27+
typename string<Tag>::type encoded_value;
4028
static const char separator[] = {'?'};
4129
uri.append(boost::begin(separator), boost::end(separator));
4230
uri.append(value);
@@ -68,48 +56,26 @@ struct query_key_value_directive {
6856
class Tag
6957
, template <class> class Uri
7058
>
71-
typename enable_if<is_pod<Tag>, void>::type
72-
operator () (Uri<Tag> &uri) const {
73-
static const char separator_1[] = {'?'};
74-
static const char separator_2[] = {'='};
75-
static const char separator_3[] = {';'};
59+
void operator () (Uri<Tag> &uri) const {
60+
typename string<Tag>::type encoded_key, encoded_value;
61+
static const char qmark[] = {'?'};
62+
static const char equal[] = {'='};
63+
static const char scolon[] = {';'};
7664
if (!uri.query_range())
7765
{
78-
uri.append(boost::begin(separator_1), boost::end(separator_1));
66+
uri.append(boost::begin(qmark), boost::end(qmark));
7967
}
8068
else
8169
{
82-
uri.append(boost::begin(separator_3), boost::end(separator_3));
70+
uri.append(boost::begin(scolon), boost::end(scolon));
8371
}
84-
uri.append(key);
85-
uri.append(boost::begin(separator_2), boost::end(separator_2));
86-
typename string<Tag>::type encoded_value;
87-
encode(boost::begin(value), boost::end(value), std::back_inserter(encoded_value));
72+
encode(boost::as_literal(key), std::back_inserter(encoded_key));
73+
uri.append(encoded_key);
74+
uri.append(boost::begin(equal), boost::end(equal));
75+
encode(boost::as_literal(value), std::back_inserter(encoded_value));
8876
uri.append(encoded_value);
8977
}
9078

91-
template <
92-
class Tag
93-
, template <class> class Uri
94-
>
95-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
96-
operator () (Uri<Tag> &uri) const {
97-
static const char separator_1[] = {'?'};
98-
static const char separator_2[] = {'='};
99-
static const char separator_3[] = {';'};
100-
if (!uri.query_range())
101-
{
102-
uri.append(boost::begin(separator_1), boost::end(separator_1));
103-
}
104-
else
105-
{
106-
uri.append(boost::begin(separator_3), boost::end(separator_3));
107-
}
108-
uri.append(key);
109-
uri.append(boost::begin(separator_2), boost::end(separator_2));
110-
uri.append(value);
111-
}
112-
11379
const KeyType &key;
11480
const ValueType &value;
11581

0 commit comments

Comments
 (0)