Clementine
basic_endpoint.hpp
1 //
2 // ip/basic_endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_IP_BASIC_ENDPOINT_HPP
12 #define ASIO_IP_BASIC_ENDPOINT_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/ip/address.hpp"
20 #include "asio/ip/detail/endpoint.hpp"
21 
22 #if !defined(ASIO_NO_IOSTREAM)
23 # include <iosfwd>
24 #endif // !defined(ASIO_NO_IOSTREAM)
25 
26 #include "asio/detail/push_options.hpp"
27 
28 namespace asio {
29 namespace ip {
30 
32 
43 template <typename InternetProtocol>
45 {
46 public:
48  typedef InternetProtocol protocol_type;
49 
52 #if defined(GENERATING_DOCUMENTATION)
53  typedef implementation_defined data_type;
54 #else
55  typedef asio::detail::socket_addr_type data_type;
56 #endif
57 
59  basic_endpoint() ASIO_NOEXCEPT
60  : impl_()
61  {
62  }
63 
68 
80  basic_endpoint(const InternetProtocol& internet_protocol,
81  unsigned short port_num) ASIO_NOEXCEPT
82  : impl_(internet_protocol.family(), port_num)
83  {
84  }
85 
90  unsigned short port_num) ASIO_NOEXCEPT
91  : impl_(addr, port_num)
92  {
93  }
94 
96  basic_endpoint(const basic_endpoint& other) ASIO_NOEXCEPT
97  : impl_(other.impl_)
98  {
99  }
100 
101 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
102  basic_endpoint(basic_endpoint&& other) ASIO_NOEXCEPT
104  : impl_(other.impl_)
105  {
106  }
107 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
108 
110  basic_endpoint& operator=(const basic_endpoint& other) ASIO_NOEXCEPT
111  {
112  impl_ = other.impl_;
113  return *this;
114  }
115 
116 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
117  basic_endpoint& operator=(basic_endpoint&& other) ASIO_NOEXCEPT
119  {
120  impl_ = other.impl_;
121  return *this;
122  }
123 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
124 
126  protocol_type protocol() const ASIO_NOEXCEPT
127  {
128  if (impl_.is_v4())
129  return InternetProtocol::v4();
130  return InternetProtocol::v6();
131  }
132 
134  data_type* data() ASIO_NOEXCEPT
135  {
136  return impl_.data();
137  }
138 
140  const data_type* data() const ASIO_NOEXCEPT
141  {
142  return impl_.data();
143  }
144 
146  std::size_t size() const ASIO_NOEXCEPT
147  {
148  return impl_.size();
149  }
150 
152  void resize(std::size_t new_size)
153  {
154  impl_.resize(new_size);
155  }
156 
158  std::size_t capacity() const ASIO_NOEXCEPT
159  {
160  return impl_.capacity();
161  }
162 
165  unsigned short port() const ASIO_NOEXCEPT
166  {
167  return impl_.port();
168  }
169 
172  void port(unsigned short port_num) ASIO_NOEXCEPT
173  {
174  impl_.port(port_num);
175  }
176 
178  asio::ip::address address() const ASIO_NOEXCEPT
179  {
180  return impl_.address();
181  }
182 
184  void address(const asio::ip::address& addr) ASIO_NOEXCEPT
185  {
186  impl_.address(addr);
187  }
188 
191  const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT
192  {
193  return e1.impl_ == e2.impl_;
194  }
195 
198  const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT
199  {
200  return !(e1 == e2);
201  }
202 
204  friend bool operator<(const basic_endpoint<InternetProtocol>& e1,
205  const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT
206  {
207  return e1.impl_ < e2.impl_;
208  }
209 
212  const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT
213  {
214  return e2.impl_ < e1.impl_;
215  }
216 
218  friend bool operator<=(const basic_endpoint<InternetProtocol>& e1,
219  const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT
220  {
221  return !(e2 < e1);
222  }
223 
226  const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT
227  {
228  return !(e1 < e2);
229  }
230 
231 private:
232  // The underlying IP endpoint.
234 };
235 
236 #if !defined(ASIO_NO_IOSTREAM)
237 
239 
250 template <typename Elem, typename Traits, typename InternetProtocol>
251 std::basic_ostream<Elem, Traits>& operator<<(
252  std::basic_ostream<Elem, Traits>& os,
253  const basic_endpoint<InternetProtocol>& endpoint);
254 
255 #endif // !defined(ASIO_NO_IOSTREAM)
256 
257 } // namespace ip
258 } // namespace asio
259 
260 #include "asio/detail/pop_options.hpp"
261 
262 #include "asio/ip/impl/basic_endpoint.hpp"
263 
264 #endif // ASIO_IP_BASIC_ENDPOINT_HPP
Describes an endpoint for a version-independent IP socket.
Definition: basic_endpoint.hpp:44
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &os, const basic_endpoint< InternetProtocol > &endpoint)
Output an endpoint as a string.
Definition: basic_endpoint.hpp:28
InternetProtocol protocol_type
The protocol type associated with the endpoint.
Definition: basic_endpoint.hpp:48
data_type * data() ASIO_NOEXCEPT
Get the underlying endpoint in the native type.
Definition: basic_endpoint.hpp:134
const data_type * data() const ASIO_NOEXCEPT
Get the underlying endpoint in the native type.
Definition: basic_endpoint.hpp:140
basic_endpoint(const InternetProtocol &internet_protocol, unsigned short port_num) ASIO_NOEXCEPT
Construct an endpoint using a port number, specified in the host&#39;s byte order.
Definition: basic_endpoint.hpp:80
friend bool operator==(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2) ASIO_NOEXCEPT
Compare two endpoints for equality.
Definition: basic_endpoint.hpp:190
friend bool operator!=(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2) ASIO_NOEXCEPT
Compare two endpoints for inequality.
Definition: basic_endpoint.hpp:197
void resize(std::size_t new_size)
Set the underlying size of the endpoint in the native type.
Definition: basic_endpoint.hpp:152
Implements version-independent IP addresses.
Definition: address.hpp:46
basic_endpoint & operator=(const basic_endpoint &other) ASIO_NOEXCEPT
Assign from another endpoint.
Definition: basic_endpoint.hpp:110
asio::detail::socket_addr_type data_type
The type of the endpoint structure.
Definition: basic_endpoint.hpp:55
friend bool operator>(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2) ASIO_NOEXCEPT
Compare endpoints for ordering.
Definition: basic_endpoint.hpp:211
Definition: endpoint.hpp:32
basic_endpoint(const basic_endpoint &other) ASIO_NOEXCEPT
Copy constructor.
Definition: basic_endpoint.hpp:96
std::size_t size() const ASIO_NOEXCEPT
Get the underlying size of the endpoint in the native type.
Definition: basic_endpoint.hpp:146
unsigned short port() const ASIO_NOEXCEPT
Get the port associated with the endpoint.
Definition: basic_endpoint.hpp:165
protocol_type protocol() const ASIO_NOEXCEPT
The protocol associated with the endpoint.
Definition: basic_endpoint.hpp:126
void port(unsigned short port_num) ASIO_NOEXCEPT
Set the port associated with the endpoint.
Definition: basic_endpoint.hpp:172
void address(const asio::ip::address &addr) ASIO_NOEXCEPT
Set the IP address associated with the endpoint.
Definition: basic_endpoint.hpp:184
Definition: any_io_executor.hpp:28
friend bool operator>=(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2) ASIO_NOEXCEPT
Compare endpoints for ordering.
Definition: basic_endpoint.hpp:225
std::size_t capacity() const ASIO_NOEXCEPT
Get the capacity of the endpoint in the native type.
Definition: basic_endpoint.hpp:158
basic_endpoint(const asio::ip::address &addr, unsigned short port_num) ASIO_NOEXCEPT
Construct an endpoint using a port number and an IP address.
Definition: basic_endpoint.hpp:89
asio::ip::address address() const ASIO_NOEXCEPT
Get the IP address associated with the endpoint.
Definition: basic_endpoint.hpp:178
basic_endpoint() ASIO_NOEXCEPT
Default constructor.
Definition: basic_endpoint.hpp:59