network_v4.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // ip/impl/network_v4.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_IP_IMPL_NETWORK_V4_HPP
  12. #define 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(ASIO_NO_IOSTREAM)
  17. #include "asio/detail/throw_error.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace ip {
  21. template <typename Elem, typename Traits>
  22. std::basic_ostream<Elem, Traits>& operator<<(
  23. std::basic_ostream<Elem, Traits>& os, const network_v4& addr)
  24. {
  25. asio::error_code ec;
  26. std::string s = addr.to_string(ec);
  27. if (ec)
  28. {
  29. if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
  30. asio::detail::throw_error(ec);
  31. else
  32. os.setstate(std::basic_ostream<Elem, Traits>::failbit);
  33. }
  34. else
  35. for (std::string::iterator i = s.begin(); i != s.end(); ++i)
  36. os << os.widen(*i);
  37. return os;
  38. }
  39. } // namespace ip
  40. } // namespace asio
  41. #include "asio/detail/pop_options.hpp"
  42. #endif // !defined(ASIO_NO_IOSTREAM)
  43. #endif // ASIO_IP_IMPL_NETWORK_V4_HPP