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.

248 lines
5.6KB

  1. //
  2. // local/basic_endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Derived from a public domain implementation written by Daniel Casimiro.
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef ASIO_LOCAL_BASIC_ENDPOINT_HPP
  12. #define ASIO_LOCAL_BASIC_ENDPOINT_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include "asio/detail/config.hpp"
  17. #if defined(ASIO_HAS_LOCAL_SOCKETS) \
  18. || defined(GENERATING_DOCUMENTATION)
  19. #include "asio/local/detail/endpoint.hpp"
  20. #if !defined(ASIO_NO_IOSTREAM)
  21. # include <iosfwd>
  22. #endif // !defined(ASIO_NO_IOSTREAM)
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace local {
  26. /// Describes an endpoint for a UNIX socket.
  27. /**
  28. * The asio::local::basic_endpoint class template describes an endpoint
  29. * that may be associated with a particular UNIX socket.
  30. *
  31. * @par Thread Safety
  32. * @e Distinct @e objects: Safe.@n
  33. * @e Shared @e objects: Unsafe.
  34. *
  35. * @par Concepts:
  36. * Endpoint.
  37. */
  38. template <typename Protocol>
  39. class basic_endpoint
  40. {
  41. public:
  42. /// The protocol type associated with the endpoint.
  43. typedef Protocol protocol_type;
  44. /// The type of the endpoint structure. This type is dependent on the
  45. /// underlying implementation of the socket layer.
  46. #if defined(GENERATING_DOCUMENTATION)
  47. typedef implementation_defined data_type;
  48. #else
  49. typedef asio::detail::socket_addr_type data_type;
  50. #endif
  51. /// Default constructor.
  52. basic_endpoint()
  53. {
  54. }
  55. /// Construct an endpoint using the specified path name.
  56. basic_endpoint(const char* path_name)
  57. : impl_(path_name)
  58. {
  59. }
  60. /// Construct an endpoint using the specified path name.
  61. basic_endpoint(const std::string& path_name)
  62. : impl_(path_name)
  63. {
  64. }
  65. #if defined(ASIO_HAS_STRING_VIEW)
  66. /// Construct an endpoint using the specified path name.
  67. basic_endpoint(string_view path_name)
  68. : impl_(path_name)
  69. {
  70. }
  71. #endif // defined(ASIO_HAS_STRING_VIEW)
  72. /// Copy constructor.
  73. basic_endpoint(const basic_endpoint& other)
  74. : impl_(other.impl_)
  75. {
  76. }
  77. #if defined(ASIO_HAS_MOVE)
  78. /// Move constructor.
  79. basic_endpoint(basic_endpoint&& other)
  80. : impl_(other.impl_)
  81. {
  82. }
  83. #endif // defined(ASIO_HAS_MOVE)
  84. /// Assign from another endpoint.
  85. basic_endpoint& operator=(const basic_endpoint& other)
  86. {
  87. impl_ = other.impl_;
  88. return *this;
  89. }
  90. #if defined(ASIO_HAS_MOVE)
  91. /// Move-assign from another endpoint.
  92. basic_endpoint& operator=(basic_endpoint&& other)
  93. {
  94. impl_ = other.impl_;
  95. return *this;
  96. }
  97. #endif // defined(ASIO_HAS_MOVE)
  98. /// The protocol associated with the endpoint.
  99. protocol_type protocol() const
  100. {
  101. return protocol_type();
  102. }
  103. /// Get the underlying endpoint in the native type.
  104. data_type* data()
  105. {
  106. return impl_.data();
  107. }
  108. /// Get the underlying endpoint in the native type.
  109. const data_type* data() const
  110. {
  111. return impl_.data();
  112. }
  113. /// Get the underlying size of the endpoint in the native type.
  114. std::size_t size() const
  115. {
  116. return impl_.size();
  117. }
  118. /// Set the underlying size of the endpoint in the native type.
  119. void resize(std::size_t new_size)
  120. {
  121. impl_.resize(new_size);
  122. }
  123. /// Get the capacity of the endpoint in the native type.
  124. std::size_t capacity() const
  125. {
  126. return impl_.capacity();
  127. }
  128. /// Get the path associated with the endpoint.
  129. std::string path() const
  130. {
  131. return impl_.path();
  132. }
  133. /// Set the path associated with the endpoint.
  134. void path(const char* p)
  135. {
  136. impl_.path(p);
  137. }
  138. /// Set the path associated with the endpoint.
  139. void path(const std::string& p)
  140. {
  141. impl_.path(p);
  142. }
  143. /// Compare two endpoints for equality.
  144. friend bool operator==(const basic_endpoint<Protocol>& e1,
  145. const basic_endpoint<Protocol>& e2)
  146. {
  147. return e1.impl_ == e2.impl_;
  148. }
  149. /// Compare two endpoints for inequality.
  150. friend bool operator!=(const basic_endpoint<Protocol>& e1,
  151. const basic_endpoint<Protocol>& e2)
  152. {
  153. return !(e1.impl_ == e2.impl_);
  154. }
  155. /// Compare endpoints for ordering.
  156. friend bool operator<(const basic_endpoint<Protocol>& e1,
  157. const basic_endpoint<Protocol>& e2)
  158. {
  159. return e1.impl_ < e2.impl_;
  160. }
  161. /// Compare endpoints for ordering.
  162. friend bool operator>(const basic_endpoint<Protocol>& e1,
  163. const basic_endpoint<Protocol>& e2)
  164. {
  165. return e2.impl_ < e1.impl_;
  166. }
  167. /// Compare endpoints for ordering.
  168. friend bool operator<=(const basic_endpoint<Protocol>& e1,
  169. const basic_endpoint<Protocol>& e2)
  170. {
  171. return !(e2 < e1);
  172. }
  173. /// Compare endpoints for ordering.
  174. friend bool operator>=(const basic_endpoint<Protocol>& e1,
  175. const basic_endpoint<Protocol>& e2)
  176. {
  177. return !(e1 < e2);
  178. }
  179. private:
  180. // The underlying UNIX domain endpoint.
  181. asio::local::detail::endpoint impl_;
  182. };
  183. /// Output an endpoint as a string.
  184. /**
  185. * Used to output a human-readable string for a specified endpoint.
  186. *
  187. * @param os The output stream to which the string will be written.
  188. *
  189. * @param endpoint The endpoint to be written.
  190. *
  191. * @return The output stream.
  192. *
  193. * @relates asio::local::basic_endpoint
  194. */
  195. template <typename Elem, typename Traits, typename Protocol>
  196. std::basic_ostream<Elem, Traits>& operator<<(
  197. std::basic_ostream<Elem, Traits>& os,
  198. const basic_endpoint<Protocol>& endpoint)
  199. {
  200. os << endpoint.path();
  201. return os;
  202. }
  203. } // namespace local
  204. } // namespace asio
  205. #include "asio/detail/pop_options.hpp"
  206. #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
  207. // || defined(GENERATING_DOCUMENTATION)
  208. #endif // ASIO_LOCAL_BASIC_ENDPOINT_HPP