Skip to content

Commit 7a00926

Browse files
committed
WIP: Converted all modifiers and wrappers to use message_base interface.
1 parent 158004f commit 7a00926

File tree

11 files changed

+113
-353
lines changed

11 files changed

+113
-353
lines changed

boost/network/message/modifiers/add_header.hpp

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
21
#ifndef BOOST_NETWORK_MESSAGE_MODIFIER_ADD_HEADER_HPP_20100824
32
#define BOOST_NETWORK_MESSAGE_MODIFIER_ADD_HEADER_HPP_20100824
43

5-
// Copyright 2010 (c) Dean Michael Berris
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
66
// Distributed under the Boost Software License, Version 1.0.
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
@@ -13,48 +13,10 @@
1313

1414
namespace boost { namespace network {
1515

16-
namespace impl {
17-
template <class Message, class KeyType, class ValueType, class Tag>
18-
inline typename enable_if<
19-
mpl::and_<
20-
mpl::not_<is_pod<Tag> >
21-
, mpl::not_<is_async<Tag> >
22-
>
23-
, void
24-
>::type
25-
add_header(Message & message, KeyType const & key, ValueType const & value, Tag) {
26-
message.headers().insert(std::make_pair(key, value));
27-
}
28-
29-
template <class Message, class KeyType, class ValueType, class Tag>
30-
inline typename enable_if<
31-
mpl::and_<
32-
mpl::not_<is_pod<Tag> >
33-
, is_async<Tag>
34-
>
35-
, void
36-
>::type
37-
add_header(Message & message, KeyType const & key, ValueType const & value, Tag) {
38-
typedef typename Message::header_type header_type;
39-
message.add_header(header_type(key,value));
40-
}
41-
42-
template <class Message, class KeyType, class ValueType, class Tag>
43-
inline typename enable_if<
44-
is_pod<Tag>
45-
, void
46-
>::type
47-
add_header(Message & message, KeyType const & key, ValueType const & value, Tag) {
48-
typename Message::header_type header = { key, value };
49-
message.headers.insert(message.headers.end(), header);
50-
}
51-
52-
}
53-
54-
template <class Tag, template <class> class Message, class KeyType, class ValueType>
55-
inline void add_header(Message<Tag> & message, KeyType const & key, ValueType const & value) {
56-
impl::add_header(message, key, value, Tag());
57-
}
16+
inline
17+
void add_header(message_base & message, std::string const & key, std::string const & value) {
18+
message.append_header(key, value);
19+
}
5820

5921
} // namespace network
6022

boost/network/message/modifiers/body.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,15 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <boost/thread/future.hpp>
10-
119
namespace boost { namespace network {
1210

13-
template <class Tag, template <class> class Message, class ValueType>
14-
inline void body_impl(Message<Tag> & message, ValueType const & body, tags::pod) {
15-
message.body = body;
16-
}
17-
18-
template <class Tag, template <class> class Message, class ValueType>
19-
inline void body_impl(Message<Tag> & message, ValueType const & body, tags::normal) {
20-
message.body(body);
21-
}
11+
inline void body(message_base & message, std::string const & body_) {
12+
message.set_body(body_);
13+
}
2214

23-
template <class Tag, template <class> class Message, class ValueType>
24-
inline void body(Message<Tag> & message, ValueType const & body_) {
25-
body_impl(message, body_, typename pod_or_normal<Tag>::type());
26-
}
15+
inline void append_body(message_base & message, std::string const & data) {
16+
message.append_body(data);
17+
}
2718

2819
} // namespace network
2920

boost/network/message/modifiers/clear_headers.hpp

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,19 @@
11
#ifndef BOOST_NETWORK_MESSAGE_MODIFIER_CLEAR_HEADERS_HPP_20100824
22
#define BOOST_NETWORK_MESSAGE_MODIFIER_CLEAR_HEADERS_HPP_20100824
33

4-
// Copyright 2010 (c) Dean Michael Berris
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
56
// Distributed under the Boost Software License, Version 1.0.
67
// (See accompanying file LICENSE_1_0.txt or copy at
78
// http://www.boost.org/LICENSE_1_0.txt)
89

9-
#include <boost/thread/future.hpp>
10-
#include <boost/utility/enable_if.hpp>
11-
#include <boost/mpl/not.hpp>
12-
#include <boost/mpl/and.hpp>
10+
#include <boost/network/message_base.hpp>
1311

1412
namespace boost { namespace network {
1513

16-
namespace impl {
17-
template <class Message, class Tag>
18-
inline typename enable_if<
19-
mpl::and_<
20-
mpl::not_<is_pod<Tag> >
21-
, mpl::not_<is_async<Tag> >
22-
>
23-
, void
24-
>::type
25-
clear_headers(Message const & message, Tag const &) {
26-
(typename Message::headers_container_type()).swap(message.headers());
27-
}
28-
29-
template <class Message, class Tag>
30-
inline typename enable_if<is_pod<Tag>, void>::type
31-
clear_headers(Message const & message, Tag const &) {
32-
(typename Message::headers_container_type()).swap(message.headers);
33-
}
34-
35-
template <class Message, class Tag>
36-
inline typename enable_if<
37-
mpl::and_<
38-
mpl::not_<is_pod<Tag> >
39-
, is_async<Tag>
40-
>
41-
, void
42-
>::type
43-
clear_headers(Message const & message, Tag const &) {
44-
boost::promise<typename Message::headers_container_type> header_promise;
45-
boost::shared_future<typename Message::headers_container_type> headers_future(header_promise.get_future());
46-
message.headers(headers_future);
47-
header_promise.set_value(typename Message::headers_container_type());
48-
}
49-
50-
} // namespace impl
51-
52-
template <class Tag, template <class> class Message>
53-
inline void clear_headers(Message<Tag> const & message) {
54-
impl::clear_headers(message, Tag());
55-
}
14+
inline void clear_headers(message_base & message) {
15+
message.remove_headers();
16+
}
5617

5718
} // namespace network
5819

boost/network/message/modifiers/destination.hpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,17 @@
22
#ifndef BOOST_NETWORK_MESSAGE_MODIFIER_DESTINATION_HPP_20100824
33
#define BOOST_NETWORK_MESSAGE_MODIFIER_DESTINATION_HPP_20100824
44

5-
// Copyright 2010 (c) Dean Michael Berris
5+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
6+
// Copyright 2011 Google, Inc.
67
// Distributed under the Boost Software License, Version 1.0.
78
// (See accompanying file LICENSE_1_0.txt or copy at
89
// http://www.boost.org/LICENSE_1_0.txt)
910

10-
#include <boost/thread/future.hpp>
11-
1211
namespace boost { namespace network {
1312

14-
namespace impl {
15-
16-
template <class Message, class ValueType, class Tag>
17-
inline void destination(Message const & message, ValueType const & destination_, Tag const &, mpl::false_ const &){
18-
message.destination(destination_);
19-
}
20-
21-
template <class Message, class ValueType, class Tag>
22-
inline void destination(Message const & message, ValueType const & destination_, Tag const &, mpl::true_ const &) {
23-
message.destination(destination_);
24-
}
25-
26-
}
27-
28-
template <class Tag, template<class> class Message, class ValueType>
29-
inline void destination(Message<Tag> const & message, ValueType const & destination_) {
30-
impl::destination(message, destination_, Tag(), is_async<Tag>());
31-
}
13+
inline void destination(message_base & message, std::string const & destination_) {
14+
message.set_destination(destination_);
15+
}
3216

3317
} // namespace network
3418

boost/network/message/modifiers/remove_header.hpp

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,15 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10-
#include <boost/utility/enable_if.hpp>
11-
#include <boost/range/algorithm/remove_if.hpp>
12-
#include <boost/algorithm/string/predicate.hpp>
13-
#include <boost/mpl/not.hpp>
10+
#include <string>
11+
#include <boost/network/message_base.hpp>
1412

1513
namespace boost { namespace network {
1614

17-
namespace impl {
18-
19-
template <class Message, class KeyType, class Tag>
20-
inline typename enable_if<
21-
mpl::and_<
22-
mpl::not_<is_pod<Tag> >
23-
, mpl::not_<is_async<Tag> >
24-
>
25-
, void
26-
>::type
27-
remove_header(Message & message, KeyType const & key, Tag) {
28-
message.headers().erase(key);
29-
}
30-
31-
template <class Message, class KeyType, class Tag>
32-
inline typename enable_if<
33-
mpl::and_<
34-
mpl::not_<is_pod<Tag> >
35-
, is_async<Tag>
36-
>
37-
, void
38-
>::type
39-
remove_header(Message & message, KeyType const & key, Tag) {
40-
message.remove_header(key);
41-
}
42-
43-
template <class KeyType>
44-
struct iequals_pred {
45-
KeyType const & key;
46-
iequals_pred(KeyType const & key)
47-
: key(key) {}
48-
template <class Header>
49-
bool operator()(Header & other) const {
50-
return boost::iequals(key, name(other));
51-
}
52-
};
53-
54-
template <class Message, class KeyType, class Tag>
55-
inline typename enable_if<
56-
is_pod<Tag>
57-
, void
58-
>::type
59-
remove_header(Message & message, KeyType const & key, Tag) {
60-
typedef typename Message::headers_container_type headers;
61-
message.headers.erase(
62-
boost::remove_if(
63-
message.headers,
64-
iequals_pred<KeyType>(key)
65-
)
66-
, message.headers.end()
67-
);
68-
}
69-
70-
71-
} // namespace impl
72-
73-
template <class Tag, template <class> class Message, class KeyType>
74-
inline void remove_header(Message<Tag> & message, KeyType const & key) {
75-
impl::remove_header(message, key, Tag());
76-
}
15+
inline
16+
void remove_header(message_base & message, std::string const & key) {
17+
message.remove_headers(key);
18+
}
7719

7820
} // namespace network
7921

boost/network/message/modifiers/source.hpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,9 @@
99

1010
namespace boost { namespace network {
1111

12-
namespace impl {
13-
14-
template <class Message, class ValueType, class Tag>
15-
inline void source(Message const & message, ValueType const & source_, Tag const &, mpl::false_ const &) {
16-
message.source(source_);
17-
}
18-
19-
template <class Message, class ValueType, class Tag>
20-
inline void source(Message const & message, ValueType const & source_, Tag const &, mpl::true_ const &) {
21-
message.source(source_);
22-
}
23-
24-
} // namespace impl
25-
26-
template <class Tag, template <class> class Message, class ValueType>
27-
inline void source(Message<Tag> const & message, ValueType const & source_) {
28-
impl::source(message, source_, Tag(), is_async<Tag>());
29-
}
12+
inline void source(message_base & message, std::string const & source_) {
13+
message.set_source(source_);
14+
}
3015

3116
} // namespace network
3217

0 commit comments

Comments
 (0)