network_v4.hpp 1.4 KB

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