Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / ip / basic_endpoint.hpp @ 2486

History | View | Annotate | Download (6.7 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// ip/basic_endpoint.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_IP_BASIC_ENDPOINT_HPP
12 2486 sjacqu01
#define BOOST_ASIO_IP_BASIC_ENDPOINT_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <boost/asio/ip/address.hpp>
20 2486 sjacqu01
#include <boost/asio/ip/detail/endpoint.hpp>
21 2486 sjacqu01
22 2486 sjacqu01
#if !defined(BOOST_ASIO_NO_IOSTREAM)
23 2486 sjacqu01
# include <iosfwd>
24 2486 sjacqu01
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
25 2486 sjacqu01
26 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
27 2486 sjacqu01
28 2486 sjacqu01
namespace boost {
29 2486 sjacqu01
namespace asio {
30 2486 sjacqu01
namespace ip {
31 2486 sjacqu01
32 2486 sjacqu01
/// Describes an endpoint for a version-independent IP socket.
33 2486 sjacqu01
/**
34 2486 sjacqu01
 * The boost::asio::ip::basic_endpoint class template describes an endpoint that
35 2486 sjacqu01
 * may be associated with a particular socket.
36 2486 sjacqu01
 *
37 2486 sjacqu01
 * @par Thread Safety
38 2486 sjacqu01
 * @e Distinct @e objects: Safe.@n
39 2486 sjacqu01
 * @e Shared @e objects: Unsafe.
40 2486 sjacqu01
 *
41 2486 sjacqu01
 * @par Concepts:
42 2486 sjacqu01
 * Endpoint.
43 2486 sjacqu01
 */
44 2486 sjacqu01
template <typename InternetProtocol>
45 2486 sjacqu01
class basic_endpoint
46 2486 sjacqu01
{
47 2486 sjacqu01
public:
48 2486 sjacqu01
  /// The protocol type associated with the endpoint.
49 2486 sjacqu01
  typedef InternetProtocol protocol_type;
50 2486 sjacqu01
51 2486 sjacqu01
  /// The type of the endpoint structure. This type is dependent on the
52 2486 sjacqu01
  /// underlying implementation of the socket layer.
53 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
54 2486 sjacqu01
  typedef implementation_defined data_type;
55 2486 sjacqu01
#else
56 2486 sjacqu01
  typedef boost::asio::detail::socket_addr_type data_type;
57 2486 sjacqu01
#endif
58 2486 sjacqu01
59 2486 sjacqu01
  /// Default constructor.
60 2486 sjacqu01
  basic_endpoint()
61 2486 sjacqu01
    : impl_()
62 2486 sjacqu01
  {
63 2486 sjacqu01
  }
64 2486 sjacqu01
65 2486 sjacqu01
  /// Construct an endpoint using a port number, specified in the host's byte
66 2486 sjacqu01
  /// order. The IP address will be the any address (i.e. INADDR_ANY or
67 2486 sjacqu01
  /// in6addr_any). This constructor would typically be used for accepting new
68 2486 sjacqu01
  /// connections.
69 2486 sjacqu01
  /**
70 2486 sjacqu01
   * @par Examples
71 2486 sjacqu01
   * To initialise an IPv4 TCP endpoint for port 1234, use:
72 2486 sjacqu01
   * @code
73 2486 sjacqu01
   * boost::asio::ip::tcp::endpoint ep(boost::asio::ip::tcp::v4(), 1234);
74 2486 sjacqu01
   * @endcode
75 2486 sjacqu01
   *
76 2486 sjacqu01
   * To specify an IPv6 UDP endpoint for port 9876, use:
77 2486 sjacqu01
   * @code
78 2486 sjacqu01
   * boost::asio::ip::udp::endpoint ep(boost::asio::ip::udp::v6(), 9876);
79 2486 sjacqu01
   * @endcode
80 2486 sjacqu01
   */
81 2486 sjacqu01
  basic_endpoint(const InternetProtocol& internet_protocol,
82 2486 sjacqu01
      unsigned short port_num)
83 2486 sjacqu01
    : impl_(internet_protocol.family(), port_num)
84 2486 sjacqu01
  {
85 2486 sjacqu01
  }
86 2486 sjacqu01
87 2486 sjacqu01
  /// Construct an endpoint using a port number and an IP address. This
88 2486 sjacqu01
  /// constructor may be used for accepting connections on a specific interface
89 2486 sjacqu01
  /// or for making a connection to a remote endpoint.
90 2486 sjacqu01
  basic_endpoint(const boost::asio::ip::address& addr, unsigned short port_num)
91 2486 sjacqu01
    : impl_(addr, port_num)
92 2486 sjacqu01
  {
93 2486 sjacqu01
  }
94 2486 sjacqu01
95 2486 sjacqu01
  /// Copy constructor.
96 2486 sjacqu01
  basic_endpoint(const basic_endpoint& other)
97 2486 sjacqu01
    : impl_(other.impl_)
98 2486 sjacqu01
  {
99 2486 sjacqu01
  }
100 2486 sjacqu01
101 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_MOVE)
102 2486 sjacqu01
  /// Move constructor.
103 2486 sjacqu01
  basic_endpoint(basic_endpoint&& other)
104 2486 sjacqu01
    : impl_(other.impl_)
105 2486 sjacqu01
  {
106 2486 sjacqu01
  }
107 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_MOVE)
108 2486 sjacqu01
109 2486 sjacqu01
  /// Assign from another endpoint.
110 2486 sjacqu01
  basic_endpoint& operator=(const basic_endpoint& other)
111 2486 sjacqu01
  {
112 2486 sjacqu01
    impl_ = other.impl_;
113 2486 sjacqu01
    return *this;
114 2486 sjacqu01
  }
115 2486 sjacqu01
116 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_MOVE)
117 2486 sjacqu01
  /// Move-assign from another endpoint.
118 2486 sjacqu01
  basic_endpoint& operator=(basic_endpoint&& other)
119 2486 sjacqu01
  {
120 2486 sjacqu01
    impl_ = other.impl_;
121 2486 sjacqu01
    return *this;
122 2486 sjacqu01
  }
123 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_MOVE)
124 2486 sjacqu01
125 2486 sjacqu01
  /// The protocol associated with the endpoint.
126 2486 sjacqu01
  protocol_type protocol() const
127 2486 sjacqu01
  {
128 2486 sjacqu01
    if (impl_.is_v4())
129 2486 sjacqu01
      return InternetProtocol::v4();
130 2486 sjacqu01
    return InternetProtocol::v6();
131 2486 sjacqu01
  }
132 2486 sjacqu01
133 2486 sjacqu01
  /// Get the underlying endpoint in the native type.
134 2486 sjacqu01
  data_type* data()
135 2486 sjacqu01
  {
136 2486 sjacqu01
    return impl_.data();
137 2486 sjacqu01
  }
138 2486 sjacqu01
139 2486 sjacqu01
  /// Get the underlying endpoint in the native type.
140 2486 sjacqu01
  const data_type* data() const
141 2486 sjacqu01
  {
142 2486 sjacqu01
    return impl_.data();
143 2486 sjacqu01
  }
144 2486 sjacqu01
145 2486 sjacqu01
  /// Get the underlying size of the endpoint in the native type.
146 2486 sjacqu01
  std::size_t size() const
147 2486 sjacqu01
  {
148 2486 sjacqu01
    return impl_.size();
149 2486 sjacqu01
  }
150 2486 sjacqu01
151 2486 sjacqu01
  /// Set the underlying size of the endpoint in the native type.
152 2486 sjacqu01
  void resize(std::size_t new_size)
153 2486 sjacqu01
  {
154 2486 sjacqu01
    impl_.resize(new_size);
155 2486 sjacqu01
  }
156 2486 sjacqu01
157 2486 sjacqu01
  /// Get the capacity of the endpoint in the native type.
158 2486 sjacqu01
  std::size_t capacity() const
159 2486 sjacqu01
  {
160 2486 sjacqu01
    return impl_.capacity();
161 2486 sjacqu01
  }
162 2486 sjacqu01
163 2486 sjacqu01
  /// Get the port associated with the endpoint. The port number is always in
164 2486 sjacqu01
  /// the host's byte order.
165 2486 sjacqu01
  unsigned short port() const
166 2486 sjacqu01
  {
167 2486 sjacqu01
    return impl_.port();
168 2486 sjacqu01
  }
169 2486 sjacqu01
170 2486 sjacqu01
  /// Set the port associated with the endpoint. The port number is always in
171 2486 sjacqu01
  /// the host's byte order.
172 2486 sjacqu01
  void port(unsigned short port_num)
173 2486 sjacqu01
  {
174 2486 sjacqu01
    impl_.port(port_num);
175 2486 sjacqu01
  }
176 2486 sjacqu01
177 2486 sjacqu01
  /// Get the IP address associated with the endpoint.
178 2486 sjacqu01
  boost::asio::ip::address address() const
179 2486 sjacqu01
  {
180 2486 sjacqu01
    return impl_.address();
181 2486 sjacqu01
  }
182 2486 sjacqu01
183 2486 sjacqu01
  /// Set the IP address associated with the endpoint.
184 2486 sjacqu01
  void address(const boost::asio::ip::address& addr)
185 2486 sjacqu01
  {
186 2486 sjacqu01
    impl_.address(addr);
187 2486 sjacqu01
  }
188 2486 sjacqu01
189 2486 sjacqu01
  /// Compare two endpoints for equality.
190 2486 sjacqu01
  friend bool operator==(const basic_endpoint<InternetProtocol>& e1,
191 2486 sjacqu01
      const basic_endpoint<InternetProtocol>& e2)
192 2486 sjacqu01
  {
193 2486 sjacqu01
    return e1.impl_ == e2.impl_;
194 2486 sjacqu01
  }
195 2486 sjacqu01
196 2486 sjacqu01
  /// Compare two endpoints for inequality.
197 2486 sjacqu01
  friend bool operator!=(const basic_endpoint<InternetProtocol>& e1,
198 2486 sjacqu01
      const basic_endpoint<InternetProtocol>& e2)
199 2486 sjacqu01
  {
200 2486 sjacqu01
    return !(e1 == e2);
201 2486 sjacqu01
  }
202 2486 sjacqu01
203 2486 sjacqu01
  /// Compare endpoints for ordering.
204 2486 sjacqu01
  friend bool operator<(const basic_endpoint<InternetProtocol>& e1,
205 2486 sjacqu01
      const basic_endpoint<InternetProtocol>& e2)
206 2486 sjacqu01
  {
207 2486 sjacqu01
    return e1.impl_ < e2.impl_;
208 2486 sjacqu01
  }
209 2486 sjacqu01
210 2486 sjacqu01
  /// Compare endpoints for ordering.
211 2486 sjacqu01
  friend bool operator>(const basic_endpoint<InternetProtocol>& e1,
212 2486 sjacqu01
      const basic_endpoint<InternetProtocol>& e2)
213 2486 sjacqu01
  {
214 2486 sjacqu01
    return e2.impl_ < e1.impl_;
215 2486 sjacqu01
  }
216 2486 sjacqu01
217 2486 sjacqu01
  /// Compare endpoints for ordering.
218 2486 sjacqu01
  friend bool operator<=(const basic_endpoint<InternetProtocol>& e1,
219 2486 sjacqu01
      const basic_endpoint<InternetProtocol>& e2)
220 2486 sjacqu01
  {
221 2486 sjacqu01
    return !(e2 < e1);
222 2486 sjacqu01
  }
223 2486 sjacqu01
224 2486 sjacqu01
  /// Compare endpoints for ordering.
225 2486 sjacqu01
  friend bool operator>=(const basic_endpoint<InternetProtocol>& e1,
226 2486 sjacqu01
      const basic_endpoint<InternetProtocol>& e2)
227 2486 sjacqu01
  {
228 2486 sjacqu01
    return !(e1 < e2);
229 2486 sjacqu01
  }
230 2486 sjacqu01
231 2486 sjacqu01
private:
232 2486 sjacqu01
  // The underlying IP endpoint.
233 2486 sjacqu01
  boost::asio::ip::detail::endpoint impl_;
234 2486 sjacqu01
};
235 2486 sjacqu01
236 2486 sjacqu01
#if !defined(BOOST_ASIO_NO_IOSTREAM)
237 2486 sjacqu01
238 2486 sjacqu01
/// Output an endpoint as a string.
239 2486 sjacqu01
/**
240 2486 sjacqu01
 * Used to output a human-readable string for a specified endpoint.
241 2486 sjacqu01
 *
242 2486 sjacqu01
 * @param os The output stream to which the string will be written.
243 2486 sjacqu01
 *
244 2486 sjacqu01
 * @param endpoint The endpoint to be written.
245 2486 sjacqu01
 *
246 2486 sjacqu01
 * @return The output stream.
247 2486 sjacqu01
 *
248 2486 sjacqu01
 * @relates boost::asio::ip::basic_endpoint
249 2486 sjacqu01
 */
250 2486 sjacqu01
template <typename Elem, typename Traits, typename InternetProtocol>
251 2486 sjacqu01
std::basic_ostream<Elem, Traits>& operator<<(
252 2486 sjacqu01
    std::basic_ostream<Elem, Traits>& os,
253 2486 sjacqu01
    const basic_endpoint<InternetProtocol>& endpoint);
254 2486 sjacqu01
255 2486 sjacqu01
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
256 2486 sjacqu01
257 2486 sjacqu01
} // namespace ip
258 2486 sjacqu01
} // namespace asio
259 2486 sjacqu01
} // namespace boost
260 2486 sjacqu01
261 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
262 2486 sjacqu01
263 2486 sjacqu01
#include <boost/asio/ip/impl/basic_endpoint.hpp>
264 2486 sjacqu01
265 2486 sjacqu01
#endif // BOOST_ASIO_IP_BASIC_ENDPOINT_HPP