Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

address.ipp 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // ip/impl/address.ipp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. #ifndef ASIO_IP_IMPL_ADDRESS_IPP
  11. #define ASIO_IP_IMPL_ADDRESS_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <typeinfo>
  17. #include "asio/detail/throw_error.hpp"
  18. #include "asio/detail/throw_exception.hpp"
  19. #include "asio/error.hpp"
  20. #include "asio/ip/address.hpp"
  21. #include "asio/ip/bad_address_cast.hpp"
  22. #include "asio/system_error.hpp"
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace ip {
  26. address::address() ASIO_NOEXCEPT
  27. : type_(ipv4),
  28. ipv4_address_(),
  29. ipv6_address_()
  30. {
  31. }
  32. address::address(
  33. const asio::ip::address_v4& ipv4_address) ASIO_NOEXCEPT
  34. : type_(ipv4),
  35. ipv4_address_(ipv4_address),
  36. ipv6_address_()
  37. {
  38. }
  39. address::address(
  40. const asio::ip::address_v6& ipv6_address) ASIO_NOEXCEPT
  41. : type_(ipv6),
  42. ipv4_address_(),
  43. ipv6_address_(ipv6_address)
  44. {
  45. }
  46. address::address(const address& other) ASIO_NOEXCEPT
  47. : type_(other.type_),
  48. ipv4_address_(other.ipv4_address_),
  49. ipv6_address_(other.ipv6_address_)
  50. {
  51. }
  52. #if defined(ASIO_HAS_MOVE)
  53. address::address(address&& other) ASIO_NOEXCEPT
  54. : type_(other.type_),
  55. ipv4_address_(other.ipv4_address_),
  56. ipv6_address_(other.ipv6_address_)
  57. {
  58. }
  59. #endif // defined(ASIO_HAS_MOVE)
  60. address& address::operator=(const address& other) ASIO_NOEXCEPT
  61. {
  62. type_ = other.type_;
  63. ipv4_address_ = other.ipv4_address_;
  64. ipv6_address_ = other.ipv6_address_;
  65. return *this;
  66. }
  67. #if defined(ASIO_HAS_MOVE)
  68. address& address::operator=(address&& other) ASIO_NOEXCEPT
  69. {
  70. type_ = other.type_;
  71. ipv4_address_ = other.ipv4_address_;
  72. ipv6_address_ = other.ipv6_address_;
  73. return *this;
  74. }
  75. #endif // defined(ASIO_HAS_MOVE)
  76. address& address::operator=(
  77. const asio::ip::address_v4& ipv4_address) ASIO_NOEXCEPT
  78. {
  79. type_ = ipv4;
  80. ipv4_address_ = ipv4_address;
  81. ipv6_address_ = asio::ip::address_v6();
  82. return *this;
  83. }
  84. address& address::operator=(
  85. const asio::ip::address_v6& ipv6_address) ASIO_NOEXCEPT
  86. {
  87. type_ = ipv6;
  88. ipv4_address_ = asio::ip::address_v4();
  89. ipv6_address_ = ipv6_address;
  90. return *this;
  91. }
  92. address make_address(const char* str)
  93. {
  94. asio::error_code ec;
  95. address addr = make_address(str, ec);
  96. asio::detail::throw_error(ec);
  97. return addr;
  98. }
  99. address make_address(const char* str,
  100. asio::error_code& ec) ASIO_NOEXCEPT
  101. {
  102. asio::ip::address_v6 ipv6_address =
  103. asio::ip::make_address_v6(str, ec);
  104. if (!ec)
  105. return address(ipv6_address);
  106. asio::ip::address_v4 ipv4_address =
  107. asio::ip::make_address_v4(str, ec);
  108. if (!ec)
  109. return address(ipv4_address);
  110. return address();
  111. }
  112. address make_address(const std::string& str)
  113. {
  114. return make_address(str.c_str());
  115. }
  116. address make_address(const std::string& str,
  117. asio::error_code& ec) ASIO_NOEXCEPT
  118. {
  119. return make_address(str.c_str(), ec);
  120. }
  121. #if defined(ASIO_HAS_STRING_VIEW)
  122. address make_address(string_view str)
  123. {
  124. return make_address(static_cast<std::string>(str));
  125. }
  126. address make_address(string_view str,
  127. asio::error_code& ec) ASIO_NOEXCEPT
  128. {
  129. return make_address(static_cast<std::string>(str), ec);
  130. }
  131. #endif // defined(ASIO_HAS_STRING_VIEW)
  132. asio::ip::address_v4 address::to_v4() const
  133. {
  134. if (type_ != ipv4)
  135. {
  136. bad_address_cast ex;
  137. asio::detail::throw_exception(ex);
  138. }
  139. return ipv4_address_;
  140. }
  141. asio::ip::address_v6 address::to_v6() const
  142. {
  143. if (type_ != ipv6)
  144. {
  145. bad_address_cast ex;
  146. asio::detail::throw_exception(ex);
  147. }
  148. return ipv6_address_;
  149. }
  150. std::string address::to_string() const
  151. {
  152. if (type_ == ipv6)
  153. return ipv6_address_.to_string();
  154. return ipv4_address_.to_string();
  155. }
  156. #if !defined(ASIO_NO_DEPRECATED)
  157. std::string address::to_string(asio::error_code& ec) const
  158. {
  159. if (type_ == ipv6)
  160. return ipv6_address_.to_string(ec);
  161. return ipv4_address_.to_string(ec);
  162. }
  163. #endif // !defined(ASIO_NO_DEPRECATED)
  164. bool address::is_loopback() const ASIO_NOEXCEPT
  165. {
  166. return (type_ == ipv4)
  167. ? ipv4_address_.is_loopback()
  168. : ipv6_address_.is_loopback();
  169. }
  170. bool address::is_unspecified() const ASIO_NOEXCEPT
  171. {
  172. return (type_ == ipv4)
  173. ? ipv4_address_.is_unspecified()
  174. : ipv6_address_.is_unspecified();
  175. }
  176. bool address::is_multicast() const ASIO_NOEXCEPT
  177. {
  178. return (type_ == ipv4)
  179. ? ipv4_address_.is_multicast()
  180. : ipv6_address_.is_multicast();
  181. }
  182. bool operator==(const address& a1, const address& a2) ASIO_NOEXCEPT
  183. {
  184. if (a1.type_ != a2.type_)
  185. return false;
  186. if (a1.type_ == address::ipv6)
  187. return a1.ipv6_address_ == a2.ipv6_address_;
  188. return a1.ipv4_address_ == a2.ipv4_address_;
  189. }
  190. bool operator<(const address& a1, const address& a2) ASIO_NOEXCEPT
  191. {
  192. if (a1.type_ < a2.type_)
  193. return true;
  194. if (a1.type_ > a2.type_)
  195. return false;
  196. if (a1.type_ == address::ipv6)
  197. return a1.ipv6_address_ < a2.ipv6_address_;
  198. return a1.ipv4_address_ < a2.ipv4_address_;
  199. }
  200. } // namespace ip
  201. } // namespace asio
  202. #include "asio/detail/pop_options.hpp"
  203. #endif // ASIO_IP_IMPL_ADDRESS_IPP