Skip to content

Commit bd41f3c

Browse files
committed
Message Refactoring
This commit gets the message tests to compile, but now the linker complains that the implementation of the stubbed out interfaces for the message implementation(s) are not available. This is a milestone which indicates that the work required to get the library into working shape would be clearer now. More work lies ahead.
1 parent b1cfe58 commit bd41f3c

26 files changed

+212
-481
lines changed

boost/network/message.hpp

Lines changed: 33 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include <boost/network/message/message_concept.hpp>
2525
#endif
2626

27-
#include <boost/network/message/basic_message.hpp>
28-
2927
/** message.hpp
3028
*
3129
* This header file implements the common message type which
@@ -38,136 +36,44 @@ namespace boost { namespace network {
3836

3937
/** The common message type.
4038
*/
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;
46-
47-
basic_message()
48-
: basic_storage_base()
49-
{}
50-
51-
basic_message(const basic_message & other)
52-
: basic_storage_base(other)
53-
{}
54-
55-
basic_message & operator=(basic_message<String> rhs) {
56-
rhs.swap(*this);
57-
return *this;
58-
}
59-
60-
void swap(basic_message<String> & other) {
61-
basic_storage_base & this_ = *this,
62-
& other_ = other;
63-
swap(this_, other_);
64-
}
65-
66-
headers_container_type & headers() {
67-
if (!headers_) {
68-
headers_ = headers_container_type();
69-
this->get_headers(*headers_);
70-
}
71-
return *headers_;
72-
}
73-
74-
void headers(headers_container_type const & headers_) const {
75-
this->set_headers(headers_);
76-
}
77-
78-
void add_header(typename headers_container_type::value_type const & pair_) const {
79-
this->append_header(pair_.first, pair_.second);
80-
}
81-
82-
void remove_header(typename headers_container_type::key_type const & key) const {
83-
this->remove_headers(key);
84-
}
85-
86-
headers_container_type const & headers() const {
87-
if (!headers_) {
88-
headers_ = headers_container_type();
89-
this->get_headers(*headers_);
90-
}
91-
return *headers_;
92-
}
93-
94-
string_type & body() {
95-
if (!body_) {
96-
body_ = String();
97-
this->get_body(*body_);
98-
}
99-
return *body_;
100-
}
101-
102-
void body(string_type const & body_) const {
103-
this->set_body(body_);
104-
}
105-
106-
string_type const & body() const {
107-
if (!body_) {
108-
body_ = String();
109-
this->get_body(*body_);
110-
}
111-
return *body_;
112-
}
113-
114-
string_type & source() {
115-
if (!source_) {
116-
source_ = String();
117-
this->get_source(*source_);
118-
}
119-
return *source_;
120-
}
121-
122-
void source(string_type const & source_) const {
123-
this->set_source(source_);
124-
}
125-
126-
string_type const & source() const {
127-
if (!source_) {
128-
source_ = String();
129-
this->get_source(*source_);
130-
}
131-
return *source_;
132-
}
133-
134-
string_type & destination() {
135-
if (!destination_) {
136-
destination_ = String();
137-
this->get_destination(*destination_);
138-
}
139-
return *destination_;
140-
}
141-
142-
void destination(string_type const & destination_) const {
143-
this->set_destination(destination_);
144-
}
145-
146-
string_type const & destination() const {
147-
if (!destination_) {
148-
destination_ = String();
149-
this->get_destination(*destination_);
150-
}
151-
return *destination_;
152-
}
153-
154-
protected:
155-
optional<String> source_, destination_;
156-
optional<headers_container_type> headers_;
157-
optional<String> body_;
39+
struct message : message_base {
40+
// Nested types
41+
typedef iterator_range<
42+
shared_container_iterator<std::multimap<std::string, std::string> > >
43+
headers_range;
44+
45+
// Mutators
46+
virtual void set_destination(std::string const & destination);
47+
virtual void set_source(std::string const & source);
48+
virtual void append_header(std::string const & name,
49+
std::string const & value);
50+
virtual void remove_headers(std::string const & name);
51+
virtual void remove_headers();
52+
virtual void set_body(std::string const & body);
53+
virtual void append_body(std::string const & data);
54+
55+
// Retrievers
56+
virtual void get_destination(std::string & destination);
57+
virtual void get_source(std::string & source);
58+
virtual void get_headers(function<void(std::string const &, std::string const &)> inserter);
59+
virtual void get_headers(std::string const & name, function<void(std::string const &, std::string const &)> inserter);
60+
virtual void get_headers(function<bool(std::string const &, std::string const &)> predicate, function<void(std::string const &, std::string const &)> inserter);
61+
virtual void get_body(std::string const & body);
62+
virtual void get_body(function<void(iterator_range<char const *>)> chunk_reader, size_t size);
63+
void swap(message & other);
64+
virtual ~message();
15865
};
15966

160-
template <class String>
161-
inline void swap(basic_message<String> & left, basic_message<String> & right) {
67+
inline void swap(message & left, message & right) {
16268
left.swap(right);
16369
}
164-
165-
// Commenting this out as we don't need to do this anymore.
166-
// BOOST_CONCEPT_ASSERT((Message<basic_message<boost::network::tags::default_string> >));
167-
// BOOST_CONCEPT_ASSERT((Message<basic_message<boost::network::tags::default_wstring> >));
168-
typedef basic_message<std::string> message;
169-
typedef basic_message<std::wstring> wmessage;
17070

71+
template <class Directive>
72+
message_base & operator<< (message_base & msg, Directive directive) {
73+
directive(msg);
74+
return msg;
75+
}
76+
17177
} // namespace network
17278
} // namespace boost
17379

boost/network/message/directives.hpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@
1313

1414
namespace boost { namespace network {
1515

16-
template <class Tag, class Directive>
17-
inline basic_message<Tag> &
18-
operator<< (basic_message<Tag> & message_, Directive const & directive) {
19-
directive(message_);
20-
return message_;
21-
}
22-
23-
BOOST_NETWORK_STRING_DIRECTIVE(source, source_, message.source(source_), message.source=source_);
24-
BOOST_NETWORK_STRING_DIRECTIVE(destination, destination_, message.destination(destination_), message.destination=destination_);
25-
BOOST_NETWORK_STRING_DIRECTIVE(body, body_, message.body(body_), message.body=body_);
16+
BOOST_NETWORK_STRING_DIRECTIVE(source);
17+
BOOST_NETWORK_STRING_DIRECTIVE(destination);
18+
BOOST_NETWORK_STRING_DIRECTIVE(body);
2619

2720
} // namespace network
2821

boost/network/message/directives/detail/string_directive.hpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,22 @@
2929
*/
3030

3131
#ifndef BOOST_NETWORK_STRING_DIRECTIVE
32-
#define BOOST_NETWORK_STRING_DIRECTIVE(name, value, body, pod_body) \
33-
template <class ValueType> \
32+
#define BOOST_NETWORK_STRING_DIRECTIVE(name) \
3433
struct name##_directive { \
35-
ValueType const & value; \
36-
explicit name##_directive(ValueType const & value_) \
34+
std::string const & value; \
35+
explicit name##_directive(std::string const & value_) \
3736
: value(value_) {} \
3837
name##_directive(name##_directive const & other) \
3938
: value(other.value) {} \
40-
template <class Tag, template <class> class Message> \
41-
typename enable_if<is_pod<Tag>, void>::type \
42-
operator()(Message<Tag> & message) const { \
43-
pod_body; \
44-
} \
45-
template <class Tag, template <class> class Message> \
46-
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type \
47-
operator()(Message<Tag> & message) const { \
48-
body; \
39+
template <class Message> \
40+
void operator()(Message & message) const { \
41+
message.set_##name(value); \
4942
} \
5043
}; \
5144
\
52-
template <class T> inline name##_directive<T> \
53-
name (T const & input) { \
54-
return name##_directive<T>(input); \
45+
inline name##_directive const \
46+
name (std::string const & input) { \
47+
return name##_directive(input); \
5548
}
5649
#endif /* BOOST_NETWORK_STRING_DIRECTIVE */
5750

boost/network/message/directives/header.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ namespace boost { namespace network {
1313

1414
namespace impl {
1515

16-
template <class KeyType, class ValueType>
1716
struct header_directive {
1817

19-
explicit header_directive(KeyType const & header_name,
20-
ValueType const & header_value) :
18+
explicit header_directive(std::string const & header_name,
19+
std::string const & header_value) :
2120
_header_name(header_name),
2221
_header_value(header_value)
2322
{ };
@@ -28,16 +27,15 @@ struct header_directive {
2827

2928
private:
3029

31-
KeyType const & _header_name;
32-
ValueType const & _header_value;
30+
std::string const & _header_name;
31+
std::string const & _header_value;
3332
};
3433

3534
} // namespace impl
3635

37-
template <class T1, class T2>
38-
inline impl::header_directive<T1, T2>
39-
header(T1 const & header_name, T2 const & header_value) {
40-
return impl::header_directive<T1, T2>(header_name, header_value);
36+
inline impl::header_directive
37+
header(std::string const & header_name, std::string const & header_value) {
38+
return impl::header_directive(header_name, header_value);
4139
}
4240
} // namespace network
4341
} // namespace boost

boost/network/message/directives/remove_header.hpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
// Copyright Dean Michael Berris 2008.
2+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
3+
// Copyright 2011 Google, Inc.
34
// Distributed under the Boost Software License, Version 1.0.
45
// (See accompanying file LICENSE_1_0.txt or copy at
56
// http://www.boost.org/LICENSE_1_0.txt)
@@ -10,40 +11,20 @@
1011

1112
namespace boost { namespace network {
1213

13-
template <class Tag>
14-
struct basic_message;
15-
1614
namespace impl {
17-
template <
18-
class T
19-
>
20-
struct remove_header_directive {
21-
22-
explicit remove_header_directive(T header_name) :
23-
header_name_(header_name)
24-
{ };
25-
26-
template <class MessageTag>
27-
void operator() (basic_message<MessageTag> & msg) const {
28-
msg.headers().erase(header_name_);
29-
}
3015

31-
private:
32-
mutable T header_name_;
16+
struct remove_header_directive {
17+
explicit remove_header_directive(std::string const & header_name);
18+
void operator() (message_base & msg) const;
19+
private:
20+
std::string const & header_name_;
3321
};
3422

3523
} // namespace impl
3624

37-
inline
38-
impl::remove_header_directive<std::string>
39-
remove_header(std::string header_name) {
40-
return impl::remove_header_directive<std::string>(header_name);
41-
}
42-
43-
inline
44-
impl::remove_header_directive<std::wstring>
45-
remove_header(std::wstring header_name) {
46-
return impl::remove_header_directive<std::wstring>(header_name);
25+
inline impl::remove_header_directive const
26+
remove_header(std::string const & header_name) {
27+
return impl::remove_header_directive(header_name);
4728
}
4829
} // namespace network
4930
} // namespace boost

boost/network/message/wrappers/headers.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ namespace impl {
3535
*/
3636
struct headers_wrapper {
3737
typedef std::multimap<std::string, std::string> container_type;
38-
typedef shared_container_iterator<container_type> iterator;
3938
typedef iterator_range<shared_container_iterator<container_type> >
4039
range_type;
4140

4241
explicit headers_wrapper(message_base & message);
4342
range_type operator[] (std::string const & key) const;
43+
operator range_type () const;
4444
container_type::size_type count() const;
45+
container_type::size_type count(std::string const &key) const;
4546
private:
4647
void init_cache_all();
4748
mutable shared_ptr<container_type> cache_;
@@ -50,7 +51,7 @@ struct headers_wrapper {
5051
} // namespace impl
5152

5253
/// Factory method to create the right wrapper object
53-
inline impl::headers_wrapper
54+
inline impl::headers_wrapper const
5455
headers(message_base & message_) {
5556
return impl::headers_wrapper(message_);
5657
}

0 commit comments

Comments
 (0)