File tree Expand file tree Collapse file tree 7 files changed +106
-0
lines changed Expand file tree Collapse file tree 7 files changed +106
-0
lines changed Original file line number Diff line number Diff line change @@ -46,12 +46,17 @@ namespace boost { namespace network {
46
46
return _headers;
47
47
};
48
48
49
+ std::string & body () const {
50
+ return _body;
51
+ };
52
+
49
53
private:
50
54
51
55
friend struct detail ::directive_base<tag> ;
52
56
friend struct detail ::wrapper_base<tag> ;
53
57
54
58
mutable headers_container_type _headers;
59
+ mutable std::string _body;
55
60
};
56
61
57
62
typedef basic_message<> message; // default message type
Original file line number Diff line number Diff line change 11
11
*/
12
12
13
13
#include < boost/network/message/directives/header.hpp>
14
+ #include < boost/network/message/directives/body.hpp>
14
15
15
16
namespace boost { namespace network {
16
17
Original file line number Diff line number Diff line change
1
+
2
+ // Copyright Dean Michael Berris 2007.
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
+ #ifndef __NETWORK_MESSAGE_DIRECTIVES_BODY_HPP__
8
+ #define __NETWORK_MESSAGE_DIRECTIVES_BODY_HPP__
9
+
10
+ /* * body.hpp
11
+ *
12
+ * Defines the types involved and the semantics of adding
13
+ * body contents into message objects.
14
+ *
15
+ * WARNING: DO NOT INCLUDE THIS HEADER DIRECTLY. THIS REQUIRES
16
+ * TYPES TO BE DEFINED FROM EARLIER FILES THAT INCLUDE THIS
17
+ * HEADER.
18
+ */
19
+ namespace boost { namespace network {
20
+
21
+ namespace impl {
22
+ template <class Tag >
23
+ struct body_directive : public detail ::directive_base<Tag> {
24
+ typedef Tag tag;
25
+
26
+ explicit body_directive (
27
+ std::string const & body
28
+ ) :
29
+ _body(body)
30
+ { };
31
+
32
+ void operator () (basic_message<tag> & msg) const {
33
+ msg.body () = _body;
34
+ };
35
+
36
+ private:
37
+
38
+ std::string _body;
39
+ };
40
+ }; // namespace impl
41
+
42
+ inline impl::body_directive<tags::default_>
43
+ body (std::string const & body_) {
44
+ return impl::body_directive<tags::default_>(body_);
45
+ };
46
+
47
+ }; // namespace network
48
+
49
+ }; // namespace boost
50
+
51
+ #endif // __NETWORK_MESSAGE_DIRECTIVES_BODY_HPP__
52
+
Original file line number Diff line number Diff line change 12
12
* Pulls in all the wrapper header files.
13
13
*/
14
14
#include < boost/network/message/wrappers/headers.hpp>
15
+ #include < boost/network/message/wrappers/body.hpp>
15
16
16
17
#endif // __NETWORK_MESSAGE_WRAPPERS_HPP__
Original file line number Diff line number Diff line change
1
+
2
+ // Copyright Dean Michael Berris 2007.
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
+ #ifndef __NETWORK_MESSAGE_WRAPPERS_BODY_HPP__
8
+ #define __NETWORK_MESSAGE_WRAPPERS_BODY_HPP__
9
+
10
+ namespace boost { namespace network {
11
+
12
+ namespace impl {
13
+ template <class Tag >
14
+ struct body_wrapper : public detail ::wrapper_base<Tag> {
15
+ typedef Tag tag;
16
+ typedef basic_message<tag> message_type;
17
+
18
+ explicit body_wrapper (basic_message<tag> & message_)
19
+ : detail::wrapper_base<tag>(message_)
20
+ { };
21
+
22
+ operator std::string () const {
23
+ return std::string (_message.body ());
24
+ };
25
+ };
26
+ }; // namespace impl
27
+
28
+ template <class Tag >
29
+ inline std::string
30
+ body (basic_message<Tag> & message_) {
31
+ return impl::body_wrapper<Tag>(message_);
32
+ };
33
+
34
+ }; // namespace network
35
+
36
+ }; // namespace boost
37
+
38
+ #endif // __NETWORK_MESSAGE_WRAPPERS_BODY_HPP__
39
+
Original file line number Diff line number Diff line change @@ -30,3 +30,11 @@ BOOST_AUTO_TEST_CASE(header_directives_test) {
30
30
headers_range<message>::type range = headers (msg)[" SOME_HEADER" ];
31
31
BOOST_CHECK ( range.first != range.second );
32
32
}
33
+
34
+ BOOST_AUTO_TEST_CASE (body_directive_test) {
35
+ using namespace boost ::network;
36
+ message msg;
37
+ msg << body (" The quick brown fox jumps over the lazy dog." ) ;
38
+
39
+ BOOST_CHECK_EQUAL ( body (msg), " The quick brown fox jumps over the lazy dog." );
40
+ }
You can’t perform that action at this time.
0 commit comments