Chris@16: // Chris@16: // local/basic_endpoint.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Derived from a public domain implementation written by Daniel Casimiro. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP Chris@16: #define BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ Chris@16: || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: # include Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace local { Chris@16: Chris@16: /// Describes an endpoint for a UNIX socket. Chris@16: /** Chris@16: * The boost::asio::local::basic_endpoint class template describes an endpoint Chris@16: * that may be associated with a particular UNIX socket. Chris@16: * Chris@16: * @par Thread Safety Chris@16: * @e Distinct @e objects: Safe.@n Chris@16: * @e Shared @e objects: Unsafe. Chris@16: * Chris@16: * @par Concepts: Chris@16: * Endpoint. Chris@16: */ Chris@16: template Chris@16: class basic_endpoint Chris@16: { Chris@16: public: Chris@16: /// The protocol type associated with the endpoint. Chris@16: typedef Protocol protocol_type; Chris@16: Chris@16: /// The type of the endpoint structure. This type is dependent on the Chris@16: /// underlying implementation of the socket layer. Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef implementation_defined data_type; Chris@16: #else Chris@16: typedef boost::asio::detail::socket_addr_type data_type; Chris@16: #endif Chris@16: Chris@16: /// Default constructor. Chris@16: basic_endpoint() Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct an endpoint using the specified path name. Chris@16: basic_endpoint(const char* path_name) Chris@16: : impl_(path_name) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct an endpoint using the specified path name. Chris@16: basic_endpoint(const std::string& path_name) Chris@16: : impl_(path_name) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Copy constructor. Chris@16: basic_endpoint(const basic_endpoint& other) Chris@16: : impl_(other.impl_) Chris@16: { Chris@16: } Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) Chris@16: /// Move constructor. Chris@16: basic_endpoint(basic_endpoint&& other) Chris@16: : impl_(other.impl_) Chris@16: { Chris@16: } Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) Chris@16: Chris@16: /// Assign from another endpoint. Chris@16: basic_endpoint& operator=(const basic_endpoint& other) Chris@16: { Chris@16: impl_ = other.impl_; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) Chris@16: /// Move-assign from another endpoint. Chris@16: basic_endpoint& operator=(basic_endpoint&& other) Chris@16: { Chris@16: impl_ = other.impl_; Chris@16: return *this; Chris@16: } Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) Chris@16: Chris@16: /// The protocol associated with the endpoint. Chris@16: protocol_type protocol() const Chris@16: { Chris@16: return protocol_type(); Chris@16: } Chris@16: Chris@16: /// Get the underlying endpoint in the native type. Chris@16: data_type* data() Chris@16: { Chris@16: return impl_.data(); Chris@16: } Chris@16: Chris@16: /// Get the underlying endpoint in the native type. Chris@16: const data_type* data() const Chris@16: { Chris@16: return impl_.data(); Chris@16: } Chris@16: Chris@16: /// Get the underlying size of the endpoint in the native type. Chris@16: std::size_t size() const Chris@16: { Chris@16: return impl_.size(); Chris@16: } Chris@16: Chris@16: /// Set the underlying size of the endpoint in the native type. Chris@16: void resize(std::size_t new_size) Chris@16: { Chris@16: impl_.resize(new_size); Chris@16: } Chris@16: Chris@16: /// Get the capacity of the endpoint in the native type. Chris@16: std::size_t capacity() const Chris@16: { Chris@16: return impl_.capacity(); Chris@16: } Chris@16: Chris@16: /// Get the path associated with the endpoint. Chris@16: std::string path() const Chris@16: { Chris@16: return impl_.path(); Chris@16: } Chris@16: Chris@16: /// Set the path associated with the endpoint. Chris@16: void path(const char* p) Chris@16: { Chris@16: impl_.path(p); Chris@16: } Chris@16: Chris@16: /// Set the path associated with the endpoint. Chris@16: void path(const std::string& p) Chris@16: { Chris@16: impl_.path(p); Chris@16: } Chris@16: Chris@16: /// Compare two endpoints for equality. Chris@16: friend bool operator==(const basic_endpoint& e1, Chris@16: const basic_endpoint& e2) Chris@16: { Chris@16: return e1.impl_ == e2.impl_; Chris@16: } Chris@16: Chris@16: /// Compare two endpoints for inequality. Chris@16: friend bool operator!=(const basic_endpoint& e1, Chris@16: const basic_endpoint& e2) Chris@16: { Chris@16: return !(e1.impl_ == e2.impl_); Chris@16: } Chris@16: Chris@16: /// Compare endpoints for ordering. Chris@16: friend bool operator<(const basic_endpoint& e1, Chris@16: const basic_endpoint& e2) Chris@16: { Chris@16: return e1.impl_ < e2.impl_; Chris@16: } Chris@16: Chris@16: /// Compare endpoints for ordering. Chris@16: friend bool operator>(const basic_endpoint& e1, Chris@16: const basic_endpoint& e2) Chris@16: { Chris@16: return e2.impl_ < e1.impl_; Chris@16: } Chris@16: Chris@16: /// Compare endpoints for ordering. Chris@16: friend bool operator<=(const basic_endpoint& e1, Chris@16: const basic_endpoint& e2) Chris@16: { Chris@16: return !(e2 < e1); Chris@16: } Chris@16: Chris@16: /// Compare endpoints for ordering. Chris@16: friend bool operator>=(const basic_endpoint& e1, Chris@16: const basic_endpoint& e2) Chris@16: { Chris@16: return !(e1 < e2); Chris@16: } Chris@16: Chris@16: private: Chris@16: // The underlying UNIX domain endpoint. Chris@16: boost::asio::local::detail::endpoint impl_; Chris@16: }; Chris@16: Chris@16: /// Output an endpoint as a string. Chris@16: /** Chris@16: * Used to output a human-readable string for a specified endpoint. Chris@16: * Chris@16: * @param os The output stream to which the string will be written. Chris@16: * Chris@16: * @param endpoint The endpoint to be written. Chris@16: * Chris@16: * @return The output stream. Chris@16: * Chris@16: * @relates boost::asio::local::basic_endpoint Chris@16: */ Chris@16: template Chris@16: std::basic_ostream& operator<<( Chris@16: std::basic_ostream& os, Chris@16: const basic_endpoint& endpoint) Chris@16: { Chris@16: os << endpoint.path(); Chris@16: return os; Chris@16: } Chris@16: Chris@16: } // namespace local Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) Chris@16: // || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #endif // BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP