|
1 | 1 |
|
2 | | -// Copyright Dean Michael Berris 2007. |
| 2 | +// Copyright Dean Michael Berris 2007-2010. |
3 | 3 | // Distributed under the Boost Software License, Version 1.0. |
4 | 4 | // (See accompanying file LICENSE_1_0.txt or copy at |
5 | 5 | // http://www.boost.org/LICENSE_1_0.txt) |
|
18 | 18 | #include<boost/variant/static_visitor.hpp> |
19 | 19 |
|
20 | 20 | namespaceboost {namespacenetwork { |
| 21 | + |
| 22 | +namespaceimpl { |
21 | 23 |
|
22 | | -namespaceimpl { |
| 24 | +template<classKeyType,classValueType> |
| 25 | +structheader_directive { |
23 | 26 |
|
24 | | -template<classKeyType,classValueType> |
25 | | -structheader_directive { |
| 27 | +explicitheader_directive(KeyTypeconst & header_name, |
| 28 | + ValueTypeconst & header_value) : |
| 29 | + _header_name(header_name), |
| 30 | + _header_value(header_value) |
| 31 | + { }; |
26 | 32 |
|
27 | | -explicitheader_directive(KeyTypeconst & header_name, |
28 | | - ValueTypeconst & header_value) : |
29 | | - _header_name(header_name), |
30 | | - _header_value(header_value) |
31 | | - { }; |
| 33 | +template<classMessage> |
| 34 | +structpod_directive { |
| 35 | +template<classT1,classT2> |
| 36 | +staticvoideval(Messageconst & message, T1const & key, T2const & value) { |
| 37 | +typedeftypename Message::headers_container_type::value_type value_type; |
| 38 | + value_type value_ = { key, value }; |
| 39 | + message.headers.insert(message.headers.end(), value_); |
| 40 | + } |
| 41 | + }; |
32 | 42 |
|
33 | | -template<classMessage> |
34 | | -voidoperator() (Messageconst & msg)const { |
35 | | -typedeftypename Message::headers_container_type::value_type value_type; |
36 | | - msg.add_header(value_type(_header_name, _header_value)); |
37 | | - } |
| 43 | +template<classMessage> |
| 44 | +structnormal_directive { |
| 45 | +template<classT1,classT2> |
| 46 | +staticvoideval(Messageconst & message, T1const & key, T2const & value) { |
| 47 | +typedeftypename Message::headers_container_type::value_type value_type; |
| 48 | + message.add_header(value_type(key, value)); |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | +template<classMessage> |
| 53 | +structdirective_impl : |
| 54 | + mpl::if_< |
| 55 | + is_base_of< |
| 56 | + tags::pod, |
| 57 | +typename Message::tag |
| 58 | + >, |
| 59 | + pod_directive<Message>, |
| 60 | + normal_directive<Message> |
| 61 | + >::type |
| 62 | + {}; |
| 63 | + |
| 64 | +template<classMessage> |
| 65 | +voidoperator() (Messageconst & msg)const { |
| 66 | +typedeftypename Message::headers_container_type::value_type value_type; |
| 67 | + directive_impl<Message>::eval(msg, _header_name, _header_value); |
| 68 | + } |
38 | 69 |
|
39 | | -private: |
| 70 | +private: |
40 | 71 |
|
41 | | - KeyTypeconst & _header_name; |
42 | | - ValueTypeconst & _header_value; |
43 | | -}; |
44 | | -}// namespace impl |
| 72 | + KeyTypeconst & _header_name; |
| 73 | + ValueTypeconst & _header_value; |
| 74 | + }; |
45 | 75 |
|
46 | | -template<classT1,classT2> |
47 | | -inline impl::header_directive<T1, T2> |
48 | | -header(T1const & header_name, |
49 | | - T2const & header_value) { |
50 | | -return impl::header_directive<T1, T2>(header_name, |
51 | | - header_value); |
52 | | -} |
| 76 | + }// namespace impl |
| 77 | + |
| 78 | +template<classT1,classT2> |
| 79 | +inline impl::header_directive<T1, T2> |
| 80 | +header(T1const &header_name, T2const & header_value) { |
| 81 | +return impl::header_directive<T1, T2>(header_name, header_value); |
| 82 | +} |
53 | 83 | }// namespace network |
54 | 84 | }// namespace boost |
55 | 85 |
|
|