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

Commit25a41e4

Browse files
committed
Re-writing directives to use BOOST_NETWORK_STRING_DIRECTIVE preprocessor macro.
1 parent06b891e commit25a41e4

File tree

10 files changed

+46
-372
lines changed

10 files changed

+46
-372
lines changed

‎boost/network/message/directives.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
/** Include all the various directive headers.
1111
*/
1212

13+
#include<boost/network/message/directives/detail/string_directive.hpp>
1314
#include<boost/network/message/directives/header.hpp>
14-
#include<boost/network/message/directives/body.hpp>
15-
#include<boost/network/message/directives/source.hpp>
16-
#include<boost/network/message/directives/destination.hpp>
1715
#include<boost/network/message/directives/remove_header.hpp>
1816

1917
namespaceboost {namespacenetwork {
@@ -25,6 +23,10 @@ namespace boost { namespace network {
2523
return message_;
2624
}
2725

26+
BOOST_NETWORK_STRING_DIRECTIVE(source, source_, message.source(source_));
27+
BOOST_NETWORK_STRING_DIRECTIVE(destination, destination_, message.destination(destination_));
28+
BOOST_NETWORK_STRING_DIRECTIVE(body, body_, message.body(body_));
29+
2830
}// namespace network
2931

3032
}// namespace boost

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include<boost/variant/static_visitor.hpp>
1313
#include<boost/mpl/if.hpp>
1414
#include<boost/mpl/or.hpp>
15+
#include<boost/network/message/directives/detail/string_value.hpp>
1516

1617
namespaceboost {namespacenetwork {namespacedetail {
1718

@@ -23,30 +24,17 @@ namespace boost { namespace network { namespace detail {
2324
*
2425
* A typical directive implementation of the visitor will take a reference
2526
* to a message as the constructor parameter and then performs operations
26-
* on that message. An example implementation of a directive base is given
27-
* below:
27+
* on that message.
2828
*
29-
* struct foo_directive_base {
30-
* template <class Message>
31-
* struct string_visitor : boost::static_visitor<> {
32-
* Message const & message_;
33-
* string_visitor(Message const & message)
34-
* : message_(message) {}
29+
*To create your own string directive, you can use the preprocessor macro
30+
*BOOST_NETWORK_STRING_DIRECTIVE which takes three parameters: the name of
31+
*the directive, a name for the variable to use in the directive visitor,
32+
*and the body to be implemented in the visitor. An example directive for
33+
*setting the source of a message would look something like this given the
34+
*BOOST_NETWORK_STRING_DIRECTIVE macro:
3535
*
36-
* void operator()(
37-
* typename detail::string_value<typename Message::tag>::type
38-
* const & foo)
39-
* const {
40-
* // do something to message_ here.
41-
* }
36+
* BOOST_NETWORK_STRING_DIRECTIVE(source, source_, message.source(source_));
4237
*
43-
* template <class T> void operator()(T const &) const {
44-
* // fail at runtime?
45-
* }
46-
* };
47-
* };
48-
*
49-
* TODO -- distill this pattern into a preprocessor macro.
5038
*/
5139
template<classBase>
5240
structstring_directive :publicBase {
@@ -75,6 +63,31 @@ namespace boost { namespace network { namespace detail {
7563
}
7664
};
7765

66+
#defineBOOST_NETWORK_STRING_DIRECTIVE(name, value, body) \
67+
structname##_directive_base { \
68+
template<classMessage> \
69+
structstring_visitor : boost::static_visitor<> { \
70+
Messageconst & message; \
71+
explicitstring_visitor(Messageconst & message) : \
72+
message(message) {} \
73+
voidoperator()( \
74+
typename boost::network::detail::string_value< \
75+
typename Message::tag \
76+
>::typeconst & value \
77+
)const { \
78+
body; \
79+
} \
80+
template<classT>voidoperator()(Tconst &)const { \
81+
} \
82+
}; \
83+
}; \
84+
typedef boost::network::detail::string_directive<name##_directive_base> \
85+
name##_directive; \
86+
template<classT>inline name##_directiveconst \
87+
name (Tconst & input) { \
88+
return name##_directive(input); \
89+
}
90+
7891
}/* detail*/
7992

8093
}/* network*/

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

‎boost/network/protocol/http/message/directives/status_message.hpp

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,12 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/tags.hpp>
11-
#include<boost/network/support/is_async.hpp>
12-
#include<boost/network/support/is_sync.hpp>
13-
#include<boost/variant/variant.hpp>
14-
#include<boost/variant/static_visitor.hpp>
15-
#include<boost/variant/apply_visitor.hpp>
11+
#include<boost/network/message/directives/detail/string_directive.hpp>
1612

1713
namespaceboost {namespacenetwork {namespacehttp {
1814

19-
template<classTag>
20-
structbasic_response;
21-
22-
namespaceimpl {
23-
24-
structstatus_message_directive {
25-
26-
boost::variant<
27-
string<tags::default_string>::type,
28-
string<tags::default_wstring>::type,
29-
boost::shared_future<string<tags::default_string>::type>,
30-
boost::shared_future<string<tags::default_wstring>::type>
31-
> status_message_;
32-
33-
status_message_directive(string<tags::default_string>::typeconst & status_message)
34-
: status_message_(status_message) {}
35-
36-
status_message_directive(string<tags::default_wstring>::typeconst & status_message)
37-
: status_message_(status_message) {}
38-
39-
status_message_directive(boost::shared_future<string<tags::default_string>::type>const & status_message)
40-
: status_message_(status_message) {}
41-
42-
status_message_directive(boost::shared_future<string<tags::default_wstring>::type>const & status_message)
43-
: status_message_(status_message) {}
44-
45-
status_message_directive(status_message_directiveconst & other)
46-
: status_message_(other.status_message_) {}
47-
48-
template<classTag>
49-
structunsupported_tag;
50-
51-
template<classTag>
52-
structvalue :
53-
mpl::if_<
54-
is_async<Tag>,
55-
boost::shared_future<typename string<Tag>::type>,
56-
typename mpl::if_<
57-
is_sync<Tag>,
58-
typename string<Tag>::type,
59-
unsupported_tag<Tag>
60-
>::type
61-
>
62-
{};
63-
64-
template<classTag>
65-
structstatus_message_visitor : boost::static_visitor<> {
66-
basic_response<Tag>const & response;
67-
status_message_visitor(basic_response<Tag>const & response)
68-
: response(response) {}
69-
voidoperator() (typename value<Tag>::typeconst & status_message)const {
70-
response.status_message(status_message);
71-
}
72-
template<classT>
73-
voidoperator() (Tconst &)const {
74-
// FIXME fail here!
75-
}
76-
};
77-
78-
template<classTag>
79-
basic_response<Tag>const &operator() (basic_response<Tag>const & response)const {
80-
apply_visitor(status_message_visitor<Tag>(response), status_message_);
81-
return response;
82-
}
83-
84-
};
85-
86-
}// namespace impl
87-
88-
template<classT>
89-
inline impl::status_message_directiveconststatus_message(Tconst & status_message_) {
90-
returnimpl::status_message_directive(status_message_);
91-
}
15+
BOOST_NETWORK_STRING_DIRECTIVE(status_message, status_message_,
16+
message.status_message(status_message_));
9217

9318
}// namespace http
9419

‎boost/network/protocol/http/message/directives/uri.hpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,11 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/tags.hpp>
11-
#include<boost/network/traits/string.hpp>
11+
#include<boost/network/message/directives/detail/string_directive.hpp>
1212

1313
namespaceboost {namespacenetwork {namespacehttp {
1414

15-
template<classTag>
16-
classbasic_request;
17-
18-
namespaceimpl {
19-
20-
template<classTag>
21-
structuri_directive {
22-
23-
typedeftypename string<Tag>::type string_type;
24-
25-
string_type uri_;
26-
27-
explicituri_directive(string_typeconst & uri)
28-
: uri_(uri) {}
29-
30-
uri_directive(uri_directiveconst & other)
31-
: uri_(other.uri_) {}
32-
33-
template<classT> basic_request<T>const &operator() (basic_request<T>const & request)const {
34-
request.uri(uri_);
35-
return request;
36-
}
37-
38-
};
39-
40-
}// namespace impl
41-
42-
inline impl::uri_directive<tags::default_>consturi(string<tags::default_>::typeconst & uri_) {
43-
return impl::uri_directive<tags::default_>(uri_);
44-
}
15+
BOOST_NETWORK_STRING_DIRECTIVE(uri, uri_, message.uri(uri_));
4516

4617
}// namespace http
4718

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp