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.hpp 6.5KB

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