|
8 | 8 | // http://www.boost.org/LICENSE_1_0.txt)
|
9 | 9 |
|
10 | 10 | #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> |
11 | 16 |
|
12 | 17 | namespace boost { namespace network {
|
13 | 18 |
|
14 | 19 | namespace impl {
|
15 | 20 |
|
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) { |
18 | 30 | message.headers().erase(key);
|
19 | 31 | }
|
20 | 32 |
|
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); |
24 | 43 | }
|
25 | 44 |
|
| 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 | + |
26 | 56 | 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 | + ); |
29 | 70 | }
|
30 | 71 |
|
31 | 72 |
|
32 | 73 | } // namespace impl
|
33 | 74 |
|
34 | 75 | 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()); |
37 | 78 | }
|
38 | 79 |
|
39 | 80 | } // namespace network
|
40 | 81 |
|
41 | 82 | } // namespace boost
|
42 | 83 |
|
43 | 84 | #endif // BOOST_NETWORK_MESSAGE_MODIFIER_REMOVE_HEADER_HPP_20100824
|
| 85 | + |
0 commit comments