Menu

[r211]: / trunk / boost / network / message / wrappers / headers.hpp  Maximize  Restore  History

Download this file

89 lines (70 with data), 3.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright Dean Michael Berris 2007.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
#define __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
#include <boost/network/traits/string.hpp>
#include <boost/network/traits/headers_container.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/functions.hpp>
namespace boost { namespace network {
/// Template metaprogram to get the range type for a message
template <class Message>
struct headers_range {
typedef typename headers_container<typename Message::tag>::type headers_container_type;
typedef typename
boost::iterator_range<typename headers_container_type::const_iterator>
type;
};
/** headers wrapper for messages.
*
* This exposes an interface similar to a map, indexable
* using operator[] taking a string as the index and returns
* a range of iterators (std::pair<iterator, iterator>)
* whose keys are all equal to the index string.
*
* This type is also convertible to a
* headers_range<basic_message<tag> >::type
* Which allows for full range support.
*
*/
namespace impl {
template <class Tag>
struct headers_wrapper : public detail::wrapper_base<Tag> {
typedef Tag tag;
typedef basic_message<Tag> message_type;
typedef typename string<Tag>::type string_type;
typedef typename headers_range<message_type>::type range_type;
typedef typename headers_container<Tag>::type headers_container_type;
typedef typename headers_container_type::const_iterator const_iterator;
typedef typename headers_container_type::iterator iterator;
explicit headers_wrapper(basic_message<tag> & message_)
: detail::wrapper_base<tag>(message_)
{ };
range_type operator[] (string_type const & key) const {
return headers_wrapper<Tag>::_message.headers().equal_range(key);
};
typename message_type::headers_container_type::size_type count(string_type const & key) const {
return headers_wrapper<Tag>::_message.headers().count(key);
};
const_iterator begin() const {
return headers_wrapper<Tag>::_message.headers().begin();
};
const_iterator end() const {
return headers_wrapper<Tag>::_message.headers().end();
};
operator range_type () {
return make_iterator_range(headers_wrapper<Tag>::_message.headers().begin(), headers_wrapper<Tag>::_message.headers().end());
};
};
} // namespace impl
/// Factory method to create the right wrapper object
template <class Tag, template <class> class Message>
inline impl::headers_wrapper<Tag>
headers(Message<Tag> & message_) {
return impl::headers_wrapper<Tag>(message_);
}
} // namespace network
} // namespace boost
#endif // __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__