Realistic 3D camera system
3D camera system components
endpoint.hpp
Go to the documentation of this file.
1 //
2 // ip/detail/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_DETAIL_ENDPOINT_HPP
12 #define ASIO_IP_DETAIL_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 <string>
22 #include "asio/error_code.hpp"
23 #include "asio/ip/address.hpp"
24 
26 
27 namespace asio {
28 namespace ip {
29 namespace detail {
30 
31 // Helper class for implementating an IP endpoint.
32 class endpoint
33 {
34 public:
35  // Default constructor.
37 
38  // Construct an endpoint using a family and port number.
39  ASIO_DECL endpoint(int family, unsigned short port_num);
40 
41  // Construct an endpoint using an address and port number.
43  unsigned short port_num);
44 
45  // Copy constructor.
46  endpoint(const endpoint& other)
47  : data_(other.data_)
48  {
49  }
50 
51  // Assign from another endpoint.
52  endpoint& operator=(const endpoint& other)
53  {
54  data_ = other.data_;
55  return *this;
56  }
57 
58  // Get the underlying endpoint in the native type.
60  {
61  return &data_.base;
62  }
63 
64  // Get the underlying endpoint in the native type.
66  {
67  return &data_.base;
68  }
69 
70  // Get the underlying size of the endpoint in the native type.
71  std::size_t size() const
72  {
73  if (is_v4())
74  return sizeof(asio::detail::sockaddr_in4_type);
75  else
76  return sizeof(asio::detail::sockaddr_in6_type);
77  }
78 
79  // Set the underlying size of the endpoint in the native type.
80  ASIO_DECL void resize(std::size_t new_size);
81 
82  // Get the capacity of the endpoint in the native type.
83  std::size_t capacity() const
84  {
85  return sizeof(data_);
86  }
87 
88  // Get the port associated with the endpoint.
89  ASIO_DECL unsigned short port() const;
90 
91  // Set the port associated with the endpoint.
92  ASIO_DECL void port(unsigned short port_num);
93 
94  // Get the IP address associated with the endpoint.
96 
97  // Set the IP address associated with the endpoint.
98  ASIO_DECL void address(const asio::ip::address& addr);
99 
100  // Compare two endpoints for equality.
101  ASIO_DECL friend bool operator==(
102  const endpoint& e1, const endpoint& e2);
103 
104  // Compare endpoints for ordering.
105  ASIO_DECL friend bool operator<(
106  const endpoint& e1, const endpoint& e2);
107 
108  // Determine whether the endpoint is IPv4.
109  bool is_v4() const
110  {
111  return data_.base.sa_family == ASIO_OS_DEF(AF_INET);
112  }
113 
114 #if !defined(ASIO_NO_IOSTREAM)
115  // Convert to a string.
116  ASIO_DECL std::string to_string(asio::error_code& ec) const;
117 #endif // !defined(ASIO_NO_IOSTREAM)
118 
119 private:
120  // The underlying IP socket address.
121  union data_union
122  {
126  } data_;
127 };
128 
129 } // namespace detail
130 } // namespace ip
131 } // namespace asio
132 
134 
135 #if defined(ASIO_HEADER_ONLY)
137 #endif // defined(ASIO_HEADER_ONLY)
138 
139 #endif // ASIO_IP_DETAIL_ENDPOINT_HPP
endpoint & operator=(const endpoint &other)
Definition: endpoint.hpp:52
ASIO_DECL friend bool operator==(const endpoint &e1, const endpoint &e2)
Definition: endpoint.ipp:165
ASIO_DECL asio::ip::address address() const
Definition: endpoint.ipp:138
asio::detail::socket_addr_type * data()
Definition: endpoint.hpp:59
#define ASIO_OS_DEF(c)
sockaddr_in sockaddr_in4_type
ASIO_DECL std::string to_string(asio::error_code &ec) const
Definition: endpoint.ipp:180
sockaddr socket_addr_type
const asio::detail::socket_addr_type * data() const
Definition: endpoint.hpp:65
ASIO_DECL friend bool operator<(const endpoint &e1, const endpoint &e2)
Definition: endpoint.ipp:170
Implements version-independent IP addresses.
Definition: address.hpp:42
ASIO_DECL unsigned short port() const
Definition: endpoint.ipp:110
Class to represent an error code value.
Definition: error_code.hpp:80
#define ASIO_DECL
Definition: config.hpp:43
std::size_t capacity() const
Definition: endpoint.hpp:83
std::size_t size() const
Definition: endpoint.hpp:71
sockaddr_in6 sockaddr_in6_type
ASIO_DECL void resize(std::size_t new_size)
Definition: endpoint.ipp:101
endpoint(const endpoint &other)
Definition: endpoint.hpp:46