Skip to content

Commit d0ab2cb

Browse files
committed
Making necessary changes to make the one-liner example work.
1 parent dd7dd8c commit d0ab2cb

File tree

5 files changed

+89
-24
lines changed

5 files changed

+89
-24
lines changed

boost/network/detail/wrapper_base.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ namespace boost { namespace network { namespace detail {
1111

1212
template <class Tag>
1313
struct wrapper_base {
14-
typedef Tag tag;
15-
explicit wrapper_base(basic_message<tag> & message_)
14+
explicit wrapper_base(basic_message<Tag> & message_)
1615
: _message(message_)
17-
{ };
16+
{};
1817

1918
protected:
20-
virtual ~wrapper_base()
21-
{ }; // for extending only
19+
~wrapper_base() {}; // for extending only
2220

23-
mutable basic_message<tag> & _message;
21+
basic_message<Tag> & _message;
2422
};
2523

24+
template <class Tag>
25+
struct wrapper_base_const {
26+
explicit wrapper_base_const(basic_message<Tag> const & message_)
27+
: _message(message_)
28+
{}
29+
30+
protected:
31+
~wrapper_base_const() {}; // for extending only
32+
33+
basic_message<Tag> const & _message;
34+
};
35+
36+
2637
} // namespace detail
2738

2839
} // namespace network

boost/network/message.hpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,49 +44,65 @@ namespace boost { namespace network {
4444

4545
typedef Tag tag;
4646

47-
typedef typename headers_container<tag>::type headers_container_type;
48-
typedef typename string<tag>::type string_type;
47+
typedef typename headers_container<Tag>::type headers_container_type;
48+
typedef typename string<Tag>::type string_type;
4949

5050
basic_message()
5151
: _headers(), _body(), _source(), _destination()
52-
{ };
52+
{ }
5353

5454
basic_message(const basic_message & other)
5555
: _headers(other._headers), _body(other._body), _source(other._source), _destination(other._destination)
56-
{ };
56+
{ }
5757

58-
basic_message & operator=(basic_message<tag> rhs) {
58+
basic_message & operator=(basic_message<Tag> rhs) {
5959
rhs.swap(*this);
6060
return *this;
61-
};
61+
}
6262

63-
void swap(basic_message<tag> & other) {
63+
void swap(basic_message<Tag> & other) {
6464
other._headers.swap(_headers);
6565
other._body.swap(_body);
6666
other._source.swap(_source);
6767
other._destination.swap(_destination);
68-
};
68+
}
6969

7070
headers_container_type & headers() {
7171
return _headers;
72-
};
72+
}
73+
74+
headers_container_type headers() const {
75+
return _headers;
76+
}
7377

7478
string_type & body() {
7579
return _body;
76-
};
80+
}
81+
82+
string_type body() const {
83+
return _body;
84+
}
7785

7886
string_type & source() {
7987
return _source;
80-
};
88+
}
89+
90+
string_type source() const {
91+
return _source;
92+
}
8193

8294
string_type & destination() {
8395
return _destination;
84-
};
96+
}
97+
98+
string_type destination() const {
99+
return _destination;
100+
}
85101

86102
private:
87103

88-
friend struct detail::directive_base<tag> ;
89-
friend struct detail::wrapper_base<tag> ;
104+
friend struct detail::directive_base<Tag> ;
105+
friend struct detail::wrapper_base<Tag> ;
90106

91107
headers_container_type _headers;
92108
string_type _body;

boost/network/message/wrappers/body.hpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,32 @@ namespace boost { namespace network {
1616
namespace impl {
1717
template <class Tag>
1818
struct body_wrapper : public detail::wrapper_base<Tag> {
19-
typedef Tag tag;
20-
typedef basic_message<tag> message_type;
19+
typedef basic_message<Tag> message_type;
2120
typedef typename string<Tag>::type string_type;
2221

23-
explicit body_wrapper(basic_message<tag> & message_)
24-
: detail::wrapper_base<tag>(message_)
22+
explicit body_wrapper(basic_message<Tag> & message_)
23+
: detail::wrapper_base<Tag>(message_)
2524
{ };
2625

2726
operator string_type () const {
2827
return string_type(detail::wrapper_base<Tag>::_message.body());
2928
};
3029
};
30+
31+
template <class Tag>
32+
struct body_wrapper_const : public detail::wrapper_base_const<Tag> {
33+
typedef basic_message<Tag> message_type;
34+
typedef typename string<Tag>::type string_type;
35+
36+
explicit body_wrapper_const(basic_message<Tag> const & message_)
37+
: detail::wrapper_base_const<Tag>(message_)
38+
{};
39+
40+
operator string_type () const {
41+
return string_type(detail::wrapper_base_const<Tag>::_message.body());
42+
}
43+
};
44+
3145
} // namespace impl
3246

3347
template <class Tag>
@@ -36,6 +50,12 @@ namespace boost { namespace network {
3650
return impl::body_wrapper<Tag>(message_);
3751
}
3852

53+
template <class Tag>
54+
inline typename string<Tag>::type
55+
body(basic_message<Tag> const & message_) {
56+
return impl::body_wrapper_const<Tag>(message_);
57+
}
58+
3959
} // namespace network
4060

4161
} // namespace boost

libs/network/example/Jamfile.v2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ exe simple_wget : simple_wget.cpp ;
3131
exe hello_world_server : http/hello_world_server.cpp ;
3232

3333
exe hello_world_client : http/hello_world_client.cpp ;
34+
35+
exe one_liner : http/one_liner.cpp ;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Copyright Dean Michael Berris 2010.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <boost/network.hpp>
8+
9+
using namespace std;
10+
using namespace boost::network;
11+
using namespace boost::network::http;
12+
13+
int main(int argc, const char *argv[]) {
14+
cout << body(client().get(client::request("http://www.boost.org/")));
15+
return 0;
16+
}

0 commit comments

Comments
 (0)