Skip to content

Commit 3a68cff

Browse files
committed
Fleshing out more implementations.
1 parent 4777601 commit 3a68cff

20 files changed

+330
-77
lines changed

boost/network/message/directives/header.hpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,12 @@ namespace boost { namespace network {
1414
namespace impl {
1515

1616
struct header_directive {
17-
18-
explicit header_directive(std::string const & header_name,
19-
std::string const & header_value) :
20-
_header_name(header_name),
21-
_header_value(header_value)
22-
{ };
23-
24-
void operator() (message_base & msg) const {
25-
msg.append_header(_header_name, _header_value);
26-
}
27-
17+
explicit header_directive(std::string const & name,
18+
std::string const & value);
19+
void operator() (message_base & msg) const;
2820
private:
29-
30-
std::string const & _header_name;
31-
std::string const & _header_value;
21+
std::string const & name_;
22+
std::string const & value_;
3223
};
3324

3425
} // namespace impl
@@ -40,4 +31,8 @@ header(std::string const & header_name, std::string const & header_value) {
4031
} // namespace network
4132
} // namespace boost
4233

34+
#ifdef BOOST_NETWORK_NO_LIB
35+
#include <boost/network/message/directives/header.ipp>
36+
#endif
37+
4338
#endif // __NETWORK_MESSAGE_DIRECTIVES_HEADER_HPP__
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_DIRECTIVES_IPP_20111021
2+
#define BOOST_NETWORK_MESSAGE_DIRECTIVES_IPP_20111021
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 <string>
11+
#include <boost/network/message/directives/header.hpp>
12+
13+
namespace boost { namespace network { namespace impl {
14+
15+
header_directive::header_directive(std::string const & name,
16+
std::string const & value):
17+
name_(name),
18+
value_(value) {}
19+
20+
void header_directive::operator() (message_base & msg) const {
21+
msg.append_header(name_, value_);
22+
}
23+
24+
} /* impl */
25+
} /* network */
26+
} /* boost */
27+
28+
#endif /* BOOST_NETWORK_MESSAGE_DIRECTIVES_IPP_20111021 */
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_HPP_20111021
2+
#define BOOST_NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_HPP_20111021
13

24
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
3-
// Copyright 2011 Google, Inc.
5+
// Copyright 2011 Google, Inc.
46
// Distributed under the Boost Software License, Version 1.0.
5-
// (See accompanying file LICENSE_1_0.txt or copy at
6-
// http://www.boost.org/LICENSE_1_0.txt)
7-
8-
#ifndef NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_HPP
9-
#define NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_HPP
10-
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
119

1210
namespace boost { namespace network {
1311

1412
namespace impl {
1513

1614
struct remove_header_directive {
1715
explicit remove_header_directive(std::string const & header_name);
18-
void operator() (message_base & msg) const;
16+
void operator() (message_base & msg) const;
1917
private:
2018
std::string const & header_name_;
2119
};
@@ -29,6 +27,8 @@ remove_header(std::string const & header_name) {
2927
} // namespace network
3028
} // namespace boost
3129

30+
#ifdef BOOST_NETWORK_NO_LIB
31+
#undef BOOST_NETWORK_NO_LIB
32+
#endif
3233

33-
#endif // NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_HPP
34-
34+
#endif // BOOST_NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_HPP_20111021
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_IPP_20111021
2+
#define BOOST_NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_IPP_20111021
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/directives/remove_header.hpp>
11+
12+
namespace boost { namespace network { namespace impl {
13+
14+
remove_header_directive::remove_header_directive(std::string const & header_name):
15+
header_name_(header_name) {}
16+
17+
void remove_header_directive::operator() (message_base & msg) const {
18+
msg.remove_headers(header_name_);
19+
}
20+
21+
} /* impl */
22+
23+
} /* network */
24+
25+
} /* boost */
26+
27+
#endif /* BOOST_NETWORK_MESSAGE_DIRECTIVES_REMOVE_HEADER_IPP_20111021 */

boost/network/message/message_base.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10-
#include <boost/network/message_base.hpp>
10+
#include <boost/network/message/message_base.hpp>
1111

1212
namespace boost { namespace network {
1313

boost/network/message/wrappers/body.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_HPP_20110930
2+
#define BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_HPP_20110930
13

24
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
35
// Copyright 2011 Google, Inc.
46
// Distributed under the Boost Software License, Version 1.0.
5-
// (See accompanying file LICENSE_1_0.txt or copy at
6-
// http://www.boost.org/LICENSE_1_0.txt)
7-
8-
#ifndef BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_HPP_20110930
9-
#define BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_HPP_20110930
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
109

1110
#include <boost/range/iterator.hpp>
1211
#include <boost/optional.hpp>
@@ -17,7 +16,7 @@ namespace boost { namespace network {
1716
namespace impl {
1817

1918
struct body_wrapper {
20-
explicit body_wrapper(message_base & message_);
19+
explicit body_wrapper(message_base & message);
2120
operator std::string () const;
2221
std::size_t size() const;
2322
operator iterator_range<std::string::const_iterator> () const;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_IPP_20111021
2+
#define BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_IPP_20111021
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/wrappers/body.hpp>
11+
12+
namespace boost { namespace network { namespace impl {
13+
14+
body_wrapper::body_wrapper(message_base & message):
15+
message_(message) {}
16+
17+
body_wrapper::operator std::string () const {
18+
if (cache_) {
19+
return *cache_;
20+
}
21+
std::string tmp;
22+
message_.get_body(tmp);
23+
cache_ = tmp;
24+
return *cache_;
25+
}
26+
27+
std::size_t body_wrapper::size() const {
28+
if (cache_) {
29+
return cache_->size();
30+
}
31+
std::string tmp;
32+
message_.get_body(tmp);
33+
cache_ = tmp;
34+
return cache_->size();
35+
}
36+
37+
body_wrapper::operator boost::iterator_range<std::string::const_iterator> () const {
38+
if (cache_) {
39+
return boost::make_iterator_range(*cache_);
40+
}
41+
std::string tmp;
42+
message_.get_body(tmp);
43+
cache_ = tmp;
44+
return boost::make_iterator_range(*cache_);
45+
}
46+
47+
std::string::const_iterator body_wrapper::begin() const {
48+
if (cache_) {
49+
return cache_->begin();
50+
}
51+
std::string tmp;
52+
message_.get_body(tmp);
53+
cache_ = tmp;
54+
return cache_->begin();
55+
}
56+
57+
std::string::const_iterator body_wrapper::end() const {
58+
if (cache_) {
59+
return cache_->end();
60+
}
61+
std::string tmp;
62+
message_.get_body(tmp);
63+
cache_ = tmp;
64+
return cache_->end();
65+
}
66+
67+
} /* impl */
68+
} /* network */
69+
} /* boost */
70+
71+
#endif /* BOOST_NETWORK_MESSAGE_WRAPPERS_BODY_IPP_20111021 */

boost/network/message/wrappers/destination.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define __NETWORK_MESSAGE_WRAPPERS_DESTINATION_HPP__
33

44
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5-
// Copyright 2011 Google, Inc.
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)
@@ -14,8 +14,11 @@ namespace boost { namespace network {
1414
namespace impl {
1515

1616
struct destination_wrapper {
17-
explicit destination_wrapper(message_base & message_);
18-
operator std::string () const;
17+
explicit destination_wrapper(message_base & message);
18+
operator std::string () const;
19+
private:
20+
message_base & message_;
21+
mutable optional<std::string> cache_;
1922
};
2023

2124
} // namespace impl
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef BOOST_NETWORK_MESSAGE_WRAPPERS_DESTINATION_IPP_20111021
2+
#define BOOST_NETWORK_MESSAGE_WRAPPERS_DESTINATION_IPP_20111021
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/wrappers/destination.hpp>
11+
12+
namespace boost { namespace network { namespace impl {
13+
14+
destination_wrapper::destination_wrapper(message_base & message):
15+
message_(message) {}
16+
17+
destination_wrapper::operator std::string () const {
18+
if (cache_) {
19+
return *cache_;
20+
}
21+
std::string tmp;
22+
message_.get_destination(tmp);
23+
cache_ = tmp;
24+
return *cache_;
25+
}
26+
27+
} /* impl */
28+
29+
} /* network */
30+
31+
} /* boost */
32+
33+
#endif /* BOOST_NETWORK_MESSAGE_WRAPPERS_DESTINATION_IPP_20111021 */

boost/network/message/wrappers/headers.hpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,23 @@ namespace impl {
2424
* a range of iterators (std::pair<iterator, iterator>)
2525
* whose keys are all equal to the index string.
2626
*
27-
* This type is also convertible to a
28-
* headers_range<basic_message<tag> >::type
29-
* Which allows for full range support.
30-
*
31-
* The type is also convertible to a
32-
* headers_container<Tag>::type
33-
* Which copies the headers from the wrapped message.
34-
*
3527
*/
3628
struct headers_wrapper {
3729
typedef std::multimap<std::string, std::string> container_type;
38-
typedef iterator_range<shared_container_iterator<container_type> >
39-
range_type;
30+
typedef shared_container_iterator<container_type> iterator;
31+
typedef iterator_range<iterator> range_type;
4032

4133
explicit headers_wrapper(message_base & message);
4234
range_type operator[] (std::string const & key) const;
4335
operator range_type () const;
36+
operator container_type () const;
4437
container_type::size_type count() const;
4538
container_type::size_type count(std::string const &key) const;
39+
iterator begin() const;
40+
iterator end() const;
4641
private:
47-
void init_cache_all();
42+
void init_cache_all() const;
43+
message_base & message_;
4844
mutable shared_ptr<container_type> cache_;
4945
};
5046

@@ -65,4 +61,3 @@ headers(message_base & message_) {
6561
#endif
6662

6763
#endif // __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
68-

0 commit comments

Comments
 (0)