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.

220 lines
4.6KB

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