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