Skip to content

Commit 862b94a

Browse files
committed
WIP: organizing and fixing base modifiers, using SFINAE for proper overload selection.
1 parent 49ac5a3 commit 862b94a

File tree

16 files changed

+114
-80
lines changed

16 files changed

+114
-80
lines changed

boost/network/message/directives/detail/string_directive.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace boost { namespace network { namespace detail {
9393
typename boost::network::detail::string_value< \
9494
typename Message::tag \
9595
>::type const & value \
96-
) const { \
96+
) { \
9797
pod_body; \
9898
} \
9999
template <class T> void operator()(T const &) const { \

boost/network/message/modifiers/clear_headers.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,38 @@
1111
#include <boost/thread/future.hpp>
1212
#include <boost/utility/enable_if.hpp>
1313
#include <boost/mpl/not.hpp>
14+
#include <boost/mpl/and.hpp>
1415

1516
namespace boost { namespace network {
1617

1718
namespace impl {
1819
template <class Message, class Tag>
19-
inline typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
20-
clear_headers(Message const & message, Tag const &, mpl::false_ const &) {
20+
inline typename enable_if<
21+
mpl::and_<
22+
mpl::not_<is_pod<Tag> >
23+
, mpl::not_<is_async<Tag> >
24+
>
25+
, void
26+
>::type
27+
clear_headers(Message const & message, Tag const &) {
2128
(typename Message::headers_container_type()).swap(message.headers());
2229
}
2330

2431
template <class Message, class Tag>
2532
inline typename enable_if<is_pod<Tag>, void>::type
26-
clear_headers(Message const & message, Tag const &, mpl::false_ const &) {
33+
clear_headers(Message const & message, Tag const &) {
2734
(typename Message::headers_container_type()).swap(message.headers);
2835
}
2936

3037
template <class Message, class Tag>
31-
inline void clear_headers(Message const & message, Tag const &, mpl::true_ const &) {
38+
inline typename enable_if<
39+
mpl::and_<
40+
mpl::not_<is_pod<Tag> >
41+
, is_async<Tag>
42+
>
43+
, void
44+
>::type
45+
clear_headers(Message const & message, Tag const &) {
3246
boost::promise<typename Message::headers_container_type> header_promise;
3347
boost::shared_future<typename Message::headers_container_type> headers_future(header_promise.get_future());
3448
message.headers(headers_future);
@@ -39,7 +53,7 @@ namespace boost { namespace network {
3953

4054
template <class Tag, template <class> class Message>
4155
inline void clear_headers(Message<Tag> const & message) {
42-
impl::clear_headers(message, Tag(), is_async<Tag>());
56+
impl::clear_headers(message, Tag());
4357
}
4458

4559
} // namespace network

boost/network/message/modifiers/remove_header.hpp

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,78 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include <boost/network/support/is_async.hpp>
11+
#include <boost/network/support/is_pod.hpp>
12+
#include <boost/utility/enable_if.hpp>
13+
#include <boost/range/algorithm/remove_if.hpp>
14+
#include <boost/algorithm/string/predicate.hpp>
15+
#include <boost/mpl/not.hpp>
1116

1217
namespace boost { namespace network {
1318

1419
namespace impl {
1520

16-
template <class Message, class KeyType>
17-
inline void remove_header(Message const & message, KeyType const & key, tags::default_string const &, mpl::false_ const &) {
21+
template <class Message, class KeyType, class Tag>
22+
inline typename enable_if<
23+
mpl::and_<
24+
mpl::not_<is_pod<Tag> >
25+
, mpl::not_<is_async<Tag> >
26+
>
27+
, void
28+
>::type
29+
remove_header(Message & message, KeyType const & key, Tag) {
1830
message.headers().erase(key);
1931
}
2032

21-
template <class Message, class KeyType>
22-
inline void remove_header(Message const & message, KeyType const & key, tags::default_wstring const &, mpl::false_ const &) {
23-
message.headers().erase(key);
33+
template <class Message, class KeyType, class Tag>
34+
inline typename enable_if<
35+
mpl::and_<
36+
mpl::not_<is_pod<Tag> >
37+
, is_async<Tag>
38+
>
39+
, void
40+
>::type
41+
remove_header(Message & message, KeyType const & key, Tag) {
42+
message.remove_header(key);
2443
}
2544

45+
template <class KeyType>
46+
struct iequals_pred {
47+
KeyType const & key;
48+
iequals_pred(KeyType const & key)
49+
: key(key) {}
50+
template <class Header>
51+
bool operator()(Header & other) const {
52+
return boost::iequals(key, name(other));
53+
}
54+
};
55+
2656
template <class Message, class KeyType, class Tag>
27-
inline void remove_header(Message const & message, KeyType const & key, Tag const &, mpl::true_ const &) {
28-
message.remove_header(key);
57+
inline typename enable_if<
58+
is_pod<Tag>
59+
, void
60+
>::type
61+
remove_header(Message & message, KeyType const & key, Tag) {
62+
typedef typename Message::headers_container_type headers;
63+
message.headers.erase(
64+
boost::remove_if(
65+
message.headers,
66+
iequals_pred<KeyType>(key)
67+
)
68+
, message.headers.end()
69+
);
2970
}
3071

3172

3273
} // namespace impl
3374

3475
template <class Tag, template <class> class Message, class KeyType>
35-
inline void remove_header(Message<Tag> const & message, KeyType const & key) {
36-
impl::remove_header(message, key, Tag(), is_async<Tag>());
76+
inline void remove_header(Message<Tag> & message, KeyType const & key) {
77+
impl::remove_header(message, key, Tag());
3778
}
3879

3980
} // namespace network
4081

4182
} // namespace boost
4283

4384
#endif // BOOST_NETWORK_MESSAGE_MODIFIER_REMOVE_HEADER_HPP_20100824
85+

boost/network/protocol/http/algorithms/linearize.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <boost/network/protocol/http/server/header/name.hpp>
10-
#include <boost/network/protocol/http/server/header/value.hpp>
11-
#include <boost/network/protocol/http/server/header/concept.hpp>
9+
#include <boost/network/protocol/http/message/header/name.hpp>
10+
#include <boost/network/protocol/http/message/header/value.hpp>
11+
#include <boost/network/protocol/http/message/header_concept.hpp>
1212
#include <boost/network/constants.hpp>
1313
#include <boost/concept_check.hpp>
1414

boost/network/protocol/http/impl/request.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
1616

1717
#include <boost/network/uri.hpp>
18-
#include <boost/network/protocol/http/header.hpp>
1918
#include <boost/network/traits/vector.hpp>
2019

2120
#include <boost/network/protocol/http/message/async_message.hpp>

boost/network/protocol/http/impl/response.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <boost/network/protocol/http/tags.hpp>
2020
#include <boost/network/traits/string.hpp>
2121
#include <boost/network/protocol/http/traits/vector.hpp>
22-
#include <boost/network/protocol/http/header.hpp>
22+
#include <boost/network/protocol/http/message/header.hpp>
2323

2424
namespace boost { namespace network { namespace http {
2525

boost/network/protocol/http/message.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HPP
1414

1515
#include <boost/network/protocol/http/traits.hpp>
16+
#include <boost/network/protocol/http/message/header/name.hpp>
17+
#include <boost/network/protocol/http/message/header/value.hpp>
18+
#include <boost/network/protocol/http/message/header_concept.hpp>
1619
#include <boost/network/protocol/http/message/modifiers/add_header.hpp>
1720
#include <boost/network/protocol/http/message/modifiers/remove_header.hpp>
1821
#include <boost/network/message.hpp>

boost/network/protocol/http/header.hpp renamed to boost/network/protocol/http/message/header.hpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1111
//
1212

13-
#ifndef HTTP_SERVER3_HEADER_HPP
14-
#define HTTP_SERVER3_HEADER_HPP
13+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_HPP_20101122
14+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_HPP_20101122
1515

1616
#include <boost/network/traits/string.hpp>
1717
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
@@ -34,6 +34,19 @@ namespace boost { namespace network { namespace http {
3434
swap(l.value, r.value);
3535
}
3636

37+
template <class Tag>
38+
struct response_header {
39+
typedef Tag tag;
40+
typedef typename string<Tag>::type string_type;
41+
string_type name, value;
42+
};
43+
44+
template <class Tag>
45+
void swap(response_header<Tag> & l, response_header<Tag> & r) {
46+
std::swap(l.name, r.name);
47+
std::swap(l.value, r.value);
48+
}
49+
3750
} // namespace http
3851

3952
} // namespace network
@@ -47,4 +60,11 @@ BOOST_FUSION_ADAPT_TPL_STRUCT(
4760
(typename boost::network::string<Tag>::type, value)
4861
)
4962

50-
#endif // HTTP_SERVER3_HEADER_HPP
63+
BOOST_FUSION_ADAPT_TPL_STRUCT(
64+
(Tag),
65+
(boost::network::http::response_header) (Tag),
66+
(typename boost::network::string<Tag>::type, name)
67+
(typename boost::network::string<Tag>::type, value)
68+
)
69+
70+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_HPP_20101122

boost/network/protocol/http/server/header/name.hpp renamed to boost/network/protocol/http/message/header/name.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_NAME_HPP_20101028
2-
#define BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_NAME_HPP_20101028
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_NAME_HPP_20101028
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_NAME_HPP_20101028
33

44
// Copyright 2010 Dean Michael Berris.
55
// Distributed under the Boost Software License, Version 1.0.
@@ -40,4 +40,4 @@ namespace boost { namespace network { namespace http {
4040

4141
} /* boost */
4242

43-
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_NAME_HPP_20101028 */
43+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_NAME_HPP_20101028 */

boost/network/protocol/http/server/header/value.hpp renamed to boost/network/protocol/http/message/header/value.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_VALUE_HPP_20101028
2-
#define BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_VALUE_HPP_20101028
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_VALUE_HPP_20101028
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_VALUE_HPP_20101028
33

44
// Copyright 2010 Dean Michael Berris.
55
// Distributed under the Boost Software License, Version 1.0.
@@ -39,5 +39,5 @@ namespace boost { namespace network { namespace http {
3939

4040
} /* boost */
4141

42-
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_VALUE_HPP_20101028 */
42+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_VALUE_HPP_20101028 */
4343

0 commit comments

Comments
 (0)