Skip to content

Commit c44e28c

Browse files
author
mikhail_beris
committed
Adding destination directive and wrapper, with appropriate unit test.
1 parent d318a5e commit c44e28c

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed

boost/network/message.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ namespace boost { namespace network {
5454
return _source;
5555
};
5656

57+
std::string & destination() const {
58+
return _destination;
59+
};
60+
5761
private:
5862

5963
friend struct detail::directive_base<tag> ;
@@ -62,6 +66,7 @@ namespace boost { namespace network {
6266
mutable headers_container_type _headers;
6367
mutable std::string _body;
6468
mutable std::string _source;
69+
mutable std::string _destination;
6570
};
6671

6772
typedef basic_message<> message; // default message type

boost/network/message/directives.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/network/message/directives/header.hpp>
1414
#include <boost/network/message/directives/body.hpp>
1515
#include <boost/network/message/directives/source.hpp>
16+
#include <boost/network/message/directives/destination.hpp>
1617

1718
namespace boost { namespace network {
1819

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_DESTINATION_HPP__
8+
#define __NETWORK_MESSAGE_DIRECTIVES_DESTINATION_HPP__
9+
10+
/** destination.hpp
11+
*
12+
* Defines the types involved and the semantics of adding
13+
* destination information 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 destination_directive : public detail::directive_base<Tag> {
24+
typedef Tag tag;
25+
26+
explicit destination_directive ( std::string const & destination)
27+
: _destination(destination)
28+
{ };
29+
30+
void operator() (basic_message<tag> & msg) const {
31+
msg.destination() = _destination;
32+
};
33+
34+
private:
35+
36+
std::string _destination;
37+
};
38+
}; // namespace impl
39+
40+
inline impl::destination_directive<tags::default_>
41+
destination(std::string const & destination_) {
42+
return impl::destination_directive<tags::default_>(destination_);
43+
};
44+
45+
}; // namespace network
46+
47+
}; // namespace boost
48+
49+
#endif // __NETWORK_MESSAGE_DIRECTIVES_DESTINATION_HPP__

boost/network/message/directives/source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef __NETWORK_MESSAGE_DIRECTIVES_SOURCE_HPP__
88
#define __NETWORK_MESSAGE_DIRECTIVES_SOURCE_HPP__
99

10-
/** header.hpp
10+
/** source.hpp
1111
*
1212
* Defines the types involved and the semantics of adding
1313
* source information into message objects.

boost/network/message/wrappers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
#include <boost/network/message/wrappers/headers.hpp>
1515
#include <boost/network/message/wrappers/body.hpp>
1616
#include <boost/network/message/wrappers/source.hpp>
17+
#include <boost/network/message/wrappers/destination.hpp>
1718

1819
#endif // __NETWORK_MESSAGE_WRAPPERS_HPP__
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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_DESTINATION_HPP__
8+
#define __NETWORK_MESSAGE_WRAPPERS_DESTINATION_HPP__
9+
10+
namespace boost { namespace network {
11+
12+
namespace impl {
13+
template <class Tag>
14+
struct destination_wrapper : public detail::wrapper_base<Tag> {
15+
typedef Tag tag;
16+
typedef basic_message<tag> message_type;
17+
18+
explicit destination_wrapper(message_type & message_)
19+
: detail::wrapper_base<tag>(message_)
20+
{ };
21+
22+
operator std::string () const {
23+
return std::string(detail::wrapper_base<tag>::_message.destination());
24+
};
25+
};
26+
}; // namespace impl
27+
28+
template <class Tag>
29+
inline std::string
30+
destination(basic_message<Tag> & message_) {
31+
return impl::destination_wrapper<Tag>(message_);
32+
};
33+
34+
}; // namespace network
35+
36+
}; // namespace boost
37+
38+
#endif __NETWORK_MESSAGE_WRAPPERS_DESTINATION_HPP__
39+

libs/network/test/message_test.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ BOOST_AUTO_TEST_CASE(source_directive_test) {
4848
msg << source("Somewhere Out There") ;
4949

5050
BOOST_CHECK_EQUAL( source(msg), "Somewhere Out There");
51-
}
51+
}
52+
53+
BOOST_AUTO_TEST_CASE(destination_directive_test) {
54+
using namespace boost::network;
55+
message msg;
56+
msg << destination("Somewhere Out There");
57+
58+
BOOST_CHECK_EQUAL( destination(msg), "Somewhere Out There");
59+
};

0 commit comments

Comments
 (0)