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.

basic_endpoint.hpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // generic/basic_endpoint.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_GENERIC_BASIC_ENDPOINT_HPP
  11. #define ASIO_GENERIC_BASIC_ENDPOINT_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 "asio/generic/detail/endpoint.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. namespace generic {
  20. /// Describes an endpoint for any socket type.
  21. /**
  22. * The asio::generic::basic_endpoint class template describes an endpoint
  23. * that may be associated with any socket type.
  24. *
  25. * @note The socket types sockaddr type must be able to fit into a
  26. * @c sockaddr_storage structure.
  27. *
  28. * @par Thread Safety
  29. * @e Distinct @e objects: Safe.@n
  30. * @e Shared @e objects: Unsafe.
  31. *
  32. * @par Concepts:
  33. * Endpoint.
  34. */
  35. template <typename Protocol>
  36. class basic_endpoint
  37. {
  38. public:
  39. /// The protocol type associated with the endpoint.
  40. typedef Protocol protocol_type;
  41. /// The type of the endpoint structure. This type is dependent on the
  42. /// underlying implementation of the socket layer.
  43. #if defined(GENERATING_DOCUMENTATION)
  44. typedef implementation_defined data_type;
  45. #else
  46. typedef asio::detail::socket_addr_type data_type;
  47. #endif
  48. /// Default constructor.
  49. basic_endpoint()
  50. {
  51. }
  52. /// Construct an endpoint from the specified socket address.
  53. basic_endpoint(const void* socket_address,
  54. std::size_t socket_address_size, int socket_protocol = 0)
  55. : impl_(socket_address, socket_address_size, socket_protocol)
  56. {
  57. }
  58. /// Construct an endpoint from the specific endpoint type.
  59. template <typename Endpoint>
  60. basic_endpoint(const Endpoint& endpoint)
  61. : impl_(endpoint.data(), endpoint.size(), endpoint.protocol().protocol())
  62. {
  63. }
  64. /// Copy constructor.
  65. basic_endpoint(const basic_endpoint& other)
  66. : impl_(other.impl_)
  67. {
  68. }
  69. #if defined(ASIO_HAS_MOVE)
  70. /// Move constructor.
  71. basic_endpoint(basic_endpoint&& other)
  72. : impl_(other.impl_)
  73. {
  74. }
  75. #endif // defined(ASIO_HAS_MOVE)
  76. /// Assign from another endpoint.
  77. basic_endpoint& operator=(const basic_endpoint& other)
  78. {
  79. impl_ = other.impl_;
  80. return *this;
  81. }
  82. #if defined(ASIO_HAS_MOVE)
  83. /// Move-assign from another endpoint.
  84. basic_endpoint& operator=(basic_endpoint&& other)
  85. {
  86. impl_ = other.impl_;
  87. return *this;
  88. }
  89. #endif // defined(ASIO_HAS_MOVE)
  90. /// The protocol associated with the endpoint.
  91. protocol_type protocol() const
  92. {
  93. return protocol_type(impl_.family(), impl_.protocol());
  94. }
  95. /// Get the underlying endpoint in the native type.
  96. data_type* data()
  97. {
  98. return impl_.data();
  99. }
  100. /// Get the underlying endpoint in the native type.
  101. const data_type* data() const
  102. {
  103. return impl_.data();
  104. }
  105. /// Get the underlying size of the endpoint in the native type.
  106. std::size_t size() const
  107. {
  108. return impl_.size();
  109. }
  110. /// Set the underlying size of the endpoint in the native type.
  111. void resize(std::size_t new_size)
  112. {
  113. impl_.resize(new_size);
  114. }
  115. /// Get the capacity of the endpoint in the native type.
  116. std::size_t capacity() const
  117. {
  118. return impl_.capacity();
  119. }
  120. /// Compare two endpoints for equality.
  121. friend bool operator==(const basic_endpoint<Protocol>& e1,
  122. const basic_endpoint<Protocol>& e2)
  123. {
  124. return e1.impl_ == e2.impl_;
  125. }
  126. /// Compare two endpoints for inequality.
  127. friend bool operator!=(const basic_endpoint<Protocol>& e1,
  128. const basic_endpoint<Protocol>& e2)
  129. {
  130. return !(e1.impl_ == e2.impl_);
  131. }
  132. /// Compare endpoints for ordering.
  133. friend bool operator<(const basic_endpoint<Protocol>& e1,
  134. const basic_endpoint<Protocol>& e2)
  135. {
  136. return e1.impl_ < e2.impl_;
  137. }
  138. /// Compare endpoints for ordering.
  139. friend bool operator>(const basic_endpoint<Protocol>& e1,
  140. const basic_endpoint<Protocol>& e2)
  141. {
  142. return e2.impl_ < e1.impl_;
  143. }
  144. /// Compare endpoints for ordering.
  145. friend bool operator<=(const basic_endpoint<Protocol>& e1,
  146. const basic_endpoint<Protocol>& e2)
  147. {
  148. return !(e2 < e1);
  149. }
  150. /// Compare endpoints for ordering.
  151. friend bool operator>=(const basic_endpoint<Protocol>& e1,
  152. const basic_endpoint<Protocol>& e2)
  153. {
  154. return !(e1 < e2);
  155. }
  156. private:
  157. // The underlying generic endpoint.
  158. asio::generic::detail::endpoint impl_;
  159. };
  160. } // namespace generic
  161. } // namespace asio
  162. #include "asio/detail/pop_options.hpp"
  163. #endif // ASIO_GENERIC_BASIC_ENDPOINT_HPP