Skip to content

Commit 788cb16

Browse files
committed
Turning the wrapper definition into a preprocessor macro "BOOST_NETWORK_DEFINE_HTTP_WRAPPER".
1 parent 301269f commit 788cb16

File tree

4 files changed

+78
-99
lines changed

4 files changed

+78
-99
lines changed

boost/network/protocol/http/message/wrappers/body.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <boost/network/protocol/http/response_concept.hpp>
10-
#include <boost/network/protocol/http/request_concept.hpp>
11-
#include <boost/concept/requires.hpp>
9+
#include <boost/network/protocol/http/message/wrappers/helper.hpp>
1210

1311
namespace boost { namespace network { namespace http {
1412

boost/network/protocol/http/message/wrappers/destination.hpp

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <boost/network/protocol/http/response_concept.hpp>
10-
#include <boost/network/protocol/http/request_concept.hpp>
11-
#include <boost/concept/requires.hpp>
9+
#include <boost/network/protocol/http/message/wrappers/helper.hpp>
1210

1311
namespace boost { namespace network { namespace http {
1412

@@ -18,38 +16,7 @@ namespace boost { namespace network { namespace http {
1816
template <class Tag>
1917
struct basic_request;
2018

21-
namespace impl {
22-
23-
template <class Message>
24-
struct destination_wrapper {
25-
typedef typename string<typename Message::tag>::type string_type;
26-
Message const & message_;
27-
destination_wrapper(Message const & message)
28-
: message_(message) {}
29-
destination_wrapper(destination_wrapper const & other)
30-
: message_(other.message_) {}
31-
operator string_type const () {
32-
return message_.source();
33-
}
34-
};
35-
36-
} // namespace impl
37-
38-
template <class Tag>
39-
inline
40-
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
41-
(impl::destination_wrapper<basic_response<Tag> > const))
42-
destination(basic_response<Tag> const & message) {
43-
return impl::destination_wrapper<basic_response<Tag> >(message);
44-
}
45-
46-
template <class Tag>
47-
inline
48-
BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)),
49-
(impl::destination_wrapper<basic_request<Tag> > const))
50-
destination(basic_request<Tag> const & message) {
51-
return impl::destination_wrapper<basic_request<Tag> >(message);
52-
}
19+
BOOST_NETWORK_DEFINE_HTTP_WRAPPER(destination, destination);
5320

5421
} // namespace http
5522

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_HELPER_20101013
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_HELPER_20101013
3+
4+
// Copyright 2010 (c) Dean Michael Berris
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <boost/network/protocol/http/response_concept.hpp>
10+
#include <boost/network/protocol/http/request_concept.hpp>
11+
#include <boost/mpl/if.hpp>
12+
#include <boost/concept/requires.hpp>
13+
14+
#ifndef BOOST_NETWORK_DEFINE_HTTP_WRAPPER
15+
#define BOOST_NETWORK_DEFINE_HTTP_WRAPPER(name, accessor) \
16+
struct name##_pod_accessor { \
17+
protected: \
18+
template <class Message> \
19+
typename Message::string_type const & \
20+
get_value(Message const & message) const { \
21+
return message.accessor; \
22+
} \
23+
}; \
24+
\
25+
struct name##_member_accessor { \
26+
protected: \
27+
template <class Message> \
28+
typename Message::string_type \
29+
get_value(Message const & message) const { \
30+
return message.accessor(); \
31+
} \
32+
}; \
33+
\
34+
template <class Tag> \
35+
struct name##_wrapper_impl : \
36+
mpl::if_< \
37+
is_base_of<tags::pod, Tag>, \
38+
name##_pod_accessor, \
39+
name##_member_accessor \
40+
> \
41+
{}; \
42+
\
43+
template <class Message> \
44+
struct name##_wrapper : \
45+
name##_wrapper_impl<typename Message::tag>::type { \
46+
typedef typename string<typename Message::tag>::type \
47+
string_type; \
48+
Message const & message_; \
49+
name##_wrapper(Message const & message) \
50+
: message_(message) {} \
51+
name##_wrapper(name##_wrapper const & other) \
52+
: message_(other.message_) {} \
53+
operator string_type () { \
54+
return this->get_value(message_); \
55+
} \
56+
}; \
57+
\
58+
template <class Tag> \
59+
inline BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)), \
60+
(name##_wrapper<basic_response<Tag> > const)) \
61+
name (basic_response<Tag> const & message) { \
62+
return name##_wrapper<basic_response<Tag> >(message); \
63+
} \
64+
\
65+
template <class Tag> \
66+
inline BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)), \
67+
(name##_wrapper<basic_request<Tag> > const)) \
68+
name (basic_request<Tag> const & message) { \
69+
return name##_wrapper<basic_request<Tag> >(message); \
70+
}
71+
#endif /* BOOST_NETWORK_DEFINE_HTTP_WRAPPER */
72+
73+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_HELPER_20101013 */
74+

boost/network/protocol/http/message/wrappers/source.hpp

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <boost/network/protocol/http/response_concept.hpp>
10-
#include <boost/network/protocol/http/request_concept.hpp>
11-
#include <boost/mpl/if.hpp>
12-
#include <boost/concept/requires.hpp>
9+
#include <boost/network/protocol/http/message/wrappers/helper.hpp>
1310

1411
namespace boost { namespace network { namespace http {
1512

@@ -19,63 +16,6 @@ namespace boost { namespace network { namespace http {
1916
template <class Tag>
2017
struct basic_request;
2118

22-
#define BOOST_NETWORK_DEFINE_HTTP_WRAPPER(name, accessor) \
23-
struct name##_pod_accessor { \
24-
protected: \
25-
template <class Message> \
26-
typename Message::string_type const & \
27-
get_value(Message const & message) const { \
28-
return message.accessor; \
29-
} \
30-
}; \
31-
\
32-
struct name##_member_accessor { \
33-
protected: \
34-
template <class Message> \
35-
typename Message::string_type \
36-
get_value(Message const & message) const { \
37-
return message.accessor(); \
38-
} \
39-
}; \
40-
\
41-
template <class Tag> \
42-
struct name##_wrapper_impl : \
43-
mpl::if_< \
44-
is_base_of<tags::pod, Tag>, \
45-
name##_pod_accessor, \
46-
name##_member_accessor \
47-
> \
48-
{}; \
49-
\
50-
template <class Message> \
51-
struct name##_wrapper : \
52-
name##_wrapper_impl<typename Message::tag>::type { \
53-
typedef typename string<typename Message::tag>::type \
54-
string_type; \
55-
Message const & message_; \
56-
name##_wrapper(Message const & message) \
57-
: message_(message) {} \
58-
name##_wrapper(name##_wrapper const & other) \
59-
: message_(other.message_) {} \
60-
operator string_type const () { \
61-
return this->get_value(message_); \
62-
} \
63-
}; \
64-
\
65-
template <class Tag> \
66-
inline BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)), \
67-
(name##_wrapper<basic_response<Tag> > const)) \
68-
name (basic_response<Tag> const & message) { \
69-
return name##_wrapper<basic_response<Tag> >(message); \
70-
} \
71-
\
72-
template <class Tag> \
73-
inline BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)), \
74-
(name##_wrapper<basic_request<Tag> > const)) \
75-
name (basic_request<Tag> const & message) { \
76-
return name##_wrapper<basic_request<Tag> >(message); \
77-
}
78-
7919
BOOST_NETWORK_DEFINE_HTTP_WRAPPER(source, source);
8020

8121
} // namespace http

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy