2 // local/basic_endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Derived from a public domain implementation written by Daniel Casimiro.
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)
12 #ifndef BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
13 #define BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
21 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
22 || defined(GENERATING_DOCUMENTATION)
24 #include <boost/asio/local/detail/endpoint.hpp>
26 #if !defined(BOOST_ASIO_NO_IOSTREAM)
28 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
30 #include <boost/asio/detail/push_options.hpp>
36 /// Describes an endpoint for a UNIX socket.
38 * The boost::asio::local::basic_endpoint class template describes an endpoint
39 * that may be associated with a particular UNIX socket.
42 * @e Distinct @e objects: Safe.@n
43 * @e Shared @e objects: Unsafe.
48 template <typename Protocol>
52 /// The protocol type associated with the endpoint.
53 typedef Protocol protocol_type;
55 /// The type of the endpoint structure. This type is dependent on the
56 /// underlying implementation of the socket layer.
57 #if defined(GENERATING_DOCUMENTATION)
58 typedef implementation_defined data_type;
60 typedef boost::asio::detail::socket_addr_type data_type;
63 /// Default constructor.
68 /// Construct an endpoint using the specified path name.
69 basic_endpoint(const char* path_name)
74 /// Construct an endpoint using the specified path name.
75 basic_endpoint(const std::string& path_name)
81 basic_endpoint(const basic_endpoint& other)
86 #if defined(BOOST_ASIO_HAS_MOVE)
88 basic_endpoint(basic_endpoint&& other)
92 #endif // defined(BOOST_ASIO_HAS_MOVE)
94 /// Assign from another endpoint.
95 basic_endpoint& operator=(const basic_endpoint& other)
101 #if defined(BOOST_ASIO_HAS_MOVE)
102 /// Move-assign from another endpoint.
103 basic_endpoint& operator=(basic_endpoint&& other)
108 #endif // defined(BOOST_ASIO_HAS_MOVE)
110 /// The protocol associated with the endpoint.
111 protocol_type protocol() const
113 return protocol_type();
116 /// Get the underlying endpoint in the native type.
122 /// Get the underlying endpoint in the native type.
123 const data_type* data() const
128 /// Get the underlying size of the endpoint in the native type.
129 std::size_t size() const
134 /// Set the underlying size of the endpoint in the native type.
135 void resize(std::size_t new_size)
137 impl_.resize(new_size);
140 /// Get the capacity of the endpoint in the native type.
141 std::size_t capacity() const
143 return impl_.capacity();
146 /// Get the path associated with the endpoint.
147 std::string path() const
152 /// Set the path associated with the endpoint.
153 void path(const char* p)
158 /// Set the path associated with the endpoint.
159 void path(const std::string& p)
164 /// Compare two endpoints for equality.
165 friend bool operator==(const basic_endpoint<Protocol>& e1,
166 const basic_endpoint<Protocol>& e2)
168 return e1.impl_ == e2.impl_;
171 /// Compare two endpoints for inequality.
172 friend bool operator!=(const basic_endpoint<Protocol>& e1,
173 const basic_endpoint<Protocol>& e2)
175 return !(e1.impl_ == e2.impl_);
178 /// Compare endpoints for ordering.
179 friend bool operator<(const basic_endpoint<Protocol>& e1,
180 const basic_endpoint<Protocol>& e2)
182 return e1.impl_ < e2.impl_;
185 /// Compare endpoints for ordering.
186 friend bool operator>(const basic_endpoint<Protocol>& e1,
187 const basic_endpoint<Protocol>& e2)
189 return e2.impl_ < e1.impl_;
192 /// Compare endpoints for ordering.
193 friend bool operator<=(const basic_endpoint<Protocol>& e1,
194 const basic_endpoint<Protocol>& e2)
199 /// Compare endpoints for ordering.
200 friend bool operator>=(const basic_endpoint<Protocol>& e1,
201 const basic_endpoint<Protocol>& e2)
207 // The underlying UNIX domain endpoint.
208 boost::asio::local::detail::endpoint impl_;
211 /// Output an endpoint as a string.
213 * Used to output a human-readable string for a specified endpoint.
215 * @param os The output stream to which the string will be written.
217 * @param endpoint The endpoint to be written.
219 * @return The output stream.
221 * @relates boost::asio::local::basic_endpoint
223 template <typename Elem, typename Traits, typename Protocol>
224 std::basic_ostream<Elem, Traits>& operator<<(
225 std::basic_ostream<Elem, Traits>& os,
226 const basic_endpoint<Protocol>& endpoint)
228 os << endpoint.path();
236 #include <boost/asio/detail/pop_options.hpp>
238 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
239 // || defined(GENERATING_DOCUMENTATION)
241 #endif // BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP