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

Commit9dc07de

Browse files
author
mikhail_beris
committed
Implement to_upper transformer and basic transformation infrastructure.
1 parent3bf7c60 commit9dc07de

File tree

6 files changed

+160
-0
lines changed

6 files changed

+160
-0
lines changed

‎boost/network/message.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,8 @@ namespace boost { namespace network {
8080
#include<boost/network/message/wrappers.hpp>
8181
// pull in wrappers header file
8282

83+
#include<boost/network/message/transformers.hpp>
84+
// pull in transformer header file
85+
8386
#endif// __NETWORK_MESSAGE_HPP__
8487

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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_TRANSFORMERS_HPP__
8+
#define__NETWORK_MESSAGE_TRANSFORMERS_HPP__
9+
10+
/** transformers.hpp
11+
*
12+
* Pulls in all the transformers files.
13+
*/
14+
#include<boost/network/message/transformers/selectors.hpp>
15+
#include<boost/network/message/transformers/to_upper.hpp>
16+
17+
namespaceboost {namespacenetwork {
18+
namespaceimpl {
19+
template<classAlgorithm,classSelector>
20+
structget_real_algorithm {
21+
typedeftypename Algorithm::type<Selector> type;
22+
};
23+
24+
template<classAlgorithm,classSelector>
25+
structtransform_impl :publicget_real_algorithm<Algorithm, Selector>::type { };
26+
};// namspace impl
27+
28+
template<classAlgorithm,classSelector>
29+
inline impl::transform_impl<Algorithm, Selector>
30+
transform(Algorithm, Selector) {
31+
return impl::transform_impl<Algorithm, Selector>();
32+
};
33+
34+
template<classTag,classAlgorithm,classSelector>
35+
inline basic_message<Tag> &
36+
operator<< (basic_message<Tag> & msg_,
37+
impl::transform_impl<Algorithm, Selector>
38+
const & transformer) {
39+
transformer(msg_);
40+
return msg_;
41+
};
42+
43+
};// namespace network
44+
45+
};// namespace boost
46+
47+
#endif// __NETWORK_MESSAGE_TRANSFORMERS_HPP__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_TRANSFORMERS_SELECTORS_HPP__
8+
#define__NETWORK_MESSAGE_TRANSFORMERS_SELECTORS_HPP__
9+
10+
namespaceboost {namespacenetwork {
11+
namespaceselectors {
12+
structsource_selector { };
13+
structdestination_selector { };
14+
};// namespace selectors
15+
16+
extern selectors::source_selector source_;
17+
extern selectors::destination_selector destination_;
18+
19+
};// namespace network
20+
21+
};// namespace boost
22+
23+
#endif// __NETWORK_MESSAGE_TRANSFORMERS_SELECTORS_HPP__
24+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_TRANSFORMERS_TO_UPPER_HPP__
8+
#define__NETWORK_MESSAGE_TRANSFORMERS_TO_UPPER_HPP__
9+
10+
#include<boost/algorithm/string.hpp>
11+
12+
/** to_upper.hpp
13+
*
14+
* Implements the to_upper transformer. This applies
15+
* the to_upper string algorithm to a string, which
16+
* is selected by the appropriate selector.
17+
*
18+
* This defines a type, to be applied using template
19+
* metaprogramming on the selected string target.
20+
*/
21+
namespaceboost {namespacenetwork {
22+
23+
namespaceimpl {
24+
25+
template<classSelector>
26+
structto_upper_transformer { };
27+
28+
template<>
29+
structto_upper_transformer<selectors::source_selector> {
30+
template<classTag>
31+
voidoperator() (basic_message<Tag> & message_)const {
32+
boost::to_upper(message_.source());
33+
};
34+
35+
protected:
36+
~to_upper_transformer() { };
37+
};
38+
39+
template<>
40+
structto_upper_transformer<selectors::destination_selector> {
41+
template<classTag>
42+
voidoperator() (basic_message<Tag> & message_)const {
43+
boost::to_upper(message_.destination());
44+
};
45+
46+
protected:
47+
~to_upper_transformer() { };
48+
};
49+
50+
};// namespace impl
51+
52+
structto_upper_placeholder {
53+
template<classSelector>
54+
structtype :publicimpl::to_upper_transformer<Selector> { };
55+
} ;
56+
57+
extern to_upper_placeholder to_upper_;
58+
59+
};// namespace network
60+
61+
};// namespace boost
62+
63+
#endif// __NETWORK_MESSAGE_TRANSFORMERS_TO_UPPER_HPP__
64+

‎libs/network/test/Jamfile.v2‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ project network_test :
1212
;
1313

1414
unit-test message_test : message_test.cpp ;
15+
16+
unit-test message_transform_test : message_transform_test.cpp ;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
#defineBOOST_TEST_MODULE message test
8+
#include<boost/test/unit_test.hpp>
9+
#include<boost/network.hpp>
10+
#include<algorithm>
11+
12+
BOOST_AUTO_TEST_CASE ( message_transform_tolower ) {
13+
usingnamespaceboost::network;
14+
15+
message msg;
16+
msg <<source("me");
17+
BOOST_CHECK_EQUAL (source(msg),"me" );
18+
msg <<transform(to_upper_, source_);
19+
BOOST_CHECK_EQUAL (source(msg),"ME" );
20+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp