1 #ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618 2 #define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618 3 4 // Copyright 2010, 2014 Dean Michael Berris <dberris@google.com> 5 // Copyright 2010 (c) Sinefunc, Inc. 6 // Copyright 2014 Google, Inc. 7 // Copyright 2014 Jussi Lyytinen 8 // Distributed under the Boost Software License, Version 1.0. 9 // (See accompanying file LICENSE_1_0.txt or copy at 10 // http://www.boost.org/LICENSE_1_0.txt) 11 12 #include <cstdint> 13 #include <boost/network/uri/accessors.hpp> 14 #include <boost/optional.hpp> 15 #include <boost/version.hpp> 16 17 namespace boost { 18 namespace network { 19 namespace http { 20 21 template <class Tag> 22 struct basic_request; 23 24 namespace impl { 25 26 template <class Tag> 27 struct port_wrapper { 28 basic_request<Tag> const& message_; 29 port_wrapperboost::network::http::impl::port_wrapper30 explicit port_wrapper(basic_request<Tag> const& message) : message_(message) {} 31 32 typedef typename basic_request<Tag>::port_type port_type; 33 operator port_typeboost::network::http::impl::port_wrapper34 operator port_type() const { return message_.port(); } 35 36 #if (_MSC_VER >= 1600 && BOOST_VERSION > 105500) 37 // Because of a breaking change in Boost 1.56 to boost::optional, implicit 38 // conversions no longer work correctly with MSVC. The conversion therefore 39 // has to be done explicitly with as_optional(). as_optionalboost::network::http::impl::port_wrapper40 boost::optional<std::uint16_t> as_optional() const { 41 return uri::port_us(message_.uri()); 42 } 43 #else operator boost::optional<std::uint16_t>boost::network::http::impl::port_wrapper44 operator boost::optional<std::uint16_t>() const { 45 return uri::port_us(message_.uri()); 46 } 47 #endif 48 49 }; 50 51 } // namespace impl 52 53 template <class Tag> port(basic_request<Tag> const & request)54inline impl::port_wrapper<Tag> port(basic_request<Tag> const& request) { 55 return impl::port_wrapper<Tag>(request); 56 } 57 58 } // namespace http 59 } // namespace network 60 } // namespace boost 61 62 #endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618 63