Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:00

0001 //
0002 // local/basic_endpoint.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 // Derived from a public domain implementation written by Daniel Casimiro.
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 
0012 #ifndef BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
0013 #define BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
0014 
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0018 
0019 #include <boost/asio/detail/config.hpp>
0020 
0021 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
0022   || defined(GENERATING_DOCUMENTATION)
0023 
0024 #include <boost/asio/local/detail/endpoint.hpp>
0025 
0026 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0027 # include <iosfwd>
0028 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0029 
0030 #include <boost/asio/detail/push_options.hpp>
0031 
0032 namespace boost {
0033 namespace asio {
0034 namespace local {
0035 
0036 /// Describes an endpoint for a UNIX socket.
0037 /**
0038  * The boost::asio::local::basic_endpoint class template describes an endpoint
0039  * that may be associated with a particular UNIX socket.
0040  *
0041  * @par Thread Safety
0042  * @e Distinct @e objects: Safe.@n
0043  * @e Shared @e objects: Unsafe.
0044  *
0045  * @par Concepts:
0046  * Endpoint.
0047  */
0048 template <typename Protocol>
0049 class basic_endpoint
0050 {
0051 public:
0052   /// The protocol type associated with the endpoint.
0053   typedef Protocol protocol_type;
0054 
0055   /// The type of the endpoint structure. This type is dependent on the
0056   /// underlying implementation of the socket layer.
0057 #if defined(GENERATING_DOCUMENTATION)
0058   typedef implementation_defined data_type;
0059 #else
0060   typedef boost::asio::detail::socket_addr_type data_type;
0061 #endif
0062 
0063   /// Default constructor.
0064   basic_endpoint() noexcept
0065   {
0066   }
0067 
0068   /// Construct an endpoint using the specified path name.
0069   basic_endpoint(const char* path_name)
0070     : impl_(path_name)
0071   {
0072   }
0073 
0074   /// Construct an endpoint using the specified path name.
0075   basic_endpoint(const std::string& path_name)
0076     : impl_(path_name)
0077   {
0078   }
0079 
0080   #if defined(BOOST_ASIO_HAS_STRING_VIEW)
0081   /// Construct an endpoint using the specified path name.
0082   basic_endpoint(string_view path_name)
0083     : impl_(path_name)
0084   {
0085   }
0086   #endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
0087 
0088   /// Copy constructor.
0089   basic_endpoint(const basic_endpoint& other)
0090     : impl_(other.impl_)
0091   {
0092   }
0093 
0094   /// Move constructor.
0095   basic_endpoint(basic_endpoint&& other)
0096     : impl_(other.impl_)
0097   {
0098   }
0099 
0100   /// Assign from another endpoint.
0101   basic_endpoint& operator=(const basic_endpoint& other)
0102   {
0103     impl_ = other.impl_;
0104     return *this;
0105   }
0106 
0107   /// Move-assign from another endpoint.
0108   basic_endpoint& operator=(basic_endpoint&& other)
0109   {
0110     impl_ = other.impl_;
0111     return *this;
0112   }
0113 
0114   /// The protocol associated with the endpoint.
0115   protocol_type protocol() const
0116   {
0117     return protocol_type();
0118   }
0119 
0120   /// Get the underlying endpoint in the native type.
0121   data_type* data()
0122   {
0123     return impl_.data();
0124   }
0125 
0126   /// Get the underlying endpoint in the native type.
0127   const data_type* data() const
0128   {
0129     return impl_.data();
0130   }
0131 
0132   /// Get the underlying size of the endpoint in the native type.
0133   std::size_t size() const
0134   {
0135     return impl_.size();
0136   }
0137 
0138   /// Set the underlying size of the endpoint in the native type.
0139   void resize(std::size_t new_size)
0140   {
0141     impl_.resize(new_size);
0142   }
0143 
0144   /// Get the capacity of the endpoint in the native type.
0145   std::size_t capacity() const
0146   {
0147     return impl_.capacity();
0148   }
0149 
0150   /// Get the path associated with the endpoint.
0151   std::string path() const
0152   {
0153     return impl_.path();
0154   }
0155 
0156   /// Set the path associated with the endpoint.
0157   void path(const char* p)
0158   {
0159     impl_.path(p);
0160   }
0161 
0162   /// Set the path associated with the endpoint.
0163   void path(const std::string& p)
0164   {
0165     impl_.path(p);
0166   }
0167 
0168   /// Compare two endpoints for equality.
0169   friend bool operator==(const basic_endpoint<Protocol>& e1,
0170       const basic_endpoint<Protocol>& e2)
0171   {
0172     return e1.impl_ == e2.impl_;
0173   }
0174 
0175   /// Compare two endpoints for inequality.
0176   friend bool operator!=(const basic_endpoint<Protocol>& e1,
0177       const basic_endpoint<Protocol>& e2)
0178   {
0179     return !(e1.impl_ == e2.impl_);
0180   }
0181 
0182   /// Compare endpoints for ordering.
0183   friend bool operator<(const basic_endpoint<Protocol>& e1,
0184       const basic_endpoint<Protocol>& e2)
0185   {
0186     return e1.impl_ < e2.impl_;
0187   }
0188 
0189   /// Compare endpoints for ordering.
0190   friend bool operator>(const basic_endpoint<Protocol>& e1,
0191       const basic_endpoint<Protocol>& e2)
0192   {
0193     return e2.impl_ < e1.impl_;
0194   }
0195 
0196   /// Compare endpoints for ordering.
0197   friend bool operator<=(const basic_endpoint<Protocol>& e1,
0198       const basic_endpoint<Protocol>& e2)
0199   {
0200     return !(e2 < e1);
0201   }
0202 
0203   /// Compare endpoints for ordering.
0204   friend bool operator>=(const basic_endpoint<Protocol>& e1,
0205       const basic_endpoint<Protocol>& e2)
0206   {
0207     return !(e1 < e2);
0208   }
0209 
0210 private:
0211   // The underlying UNIX domain endpoint.
0212   boost::asio::local::detail::endpoint impl_;
0213 };
0214 
0215 /// Output an endpoint as a string.
0216 /**
0217  * Used to output a human-readable string for a specified endpoint.
0218  *
0219  * @param os The output stream to which the string will be written.
0220  *
0221  * @param endpoint The endpoint to be written.
0222  *
0223  * @return The output stream.
0224  *
0225  * @relates boost::asio::local::basic_endpoint
0226  */
0227 template <typename Elem, typename Traits, typename Protocol>
0228 std::basic_ostream<Elem, Traits>& operator<<(
0229     std::basic_ostream<Elem, Traits>& os,
0230     const basic_endpoint<Protocol>& endpoint)
0231 {
0232   os << endpoint.path();
0233   return os;
0234 }
0235 
0236 } // namespace local
0237 } // namespace asio
0238 } // namespace boost
0239 
0240 #include <boost/asio/detail/pop_options.hpp>
0241 
0242 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
0243        //   || defined(GENERATING_DOCUMENTATION)
0244 
0245 #endif // BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP