Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78363fc

Browse files
committed
Big blob of changes, to support asynchronous messages that use Boost.Thread futures internally.
1 parent7814723 commit78363fc

35 files changed

+952
-394
lines changed

‎boost/network/message.hpp‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
// include wrappers base
2525
#include<boost/network/detail/wrapper_base.hpp>
2626

27+
#include<boost/network/message/modifiers/add_header.hpp>
28+
#include<boost/network/message/modifiers/remove_header.hpp>
29+
#include<boost/network/message/modifiers/clear_headers.hpp>
30+
#include<boost/network/message/modifiers/source.hpp>
31+
#include<boost/network/message/modifiers/destination.hpp>
32+
#include<boost/network/message/modifiers/body.hpp>
33+
2734
#include<boost/network/message/message_concept.hpp>
2835

2936
/** message.hpp
@@ -71,14 +78,30 @@ namespace boost { namespace network {
7178
return _headers;
7279
}
7380

74-
headers_container_typeheaders()const {
81+
voidheaders(headers_container_typeconst & headers_)const {
82+
_headers = headers_;
83+
}
84+
85+
voidadd_header(typename headers_container_type::value_typeconst & pair_)const {
86+
_headers.insert(pair_);
87+
}
88+
89+
voidremove_header(typename headers_container_type::key_typeconst & key)const {
90+
_headers.erase(key);
91+
}
92+
93+
headers_container_type &headers()const {
7594
return _headers;
7695
}
7796

7897
string_type &body() {
7998
return _body;
8099
}
81100

101+
voidbody(string_typeconst & body_)const {
102+
_body = body_;
103+
}
104+
82105
string_typebody()const {
83106
return _body;
84107
}
@@ -87,6 +110,10 @@ namespace boost { namespace network {
87110
return _source;
88111
}
89112

113+
voidsource(string_typeconst & source_)const {
114+
_source = source_;
115+
}
116+
90117
string_typesource()const {
91118
return _source;
92119
}
@@ -95,6 +122,10 @@ namespace boost { namespace network {
95122
return _destination;
96123
}
97124

125+
voiddestination(string_typeconst & destination_)const {
126+
_destination = destination_;
127+
}
128+
98129
string_typedestination()const {
99130
return _destination;
100131
}
@@ -104,10 +135,10 @@ namespace boost { namespace network {
104135
friendstructdetail::directive_base<Tag> ;
105136
friendstructdetail::wrapper_base<Tag> ;
106137

107-
headers_container_type _headers;
108-
string_type _body;
109-
string_type _source;
110-
string_type _destination;
138+
mutableheaders_container_type _headers;
139+
mutablestring_type _body;
140+
mutablestring_type _source;
141+
mutablestring_type _destination;
111142
};
112143

113144
template<classTag>

‎boost/network/message/directives/body.hpp‎

Lines changed: 96 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,106 @@
88
#define__NETWORK_MESSAGE_DIRECTIVES_BODY_HPP__
99

1010
#include<boost/network/traits/string.hpp>
11+
#include<boost/network/support/is_async.hpp>
12+
#include<boost/network/support/is_sync.hpp>
13+
#include<boost/type_traits/is_same.hpp>
14+
#include<boost/variant/variant.hpp>
15+
#include<boost/variant/apply_visitor.hpp>
16+
#include<boost/variant/static_visitor.hpp>
17+
#include<boost/mpl/if.hpp>
18+
#include<boost/mpl/or.hpp>
1119

12-
13-
/** body.hpp
14-
*
15-
* Defines the types involved and the semantics of adding
16-
* body contents into message objects.
17-
*
18-
* WARNING: DO NOT INCLUDE THIS HEADER DIRECTLY. THIS REQUIRES
19-
* TYPES TO BE DEFINED FROM EARLIER FILES THAT INCLUDE THIS
20-
* HEADER.
21-
*/
2220
namespaceboost {namespacenetwork {
23-
namespaceimpl {
24-
template<
25-
classT
26-
>
27-
structbody_directive {
28-
29-
explicitbody_directive(T body) :
30-
_body(body)
31-
{ };
32-
33-
template<classMessageTag>
34-
voidoperator() (basic_message<MessageTag> & msg)const {
35-
msg.body() = _body;
36-
}
37-
38-
private:
39-
40-
T _body;
41-
};
42-
}// namespace impl
43-
44-
45-
// template <
46-
// class T
47-
// >
48-
// inline
49-
// impl::body_directive<T>
50-
// body(T body_, boost::disable_if<T::message>::type) {
51-
// return impl::body_directive<T>(body_);
52-
// }
53-
54-
55-
inline
56-
impl::body_directive<std::string>
57-
body(std::string body_) {
58-
return impl::body_directive<std::string>(body_);
59-
}
6021

22+
namespacetraits {
23+
template<classTag>
24+
structunsupported_tag;
25+
26+
template<classMessage>
27+
structbody :
28+
mpl::if_<
29+
is_async<typename Message::tag>,
30+
boost::shared_future<typename string<typename Message::tag>::type>,
31+
typename mpl::if_<
32+
mpl::or_<
33+
is_sync<typename Message::tag>,
34+
is_same<typename Message::tag, tags::default_string>,
35+
is_same<typename Message::tag, tags::default_wstring>
36+
>,
37+
typename string<typename Message::tag>::type,
38+
unsupported_tag<typename Message::tag>
39+
>::type
40+
>
41+
{};
42+
}// namespace traits
43+
44+
namespaceimpl {
45+
46+
structbody_directive {
47+
boost::variant<
48+
string<tags::default_string>::type,
49+
string<tags::default_wstring>::type,
50+
boost::shared_future<string<tags::default_string>::type>,
51+
boost::shared_future<string<tags::default_wstring>::type>
52+
> body_;
53+
54+
body_directive(string<tags::default_string>::typeconst & body)
55+
: body_(body) {}
56+
body_directive(string<tags::default_wstring>::typeconst & body)
57+
: body_(body) {}
58+
body_directive(boost::shared_future<string<tags::default_string>::type>const & body)
59+
: body_(body) {}
60+
body_directive(boost::shared_future<string<tags::default_wstring>::type>const & body)
61+
: body_(body) {}
62+
63+
body_directive(body_directiveconst & other)
64+
: body_(other.body_) {}
65+
66+
template<classTag>
67+
structvalue :
68+
mpl::if_<
69+
is_async<Tag>,
70+
boost::shared_future<typename string<Tag>::type>,
71+
typename mpl::if_<
72+
mpl::or_<
73+
is_sync<Tag>,
74+
is_same<Tag, tags::default_string>,
75+
is_same<Tag, tags::default_wstring>
76+
>,
77+
typename string<Tag>::type,
78+
unsupported_tag<Tag>
79+
>::type
80+
>
81+
{};
82+
83+
template<classMessage>
84+
structbody_visitor : boost::static_visitor<> {
85+
Messageconst & message_;
86+
body_visitor(Messageconst & message)
87+
: message_(message) {}
88+
voidoperator()(typename value<typename Message::tag>::typeconst & body)const {
89+
message_.body(body);
90+
}
91+
template<classT>voidoperator()(Tconst &)const {
92+
// FIXME -- fail here
93+
}
94+
};
95+
96+
template<classTag,template<class>classMessage>
97+
voidoperator()(Message<Tag>const & message)const {
98+
apply_visitor(body_visitor<Message<Tag> >(message), body_);
99+
}
100+
101+
};
102+
103+
}// namespace impl
104+
105+
106+
template<classInput>
107+
inline impl::body_directiveconstbody(Inputconst & input) {
108+
returnimpl::body_directive(input);
109+
}
61110

62-
inline
63-
impl::body_directive<std::wstring>
64-
body(std::wstring body_) {
65-
return impl::body_directive<std::wstring>(body_);
66-
}
67111
}// namespace network
68112
}// namespace boost
69113

‎boost/network/message/directives/destination.hpp‎

Lines changed: 101 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,110 @@
88
#define__NETWORK_MESSAGE_DIRECTIVES_DESTINATION_HPP__
99

1010
#include<boost/network/traits/string.hpp>
11+
#include<boost/network/support/is_async.hpp>
12+
#include<boost/network/support/is_sync.hpp>
13+
#include<boost/type_traits/is_same.hpp>
14+
#include<boost/variant/variant.hpp>
15+
#include<boost/variant/apply_visitor.hpp>
16+
#include<boost/variant/static_visitor.hpp>
17+
#include<boost/mpl/if.hpp>
18+
#include<boost/mpl/or.hpp>
1119

12-
13-
/** destination.hpp
14-
*
15-
* Defines the types involved and the semantics of adding
16-
* destination information into message objects.
17-
*
18-
* WARNING: DO NOT INCLUDE THIS HEADER DIRECTLY. THIS REQUIRES
19-
* TYPES TO BE DEFINED FROM EARLIER FILES THAT INCLUDE THIS
20-
* HEADER.
21-
*/
2220
namespaceboost {namespacenetwork {
23-
24-
namespaceimpl {
25-
template<classT>
26-
structdestination_directive {
27-
28-
explicitdestination_directive (T destination)
29-
: _destination(destination)
30-
{ };
31-
32-
template<
33-
classMessageTag
34-
>
35-
voidoperator() (basic_message<MessageTag> & msg)const {
36-
msg.destination() = _destination;
37-
};
38-
39-
private:
40-
41-
T _destination;
42-
};
43-
}// namespace impl
44-
45-
46-
inline
47-
impl::destination_directive<std::string>
48-
destination(std::string destination_) {
49-
return impl::destination_directive<std::string>(destination_);
50-
}
51-
52-
inline
53-
impl::destination_directive<std::wstring>
54-
destination(std::wstring destination_) {
55-
return impl::destination_directive<std::wstring>(destination_);
56-
}
21+
22+
namespacetraits {
23+
24+
template<classTag>
25+
structunsupported_tag;
26+
27+
template<classMessage>
28+
structdestination
29+
: mpl::if_<
30+
is_async<typename Message::tag>,
31+
boost::shared_future<typename string<typename Message::tag>::type>,
32+
typename mpl::if_<
33+
mpl::or_<
34+
is_sync<typename Message::tag>,
35+
is_same<typename Message::tag, tags::default_string>,
36+
is_same<typename Message::tag, tags::default_wstring>
37+
>,
38+
typename string<typename Message::tag>::type,
39+
unsupported_tag<typename Message::tag>
40+
>::type
41+
>
42+
{};
43+
44+
}// namespace traits
45+
46+
namespaceimpl {
47+
48+
structdestination_directive {
49+
boost::variant<
50+
string<tags::default_string>::type,
51+
string<tags::default_wstring>::type,
52+
boost::shared_future<string<tags::default_string>::type>,
53+
boost::shared_future<string<tags::default_wstring>::type>
54+
> destination_;
55+
56+
destination_directive(string<tags::default_string>::typeconst & destination)
57+
: destination_(destination) {}
58+
destination_directive(string<tags::default_wstring>::typeconst & destination)
59+
: destination_(destination) {}
60+
destination_directive(boost::shared_future<string<tags::default_string>::type>const & destination)
61+
: destination_(destination) {}
62+
destination_directive(boost::shared_future<string<tags::default_wstring>::type>const & destination)
63+
: destination_(destination) {}
64+
65+
destination_directive(destination_directiveconst & other)
66+
: destination_(other.destination_) {}
67+
68+
template<classTag>
69+
structvalue :
70+
mpl::if_<
71+
is_async<Tag>,
72+
boost::shared_future<typename string<Tag>::type>,
73+
typename mpl::if_<
74+
mpl::or_<
75+
is_sync<Tag>,
76+
is_same<Tag, tags::default_string>,
77+
is_same<Tag, tags::default_wstring>
78+
>,
79+
typename string<Tag>::type,
80+
unsupported_tag<Tag>
81+
>::type
82+
>
83+
{};
84+
85+
template<classMessage>
86+
structdestination_visitor : boost::static_visitor<> {
87+
Messageconst & message_;
88+
destination_visitor(Messageconst & message)
89+
: message_(message) {}
90+
voidoperator()(typename value<typename Message::tag>::typeconst & destination)const {
91+
message_.destination(destination);
92+
}
93+
template<classT>voidoperator() (Tconst &)const {
94+
// FIXME -- fail here!
95+
}
96+
};
97+
98+
template<classTag,template<class>classMessage>
99+
voidoperator()(Message<Tag>const & message)const {
100+
apply_visitor(destination_visitor<Message<Tag> >(message), destination_);
101+
}
102+
};
103+
104+
}// namespace impl
105+
106+
template<classT>
107+
inline impl::destination_directiveconst
108+
destination(Tconst & destination_) {
109+
returnimpl::destination_directive(destination_);
110+
}
111+
57112
}// namespace network
58-
}// namespace boost
59113

114+
}// namespace boost
115+
60116

61117
#endif// __NETWORK_MESSAGE_DIRECTIVES_DESTINATION_HPP__

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp