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.

269 lines
7.5KB

  1. //
  2. // ip/address.hpp
  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_ADDRESS_HPP
  11. #define ASIO_IP_ADDRESS_HPP
  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 <string>
  17. #include "asio/detail/throw_exception.hpp"
  18. #include "asio/detail/string_view.hpp"
  19. #include "asio/detail/type_traits.hpp"
  20. #include "asio/error_code.hpp"
  21. #include "asio/ip/address_v4.hpp"
  22. #include "asio/ip/address_v6.hpp"
  23. #include "asio/ip/bad_address_cast.hpp"
  24. #if !defined(ASIO_NO_IOSTREAM)
  25. # include <iosfwd>
  26. #endif // !defined(ASIO_NO_IOSTREAM)
  27. #include "asio/detail/push_options.hpp"
  28. namespace asio {
  29. namespace ip {
  30. /// Implements version-independent IP addresses.
  31. /**
  32. * The asio::ip::address class provides the ability to use either IP
  33. * version 4 or version 6 addresses.
  34. *
  35. * @par Thread Safety
  36. * @e Distinct @e objects: Safe.@n
  37. * @e Shared @e objects: Unsafe.
  38. */
  39. class address
  40. {
  41. public:
  42. /// Default constructor.
  43. ASIO_DECL address() ASIO_NOEXCEPT;
  44. /// Construct an address from an IPv4 address.
  45. ASIO_DECL address(
  46. const asio::ip::address_v4& ipv4_address) ASIO_NOEXCEPT;
  47. /// Construct an address from an IPv6 address.
  48. ASIO_DECL address(
  49. const asio::ip::address_v6& ipv6_address) ASIO_NOEXCEPT;
  50. /// Copy constructor.
  51. ASIO_DECL address(const address& other) ASIO_NOEXCEPT;
  52. #if defined(ASIO_HAS_MOVE)
  53. /// Move constructor.
  54. ASIO_DECL address(address&& other) ASIO_NOEXCEPT;
  55. #endif // defined(ASIO_HAS_MOVE)
  56. /// Assign from another address.
  57. ASIO_DECL address& operator=(const address& other) ASIO_NOEXCEPT;
  58. #if defined(ASIO_HAS_MOVE)
  59. /// Move-assign from another address.
  60. ASIO_DECL address& operator=(address&& other) ASIO_NOEXCEPT;
  61. #endif // defined(ASIO_HAS_MOVE)
  62. /// Assign from an IPv4 address.
  63. ASIO_DECL address& operator=(
  64. const asio::ip::address_v4& ipv4_address) ASIO_NOEXCEPT;
  65. /// Assign from an IPv6 address.
  66. ASIO_DECL address& operator=(
  67. const asio::ip::address_v6& ipv6_address) ASIO_NOEXCEPT;
  68. /// Get whether the address is an IP version 4 address.
  69. bool is_v4() const ASIO_NOEXCEPT
  70. {
  71. return type_ == ipv4;
  72. }
  73. /// Get whether the address is an IP version 6 address.
  74. bool is_v6() const ASIO_NOEXCEPT
  75. {
  76. return type_ == ipv6;
  77. }
  78. /// Get the address as an IP version 4 address.
  79. ASIO_DECL asio::ip::address_v4 to_v4() const;
  80. /// Get the address as an IP version 6 address.
  81. ASIO_DECL asio::ip::address_v6 to_v6() const;
  82. /// Get the address as a string.
  83. ASIO_DECL std::string to_string() const;
  84. #if !defined(ASIO_NO_DEPRECATED)
  85. /// (Deprecated: Use other overload.) Get the address as a string.
  86. ASIO_DECL std::string to_string(asio::error_code& ec) const;
  87. /// (Deprecated: Use make_address().) Create an address from an IPv4 address
  88. /// string in dotted decimal form, or from an IPv6 address in hexadecimal
  89. /// notation.
  90. static address from_string(const char* str);
  91. /// (Deprecated: Use make_address().) Create an address from an IPv4 address
  92. /// string in dotted decimal form, or from an IPv6 address in hexadecimal
  93. /// notation.
  94. static address from_string(const char* str, asio::error_code& ec);
  95. /// (Deprecated: Use make_address().) Create an address from an IPv4 address
  96. /// string in dotted decimal form, or from an IPv6 address in hexadecimal
  97. /// notation.
  98. static address from_string(const std::string& str);
  99. /// (Deprecated: Use make_address().) Create an address from an IPv4 address
  100. /// string in dotted decimal form, or from an IPv6 address in hexadecimal
  101. /// notation.
  102. static address from_string(
  103. const std::string& str, asio::error_code& ec);
  104. #endif // !defined(ASIO_NO_DEPRECATED)
  105. /// Determine whether the address is a loopback address.
  106. ASIO_DECL bool is_loopback() const ASIO_NOEXCEPT;
  107. /// Determine whether the address is unspecified.
  108. ASIO_DECL bool is_unspecified() const ASIO_NOEXCEPT;
  109. /// Determine whether the address is a multicast address.
  110. ASIO_DECL bool is_multicast() const ASIO_NOEXCEPT;
  111. /// Compare two addresses for equality.
  112. ASIO_DECL friend bool operator==(const address& a1,
  113. const address& a2) ASIO_NOEXCEPT;
  114. /// Compare two addresses for inequality.
  115. friend bool operator!=(const address& a1,
  116. const address& a2) ASIO_NOEXCEPT
  117. {
  118. return !(a1 == a2);
  119. }
  120. /// Compare addresses for ordering.
  121. ASIO_DECL friend bool operator<(const address& a1,
  122. const address& a2) ASIO_NOEXCEPT;
  123. /// Compare addresses for ordering.
  124. friend bool operator>(const address& a1,
  125. const address& a2) ASIO_NOEXCEPT
  126. {
  127. return a2 < a1;
  128. }
  129. /// Compare addresses for ordering.
  130. friend bool operator<=(const address& a1,
  131. const address& a2) ASIO_NOEXCEPT
  132. {
  133. return !(a2 < a1);
  134. }
  135. /// Compare addresses for ordering.
  136. friend bool operator>=(const address& a1,
  137. const address& a2) ASIO_NOEXCEPT
  138. {
  139. return !(a1 < a2);
  140. }
  141. private:
  142. // The type of the address.
  143. enum { ipv4, ipv6 } type_;
  144. // The underlying IPv4 address.
  145. asio::ip::address_v4 ipv4_address_;
  146. // The underlying IPv6 address.
  147. asio::ip::address_v6 ipv6_address_;
  148. };
  149. /// Create an address from an IPv4 address string in dotted decimal form,
  150. /// or from an IPv6 address in hexadecimal notation.
  151. /**
  152. * @relates address
  153. */
  154. ASIO_DECL address make_address(const char* str);
  155. /// Create an address from an IPv4 address string in dotted decimal form,
  156. /// or from an IPv6 address in hexadecimal notation.
  157. /**
  158. * @relates address
  159. */
  160. ASIO_DECL address make_address(const char* str,
  161. asio::error_code& ec) ASIO_NOEXCEPT;
  162. /// Create an address from an IPv4 address string in dotted decimal form,
  163. /// or from an IPv6 address in hexadecimal notation.
  164. /**
  165. * @relates address
  166. */
  167. ASIO_DECL address make_address(const std::string& str);
  168. /// Create an address from an IPv4 address string in dotted decimal form,
  169. /// or from an IPv6 address in hexadecimal notation.
  170. /**
  171. * @relates address
  172. */
  173. ASIO_DECL address make_address(const std::string& str,
  174. asio::error_code& ec) ASIO_NOEXCEPT;
  175. #if defined(ASIO_HAS_STRING_VIEW) \
  176. || defined(GENERATING_DOCUMENTATION)
  177. /// Create an address from an IPv4 address string in dotted decimal form,
  178. /// or from an IPv6 address in hexadecimal notation.
  179. /**
  180. * @relates address
  181. */
  182. ASIO_DECL address make_address(string_view str);
  183. /// Create an address from an IPv4 address string in dotted decimal form,
  184. /// or from an IPv6 address in hexadecimal notation.
  185. /**
  186. * @relates address
  187. */
  188. ASIO_DECL address make_address(string_view str,
  189. asio::error_code& ec) ASIO_NOEXCEPT;
  190. #endif // defined(ASIO_HAS_STRING_VIEW)
  191. // || defined(GENERATING_DOCUMENTATION)
  192. #if !defined(ASIO_NO_IOSTREAM)
  193. /// Output an address as a string.
  194. /**
  195. * Used to output a human-readable string for a specified address.
  196. *
  197. * @param os The output stream to which the string will be written.
  198. *
  199. * @param addr The address to be written.
  200. *
  201. * @return The output stream.
  202. *
  203. * @relates asio::ip::address
  204. */
  205. template <typename Elem, typename Traits>
  206. std::basic_ostream<Elem, Traits>& operator<<(
  207. std::basic_ostream<Elem, Traits>& os, const address& addr);
  208. #endif // !defined(ASIO_NO_IOSTREAM)
  209. } // namespace ip
  210. } // namespace asio
  211. #include "asio/detail/pop_options.hpp"
  212. #include "asio/ip/impl/address.hpp"
  213. #if defined(ASIO_HEADER_ONLY)
  214. # include "asio/ip/impl/address.ipp"
  215. #endif // defined(ASIO_HEADER_ONLY)
  216. #endif // ASIO_IP_ADDRESS_HPP