Realistic 3D camera system
3D camera system components
basic_endpoint.hpp
Go to the documentation of this file.
1 //
2 // ip/basic_endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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"
21 
22 #if !defined(ASIO_NO_IOSTREAM)
23 # include <iosfwd>
24 #endif // !defined(ASIO_NO_IOSTREAM)
25 
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
56 #endif
57 
60  : impl_()
61  {
62  }
63 
68 
80  basic_endpoint(const InternetProtocol& internet_protocol,
81  unsigned short port_num)
82  : impl_(internet_protocol.family(), port_num)
83  {
84  }
85 
89  basic_endpoint(const asio::ip::address& addr, unsigned short port_num)
90  : impl_(addr, port_num)
91  {
92  }
93 
96  : impl_(other.impl_)
97  {
98  }
99 
100 #if defined(ASIO_HAS_MOVE)
103  : impl_(other.impl_)
104  {
105  }
106 #endif // defined(ASIO_HAS_MOVE)
107 
110  {
111  impl_ = other.impl_;
112  return *this;
113  }
114 
115 #if defined(ASIO_HAS_MOVE)
118  {
119  impl_ = other.impl_;
120  return *this;
121  }
122 #endif // defined(ASIO_HAS_MOVE)
123 
125  protocol_type protocol() const
126  {
127  if (impl_.is_v4())
128  return InternetProtocol::v4();
129  return InternetProtocol::v6();
130  }
131 
133  data_type* data()
134  {
135  return impl_.data();
136  }
137 
139  const data_type* data() const
140  {
141  return impl_.data();
142  }
143 
145  std::size_t size() const
146  {
147  return impl_.size();
148  }
149 
151  void resize(std::size_t new_size)
152  {
153  impl_.resize(new_size);
154  }
155 
157  std::size_t capacity() const
158  {
159  return impl_.capacity();
160  }
161 
164  unsigned short port() const
165  {
166  return impl_.port();
167  }
168 
171  void port(unsigned short port_num)
172  {
173  impl_.port(port_num);
174  }
175 
178  {
179  return impl_.address();
180  }
181 
183  void address(const asio::ip::address& addr)
184  {
185  impl_.address(addr);
186  }
187 
191  {
192  return e1.impl_ == e2.impl_;
193  }
194 
198  {
199  return !(e1 == e2);
200  }
201 
203  friend bool operator<(const basic_endpoint<InternetProtocol>& e1,
205  {
206  return e1.impl_ < e2.impl_;
207  }
208 
212  {
213  return e2.impl_ < e1.impl_;
214  }
215 
217  friend bool operator<=(const basic_endpoint<InternetProtocol>& e1,
219  {
220  return !(e2 < e1);
221  }
222 
226  {
227  return !(e1 < e2);
228  }
229 
230 private:
231  // The underlying IP endpoint.
233 };
234 
235 #if !defined(ASIO_NO_IOSTREAM)
236 
238 
249 template <typename Elem, typename Traits, typename InternetProtocol>
250 std::basic_ostream<Elem, Traits>& operator<<(
251  std::basic_ostream<Elem, Traits>& os,
252  const basic_endpoint<InternetProtocol>& endpoint);
253 
254 #endif // !defined(ASIO_NO_IOSTREAM)
255 
256 } // namespace ip
257 } // namespace asio
258 
260 
262 
263 #endif // ASIO_IP_BASIC_ENDPOINT_HPP
std::size_t capacity() const
Get the capacity of the endpoint in the native type.
basic_endpoint(const InternetProtocol &internet_protocol, unsigned short port_num)
Describes an endpoint for a version-independent IP socket.
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &os, const basic_endpoint< InternetProtocol > &endpoint)
Output an endpoint as a string.
void address(const asio::ip::address &addr)
Set the IP address associated with the endpoint.
protocol_type protocol() const
The protocol associated with the endpoint.
ASIO_DECL asio::ip::address address() const
Definition: endpoint.ipp:138
asio::detail::socket_addr_type * data()
Definition: endpoint.hpp:59
InternetProtocol protocol_type
The protocol type associated with the endpoint.
friend bool operator>=(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2)
Compare endpoints for ordering.
basic_endpoint(const asio::ip::address &addr, unsigned short port_num)
sockaddr socket_addr_type
data_type * data()
Get the underlying endpoint in the native type.
friend bool operator>(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2)
Compare endpoints for ordering.
asio::ip::address address() const
Get the IP address associated with the endpoint.
friend bool operator!=(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2)
Compare two endpoints for inequality.
friend bool operator==(const basic_endpoint< InternetProtocol > &e1, const basic_endpoint< InternetProtocol > &e2)
Compare two endpoints for equality.
unsigned short port() const
void resize(std::size_t new_size)
Set the underlying size of the endpoint in the native type.
Implements version-independent IP addresses.
Definition: address.hpp:42
asio::detail::socket_addr_type data_type
ASIO_DECL unsigned short port() const
Definition: endpoint.ipp:110
const data_type * data() const
Get the underlying endpoint in the native type.
std::size_t capacity() const
Definition: endpoint.hpp:83
void port(unsigned short port_num)
std::size_t size() const
Definition: endpoint.hpp:71
basic_endpoint(const basic_endpoint &other)
Copy constructor.
std::size_t size() const
Get the underlying size of the endpoint in the native type.
basic_endpoint()
Default constructor.
ASIO_DECL void resize(std::size_t new_size)
Definition: endpoint.ipp:101
basic_endpoint & operator=(const basic_endpoint &other)
Assign from another endpoint.