Skip to content

Commit 0e521d0

Browse files
committed
WIP: Gutting the message implementation.
1 parent 6c3696f commit 0e521d0

File tree

3 files changed

+65
-64
lines changed

3 files changed

+65
-64
lines changed

boost/network/message.hpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ namespace boost { namespace network {
6464
}
6565

6666
headers_container_type & headers() {
67-
return pimpl->headers_;
67+
if (!headers_) {
68+
headers_ = headers_container_type();
69+
this->get_headers(*headers_);
70+
}
71+
return *headers_;
6872
}
6973

7074
void headers(headers_container_type const & headers_) const {
71-
pimpl->headers_ = headers_;
75+
this->set_headers(headers_);
7276
}
7377

7478
void add_header(typename headers_container_type::value_type const & pair_) const {
@@ -80,44 +84,77 @@ namespace boost { namespace network {
8084
}
8185

8286
headers_container_type const & headers() const {
83-
return pimpl->headers_;
87+
if (!headers_) {
88+
headers_ = headers_container_type();
89+
this->get_headers(*headers_);
90+
}
91+
return *headers_;
8492
}
8593

8694
string_type & body() {
87-
return pimpl->body_;
95+
if (!body_) {
96+
body_ = String();
97+
this->get_body(*body_);
98+
}
99+
return *body_;
88100
}
89101

90102
void body(string_type const & body_) const {
91103
this->set_body(body_);
92104
}
93105

94106
string_type const & body() const {
95-
return pimpl->body_;
107+
if (!body_) {
108+
body_ = String();
109+
this->get_body(*body_);
110+
}
111+
return *body_;
96112
}
97113

98114
string_type & source() {
99-
return pimpl->source_;
115+
if (!source_) {
116+
source_ = String();
117+
this->get_source(*source_);
118+
}
119+
return *source_;
100120
}
101121

102122
void source(string_type const & source_) const {
103123
this->set_source(source_);
104124
}
105125

106126
string_type const & source() const {
107-
return pimpl->source_;
127+
if (!source_) {
128+
source_ = String();
129+
this->get_source(*source_);
130+
}
131+
return *source_;
108132
}
109133

110134
string_type & destination() {
111-
return pimpl->destination_;
135+
if (!destination_) {
136+
destination_ = String();
137+
this->get_destination(*destination_);
138+
}
139+
return *destination_;
112140
}
113141

114142
void destination(string_type const & destination_) const {
115143
this->set_destination(destination_);
116144
}
117145

118146
string_type const & destination() const {
119-
return pimpl->destination_;
147+
if (!destination_) {
148+
destination_ = String();
149+
this->get_destination(*destination_);
150+
}
151+
return *destination_;
120152
}
153+
154+
protected:
155+
optional<String> source_, destination_;
156+
optional<headers_container_type> headers_;
157+
optional<String> body_;
121158
};
122159

123160
template <class String>

boost/network/protocol/http/message/directives/status.hpp

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,40 @@
11
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_HPP_20100603
22
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_HPP_20100603
33

4-
// Copyright 2010 (c) Dean Michael Berris
54
// Copyright 2010 (c) Sinefunc, Inc.
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

1011
#include <boost/thread/future.hpp>
1112
#include <boost/mpl/if.hpp>
12-
#include <boost/variant/variant.hpp>
13-
#include <boost/variant/static_visitor.hpp>
14-
#include <boost/variant/apply_visitor.hpp>
1513
#include <boost/cstdint.hpp>
1614

1715
namespace boost { namespace network { namespace http {
1816

19-
template <class Tag>
20-
struct basic_response;
21-
22-
struct status_directive {
17+
template <class String>
18+
struct status_directive {
2319

24-
boost::variant<
25-
boost::uint16_t,
26-
boost::shared_future<boost::uint16_t>
27-
> status_;
20+
status_directive(String const & s)
21+
: status_(s)
22+
{}
2823

29-
explicit status_directive(boost::uint16_t status)
30-
: status_(status) {}
24+
void operator()(response_base & response) {
25+
response.set_status(status_);
26+
}
3127

32-
explicit status_directive(boost::shared_future<boost::uint16_t> const & status)
33-
: status_(status) {}
28+
protected:
29+
30+
String status_;
3431

35-
status_directive(status_directive const & other)
36-
: status_(other.status_) {}
32+
};
3733

38-
template <class Tag>
39-
struct value
40-
: mpl::if_<
41-
is_async<Tag>,
42-
boost::shared_future<boost::uint16_t>,
43-
boost::uint16_t
44-
>
45-
{};
46-
47-
template <class Tag>
48-
struct status_visitor : boost::static_visitor<> {
49-
basic_response<Tag> const & response;
50-
status_visitor(basic_response<Tag> const & response)
51-
: response(response) {}
52-
53-
void operator()(typename value<Tag>::type const & status_) const {
54-
response.status(status_);
55-
}
56-
57-
template <class T>
58-
void operator()(T const &) const {
59-
// FIXME fail here!
60-
}
61-
};
62-
63-
template <class Tag> basic_response<Tag> const & operator() (basic_response<Tag> const & response) const {
64-
apply_visitor(status_visitor<Tag>(response), status_);
65-
return response;
66-
}
67-
68-
};
69-
70-
template <class T>
71-
inline status_directive const status(T const & status_) {
72-
return status_directive(status_);
73-
}
34+
template <class String>
35+
inline status_directive<String> status(String const & response) {
36+
return status_directive<String>(response);
37+
}
7438

7539
} // namespace http
7640

boost/network/protocol/http/request.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct request_storage_base {
3333
virtual void append_header(std::string const &name, std::string const &value);
3434
};
3535

36-
struct request_base : request_storage_base {
36+
struct request_base : message_base, request_storage_base {
3737
protected:
3838
using request_storage_base::body_stream;
3939
request_base();

0 commit comments

Comments
 (0)