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.

240 lines
5.4KB

  1. //
  2. // local/basic_endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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. /// Copy constructor.
  66. basic_endpoint(const basic_endpoint& other)
  67. : impl_(other.impl_)
  68. {
  69. }
  70. #if defined(ASIO_HAS_MOVE)
  71. /// Move constructor.
  72. basic_endpoint(basic_endpoint&& other)
  73. : impl_(other.impl_)
  74. {
  75. }
  76. #endif // defined(ASIO_HAS_MOVE)
  77. /// Assign from another endpoint.
  78. basic_endpoint& operator=(const basic_endpoint& other)
  79. {
  80. impl_ = other.impl_;
  81. return *this;
  82. }
  83. #if defined(ASIO_HAS_MOVE)
  84. /// Move-assign from another endpoint.
  85. basic_endpoint& operator=(basic_endpoint&& other)
  86. {
  87. impl_ = other.impl_;
  88. return *this;
  89. }
  90. #endif // defined(ASIO_HAS_MOVE)
  91. /// The protocol associated with the endpoint.
  92. protocol_type protocol() const
  93. {
  94. return protocol_type();
  95. }
  96. /// Get the underlying endpoint in the native type.
  97. data_type* data()
  98. {
  99. return impl_.data();
  100. }
  101. /// Get the underlying endpoint in the native type.
  102. const data_type* data() const
  103. {
  104. return impl_.data();
  105. }
  106. /// Get the underlying size of the endpoint in the native type.
  107. std::size_t size() const
  108. {
  109. return impl_.size();
  110. }
  111. /// Set the underlying size of the endpoint in the native type.
  112. void resize(std::size_t new_size)
  113. {
  114. impl_.resize(new_size);
  115. }
  116. /// Get the capacity of the endpoint in the native type.
  117. std::size_t capacity() const
  118. {
  119. return impl_.capacity();
  120. }
  121. /// Get the path associated with the endpoint.
  122. std::string path() const
  123. {
  124. return impl_.path();
  125. }
  126. /// Set the path associated with the endpoint.
  127. void path(const char* p)
  128. {
  129. impl_.path(p);
  130. }
  131. /// Set the path associated with the endpoint.
  132. void path(const std::string& p)
  133. {
  134. impl_.path(p);
  135. }
  136. /// Compare two endpoints for equality.
  137. friend bool operator==(const basic_endpoint<Protocol>& e1,
  138. const basic_endpoint<Protocol>& e2)
  139. {
  140. return e1.impl_ == e2.impl_;
  141. }
  142. /// Compare two endpoints for inequality.
  143. friend bool operator!=(const basic_endpoint<Protocol>& e1,
  144. const basic_endpoint<Protocol>& e2)
  145. {
  146. return !(e1.impl_ == e2.impl_);
  147. }
  148. /// Compare endpoints for ordering.
  149. friend bool operator<(const basic_endpoint<Protocol>& e1,
  150. const basic_endpoint<Protocol>& e2)
  151. {
  152. return e1.impl_ < e2.impl_;
  153. }
  154. /// Compare endpoints for ordering.
  155. friend bool operator>(const basic_endpoint<Protocol>& e1,
  156. const basic_endpoint<Protocol>& e2)
  157. {
  158. return e2.impl_ < e1.impl_;
  159. }
  160. /// Compare endpoints for ordering.
  161. friend bool operator<=(const basic_endpoint<Protocol>& e1,
  162. const basic_endpoint<Protocol>& e2)
  163. {
  164. return !(e2 < e1);
  165. }
  166. /// Compare endpoints for ordering.
  167. friend bool operator>=(const basic_endpoint<Protocol>& e1,
  168. const basic_endpoint<Protocol>& e2)
  169. {
  170. return !(e1 < e2);
  171. }
  172. private:
  173. // The underlying UNIX domain endpoint.
  174. asio::local::detail::endpoint impl_;
  175. };
  176. /// Output an endpoint as a string.
  177. /**
  178. * Used to output a human-readable string for a specified endpoint.
  179. *
  180. * @param os The output stream to which the string will be written.
  181. *
  182. * @param endpoint The endpoint to be written.
  183. *
  184. * @return The output stream.
  185. *
  186. * @relates asio::local::basic_endpoint
  187. */
  188. template <typename Elem, typename Traits, typename Protocol>
  189. std::basic_ostream<Elem, Traits>& operator<<(
  190. std::basic_ostream<Elem, Traits>& os,
  191. const basic_endpoint<Protocol>& endpoint)
  192. {
  193. os << endpoint.path();
  194. return os;
  195. }
  196. } // namespace local
  197. } // namespace asio
  198. #include "asio/detail/pop_options.hpp"
  199. #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
  200. // || defined(GENERATING_DOCUMENTATION)
  201. #endif // ASIO_LOCAL_BASIC_ENDPOINT_HPP