1 | // |
2 | // ip/impl/basic_endpoint.hpp |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4 | // |
5 | // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
9 | // |
10 | |
11 | #ifndef BOOST_ASIO_IP_IMPL_BASIC_ENDPOINT_HPP |
12 | #define BOOST_ASIO_IP_IMPL_BASIC_ENDPOINT_HPP |
13 | |
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
15 | # pragma once |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) |
17 | |
18 | #if !defined(BOOST_ASIO_NO_IOSTREAM) |
19 | |
20 | #include <boost/asio/detail/throw_error.hpp> |
21 | |
22 | #include <boost/asio/detail/push_options.hpp> |
23 | |
24 | namespace boost { |
25 | namespace asio { |
26 | namespace ip { |
27 | |
28 | template <typename Elem, typename Traits, typename InternetProtocol> |
29 | std::basic_ostream<Elem, Traits>& operator<<( |
30 | std::basic_ostream<Elem, Traits>& os, |
31 | const basic_endpoint<InternetProtocol>& endpoint) |
32 | { |
33 | boost::asio::ip::detail::endpoint tmp_ep(endpoint.address(), endpoint.port()); |
34 | boost::system::error_code ec; |
35 | std::string s = tmp_ep.to_string(ec); |
36 | if (ec) |
37 | { |
38 | if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit) |
39 | boost::asio::detail::throw_error(err: ec); |
40 | else |
41 | os.setstate(std::basic_ostream<Elem, Traits>::failbit); |
42 | } |
43 | else |
44 | for (std::string::iterator i = s.begin(); i != s.end(); ++i) |
45 | os << os.widen(*i); |
46 | return os; |
47 | } |
48 | |
49 | } // namespace ip |
50 | } // namespace asio |
51 | } // namespace boost |
52 | |
53 | #include <boost/asio/detail/pop_options.hpp> |
54 | |
55 | #endif // !defined(BOOST_ASIO_NO_IOSTREAM) |
56 | |
57 | #endif // BOOST_ASIO_IP_IMPL_BASIC_ENDPOINT_HPP |
58 | |