Skip to content

Commit 6c3696f

Browse files
committed
More Gutting.
The direction this commit takes is to have the message type more expansive and transition the interface to a more object-oriented design that still adheres to the generic programming interfaces. Note, the builds still aren't complete. This is a WIP commit.
1 parent 7a00926 commit 6c3696f

File tree

13 files changed

+205
-391
lines changed

13 files changed

+205
-391
lines changed

boost/network/message.hpp

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#include <boost/network/message/modifiers/destination.hpp>
2121
#include <boost/network/message/modifiers/body.hpp>
2222

23+
#ifdef BOOST_NETWORK_DEBUG
2324
#include <boost/network/message/message_concept.hpp>
25+
#endif
26+
27+
#include <boost/network/message/basic_message.hpp>
2428

2529
/** message.hpp
2630
*
@@ -34,114 +38,98 @@ namespace boost { namespace network {
3438

3539
/** The common message type.
3640
*/
37-
template <class Tag>
38-
struct basic_message {
39-
public:
40-
41-
typedef Tag tag;
42-
43-
typedef typename headers_container<Tag>::type headers_container_type;
44-
typedef typename headers_container_type::value_type header_type;
45-
typedef typename string<Tag>::type string_type;
41+
template <class String>
42+
struct basic_message : basic_storage_base {
43+
typedef std::pair<String, String> header_type;
44+
typedef std::multimap<String, String> headers_container_type;
45+
typedef String string_type;
4646

4747
basic_message()
48-
: _headers(), _body(), _source(), _destination()
49-
{ }
48+
: basic_storage_base()
49+
{}
5050

5151
basic_message(const basic_message & other)
52-
: _headers(other._headers), _body(other._body), _source(other._source), _destination(other._destination)
53-
{ }
52+
: basic_storage_base(other)
53+
{}
5454

55-
basic_message & operator=(basic_message<Tag> rhs) {
55+
basic_message & operator=(basic_message<String> rhs) {
5656
rhs.swap(*this);
5757
return *this;
5858
}
5959

60-
void swap(basic_message<Tag> & other) {
61-
std::swap(other._headers, _headers);
62-
std::swap(other._body, _body);
63-
std::swap(other._source, _source);
64-
std::swap(other._destination, _destination);
60+
void swap(basic_message<String> & other) {
61+
basic_storage_base & this_ = *this,
62+
& other_ = other;
63+
swap(this_, other_);
6564
}
6665

6766
headers_container_type & headers() {
68-
return _headers;
67+
return pimpl->headers_;
6968
}
7069

7170
void headers(headers_container_type const & headers_) const {
72-
_headers = headers_;
71+
pimpl->headers_ = headers_;
7372
}
7473

7574
void add_header(typename headers_container_type::value_type const & pair_) const {
76-
_headers.insert(pair_);
75+
this->append_header(pair_.first, pair_.second);
7776
}
7877

7978
void remove_header(typename headers_container_type::key_type const & key) const {
80-
_headers.erase(key);
79+
this->remove_headers(key);
8180
}
8281

8382
headers_container_type const & headers() const {
84-
return _headers;
83+
return pimpl->headers_;
8584
}
8685

8786
string_type & body() {
88-
return _body;
87+
return pimpl->body_;
8988
}
9089

9190
void body(string_type const & body_) const {
92-
_body = body_;
91+
this->set_body(body_);
9392
}
9493

9594
string_type const & body() const {
96-
return _body;
95+
return pimpl->body_;
9796
}
9897

9998
string_type & source() {
100-
return _source;
99+
return pimpl->source_;
101100
}
102101

103102
void source(string_type const & source_) const {
104-
_source = source_;
103+
this->set_source(source_);
105104
}
106105

107106
string_type const & source() const {
108-
return _source;
107+
return pimpl->source_;
109108
}
110109

111110
string_type & destination() {
112-
return _destination;
111+
return pimpl->destination_;
113112
}
114113

115114
void destination(string_type const & destination_) const {
116-
_destination = destination_;
115+
this->set_destination(destination_);
117116
}
118117

119118
string_type const & destination() const {
120-
return _destination;
119+
return pimpl->destination_;
121120
}
122-
123-
private:
124-
125-
friend struct detail::directive_base<Tag> ;
126-
friend struct detail::wrapper_base<Tag, basic_message<Tag> > ;
127-
128-
mutable headers_container_type _headers;
129-
mutable string_type _body;
130-
mutable string_type _source;
131-
mutable string_type _destination;
132121
};
133122

134-
template <class Tag>
135-
inline void swap(basic_message<Tag> & left, basic_message<Tag> & right) {
136-
// swap for ADL
123+
template <class String>
124+
inline void swap(basic_message<String> & left, basic_message<String> & right) {
137125
left.swap(right);
138126
}
139127

140128
// Commenting this out as we don't need to do this anymore.
141129
// BOOST_CONCEPT_ASSERT((Message<basic_message<boost::network::tags::default_string> >));
142130
// BOOST_CONCEPT_ASSERT((Message<basic_message<boost::network::tags::default_wstring> >));
143-
typedef basic_message<tags::default_string> message;
144-
typedef basic_message<tags::default_wstring> wmessage;
131+
typedef basic_message<std::string> message;
132+
typedef basic_message<std::wstring> wmessage;
145133

146134
} // namespace network
147135
} // namespace boost
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_BASIC_MESSAGE_HPP_20110911
2+
#define BOOST_NETWORK_MESSAGE_BASIC_MESSAGE_HPP_20110911
3+
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/message_base.hpp>
11+
#include <boost/scoped_ptr.hpp>
12+
13+
namespace boost { namespace network {
14+
15+
struct basic_storage_pimpl;
16+
17+
struct basic_storage_base : message_base {
18+
basic_storage_base();
19+
basic_storage_base(basic_storage_base const &);
20+
virtual void set_destination(std::string const & destination);
21+
virtual void set_source(std::string const & source);
22+
virtual void append_header(std::string const & name,
23+
std::string const & value);
24+
virtual void remove_headers(std::string const & name);
25+
virtual void remove_headers();
26+
virtual void set_body(std::string const & body);
27+
virtual void append_body(std::string const & data);
28+
29+
virtual void get_destination(std::string & destination);
30+
virtual void get_source(std::string & source);
31+
virtual void get_headers(function<void(std::string const &, std::string const &)> inserter);
32+
virtual void get_headers(std::string const & name, function<void(std::string const &, std::string const &)> inserter);
33+
virtual void get_body(std::string & body);
34+
virtual void get_body(function<void(iterator_range<char const *>)> chunk_reader, size_t size);
35+
36+
void swap(basic_storage_base & other);
37+
38+
virtual ~basic_storage_base();
39+
protected:
40+
scoped_ptr<basic_storage_pimpl> pimpl;
41+
};
42+
43+
void swap(basic_storage_base & l, basic_storage_base & r);
44+
45+
} /* network */
46+
} /* boost */
47+
48+
#ifdef BOOST_NETWORK_NO_LIB
49+
#include <boost/network/message/basic_message.ipp>
50+
#endif
51+
52+
#endif /* BOOST_NETWORK_MESSAGE_BASIC_MESSAGE_HPP_20110911 */
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_BASIC_MESSAGE_IPP_20110911
2+
#define BOOST_NETWORK_MESSAGE_BASIC_MESSAGE_IPP_20110911
3+
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
namespace boost { namespace network {
11+
12+
struct basic_storage_pimpl {
13+
basic_storage_pimpl();
14+
basic_storage_pimpl(basic_storage_pimpl const &);
15+
16+
virtual basic_storage_pimpl* clone();
17+
protected:
18+
friend struct basic_storage_base;
19+
std::string source_, destination_;
20+
typedef std::multimap<std::string, std::string> headers_container_type;
21+
headers_container_type headers_;
22+
std::string body_;
23+
};
24+
25+
basic_storage_base::basic_storage_base()
26+
: pimpl(new (std::nothrow) basic_storage_pimpl())
27+
{}
28+
29+
basic_storage_base::basic_storage_base(basic_storage_base const & other)
30+
: pimpl(other.clone())
31+
{}
32+
33+
void basic_storage_base::set_destination(std::string const & destination) {
34+
pimpl->destination_ = destination;
35+
}
36+
37+
void basic_storage_base::set_source(std::string const & source) {
38+
pimpl->source_ = source;
39+
}
40+
41+
void basic_storage_base::append_header(std::string const & name,
42+
std::string const & value) {
43+
pimpl->headers_.insert(std::make_pair(name, value));
44+
}
45+
46+
void basic_storage_base::remove_headers(std::string const & name) {
47+
pimpl->headers_.erase(name);
48+
}
49+
50+
void basic_storage_base::remove_headers() {
51+
basic_storage_pimpl::headers_container_type().swap(pimpl->headers_);
52+
}
53+
54+
void basic_storage_base::set_body(std::string const & body) {
55+
pimpl->body = body;
56+
}
57+
58+
void basic_storage_base::append_body(std::string const & data) {
59+
pimpl->body.append(data);
60+
}
61+
62+
void basic_storage_base::get_destination(std::string & destination) {
63+
destination = pimpl->destination;
64+
}
65+
66+
void basic_storage_base::get_source(std::string & source) {
67+
source = pimpl->source;
68+
}
69+
70+
void basic_storage_base::get_headers(function<void(std::string const &, std::string const &)> inserter) {
71+
copy(pimpl->headers_, inserter);
72+
}
73+
74+
void basic_storage_base::get_headers(std::string const & name, function<void(std::string const &, std::string const &)> inserter) {
75+
basic_storage_pimpl::headers_container_type::const_iterator
76+
it = pimpl->headers_.find(name),
77+
pe = pimpl->headers_.end();
78+
for (; it != pe; ++it)
79+
inserter(it->first, it->second);
80+
}
81+
82+
void basic_storage_base::get_body(std::string & body) {
83+
// TODO use iostreams!
84+
body = pimpl_->body;
85+
}
86+
87+
void basic_storage_base::get_body(function<void(iterator_range<char const *>)> chunk_reader, size_t size) {
88+
// TODO use iostreams!
89+
std::string::const_iterator it = pimpl->body.begin(),
90+
pe = pimpl->body.end();
91+
std::advance(it, size);
92+
chunk_reader(make_iterator_range(it, pe));
93+
pimpl->body.assign(it, pe);
94+
}
95+
96+
basic_storage_base::~basic_storage_base() {
97+
pimpl->reset();
98+
}
99+
100+
void basic_storage_base::swap(basic_storage_base & other) {
101+
std::swap(pimpl, other.pimpl);
102+
}
103+
104+
void swap(basic_storage_base & l, basic_storage_base & r) {
105+
l.swap(r);
106+
}
107+
108+
} /* network */
109+
110+
} /* boost */
111+
112+
#endif /* BOOST_NETWORK_MESSAGE_BASIC_MESSAGE_IPP_20110911 */

boost/network/message/message_concept.hpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
// http://www.boost.org/LICENSE_1_0.txt)
1111

1212
#include <boost/concept_check.hpp>
13-
#include <boost/network/message/traits/body.hpp>
14-
#include <boost/network/message/traits/source.hpp>
15-
#include <boost/network/message/traits/destination.hpp>
16-
#include <boost/network/message/traits/headers.hpp>
1713
#include <boost/network/message/wrappers.hpp>
1814
#include <boost/network/message/transformers.hpp>
1915
#include <boost/network/message/directives.hpp>
@@ -29,13 +25,11 @@ namespace boost { namespace network {
2925
BOOST_CONCEPT_USAGE(Message) {
3026
M message_;
3127
swap(message, message_);
32-
33-
typedef typename traits::body<M>::type body_type;
34-
typedef typename traits::source<M>::type source_type;
35-
typedef typename traits::destination<M>::type destination_type;
36-
37-
typedef typename traits::header_key<M>::type header_key_type;
38-
typedef typename traits::header_value<M>::type header_value_type;
28+
typedef std::string source_type;
29+
typedef std::string destination_type;
30+
typedef std::string body_type;
31+
typedef std::string header_key_type;
32+
typedef std::string header_value_type;
3933

4034
headers_container_type headers_ = headers(message);
4135
string_type body_ = body(message);

0 commit comments

Comments
 (0)