1 #ifndef BOOST_NETWORK_MESSAGE_MODIFIER_CLEAR_HEADERS_HPP_20100824
2 #define BOOST_NETWORK_MESSAGE_MODIFIER_CLEAR_HEADERS_HPP_20100824
3
4 // Copyright 2010 (c) Dean Michael Berris
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 #include <boost/mpl/and.hpp>
10 #include <boost/mpl/not.hpp>
11 #include <boost/network/support/is_async.hpp>
12 #include <boost/network/support/is_pod.hpp>
13 #include <boost/thread/future.hpp>
14 #include <boost/utility/enable_if.hpp>
15
16 namespace boost {
17 namespace network {
18
19 namespace impl {
20 template <class Message, class Tag>
21 inline typename enable_if<
22 mpl::and_<mpl::not_<is_pod<Tag> >, mpl::not_<is_async<Tag> > >, void>::type
clear_headers(Message const & message,Tag const &)23 clear_headers(Message const &message, Tag const &) {
24 (typename Message::headers_container_type()).swap(message.headers());
25 }
26
27 template <class Message, class Tag>
clear_headers(Message const & message,Tag const &)28 inline typename enable_if<is_pod<Tag>, void>::type clear_headers(
29 Message const &message, Tag const &) {
30 (typename Message::headers_container_type()).swap(message.headers);
31 }
32
33 template <class Message, class Tag>
34 inline typename enable_if<mpl::and_<mpl::not_<is_pod<Tag> >, is_async<Tag> >,
35 void>::type
clear_headers(Message const & message,Tag const &)36 clear_headers(Message const &message, Tag const &) {
37 boost::promise<typename Message::headers_container_type> header_promise;
38 boost::shared_future<typename Message::headers_container_type> headers_future(
39 header_promise.get_future());
40 message.headers(headers_future);
41 header_promise.set_value(typename Message::headers_container_type());
42 }
43
44 } // namespace impl
45
46 template <class Tag, template <class> class Message>
clear_headers(Message<Tag> const & message)47 inline void clear_headers(Message<Tag> const &message) {
48 impl::clear_headers(message, Tag());
49 }
50
51 } // namespace network
52
53 } // namespace boost
54
55 #endif // BOOST_NETWORK_MESSAGE_MODIFIER_CLEAR_HEADERS_HPP_20100824
56