Realistic 3D camera system
3D camera system components
address_v4.hpp
Go to the documentation of this file.
1 //
2 // ip/address_v4.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_ADDRESS_V4_HPP
12 #define ASIO_IP_ADDRESS_V4_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>
20 #include "asio/detail/array.hpp"
23 #include "asio/error_code.hpp"
24 
25 #if !defined(ASIO_NO_IOSTREAM)
26 # include <iosfwd>
27 #endif // !defined(ASIO_NO_IOSTREAM)
28 
30 
31 namespace asio {
32 namespace ip {
33 
35 
44 {
45 public:
47 
51 #if defined(GENERATING_DOCUMENTATION)
52  typedef array<unsigned char, 4> bytes_type;
53 #else
55 #endif
56 
59  {
60  addr_.s_addr = 0;
61  }
62 
64  ASIO_DECL explicit address_v4(const bytes_type& bytes);
65 
67  ASIO_DECL explicit address_v4(unsigned long addr);
68 
70  address_v4(const address_v4& other)
71  : addr_(other.addr_)
72  {
73  }
74 
75 #if defined(ASIO_HAS_MOVE)
76  address_v4(address_v4&& other)
78  : addr_(other.addr_)
79  {
80  }
81 #endif // defined(ASIO_HAS_MOVE)
82 
84  address_v4& operator=(const address_v4& other)
85  {
86  addr_ = other.addr_;
87  return *this;
88  }
89 
90 #if defined(ASIO_HAS_MOVE)
91  address_v4& operator=(address_v4&& other)
93  {
94  addr_ = other.addr_;
95  return *this;
96  }
97 #endif // defined(ASIO_HAS_MOVE)
98 
100  ASIO_DECL bytes_type to_bytes() const;
101 
103  ASIO_DECL unsigned long to_ulong() const;
104 
106  ASIO_DECL std::string to_string() const;
107 
109  ASIO_DECL std::string to_string(asio::error_code& ec) const;
110 
112  ASIO_DECL static address_v4 from_string(const char* str);
113 
115  ASIO_DECL static address_v4 from_string(
116  const char* str, asio::error_code& ec);
117 
119  ASIO_DECL static address_v4 from_string(const std::string& str);
120 
122  ASIO_DECL static address_v4 from_string(
123  const std::string& str, asio::error_code& ec);
124 
126  ASIO_DECL bool is_loopback() const;
127 
129  ASIO_DECL bool is_unspecified() const;
130 
132  ASIO_DECL bool is_class_a() const;
133 
135  ASIO_DECL bool is_class_b() const;
136 
138  ASIO_DECL bool is_class_c() const;
139 
141  ASIO_DECL bool is_multicast() const;
142 
144  friend bool operator==(const address_v4& a1, const address_v4& a2)
145  {
146  return a1.addr_.s_addr == a2.addr_.s_addr;
147  }
148 
150  friend bool operator!=(const address_v4& a1, const address_v4& a2)
151  {
152  return a1.addr_.s_addr != a2.addr_.s_addr;
153  }
154 
156  friend bool operator<(const address_v4& a1, const address_v4& a2)
157  {
158  return a1.to_ulong() < a2.to_ulong();
159  }
160 
162  friend bool operator>(const address_v4& a1, const address_v4& a2)
163  {
164  return a1.to_ulong() > a2.to_ulong();
165  }
166 
168  friend bool operator<=(const address_v4& a1, const address_v4& a2)
169  {
170  return a1.to_ulong() <= a2.to_ulong();
171  }
172 
174  friend bool operator>=(const address_v4& a1, const address_v4& a2)
175  {
176  return a1.to_ulong() >= a2.to_ulong();
177  }
178 
180  static address_v4 any()
181  {
182  return address_v4();
183  }
184 
186  static address_v4 loopback()
187  {
188  return address_v4(0x7F000001);
189  }
190 
192  static address_v4 broadcast()
193  {
194  return address_v4(0xFFFFFFFF);
195  }
196 
199  ASIO_DECL static address_v4 broadcast(
200  const address_v4& addr, const address_v4& mask);
201 
204  ASIO_DECL static address_v4 netmask(const address_v4& addr);
205 
206 private:
207  // The underlying IPv4 address.
209 };
210 
211 #if !defined(ASIO_NO_IOSTREAM)
212 
214 
225 template <typename Elem, typename Traits>
226 std::basic_ostream<Elem, Traits>& operator<<(
227  std::basic_ostream<Elem, Traits>& os, const address_v4& addr);
228 
229 #endif // !defined(ASIO_NO_IOSTREAM)
230 
231 } // namespace ip
232 } // namespace asio
233 
235 
237 #if defined(ASIO_HEADER_ONLY)
238 # include "asio/ip/impl/address_v4.ipp"
239 #endif // defined(ASIO_HEADER_ONLY)
240 
241 #endif // ASIO_IP_ADDRESS_V4_HPP
in_addr in4_addr_type
friend bool operator>(const address_v4 &a1, const address_v4 &a2)
Compare addresses for ordering.
Definition: address_v4.hpp:162
static ASIO_DECL address_v4 netmask(const address_v4 &addr)
Definition: address_v4.ipp:162
friend bool operator==(const address_v4 &a1, const address_v4 &a2)
Compare two addresses for equality.
Definition: address_v4.hpp:144
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &os, const address_v4 &addr)
Output an address as a string.
Definition: address_v4.hpp:28
asio::detail::array< unsigned char, 4 > bytes_type
The type used to represent an address as an array of bytes.
Definition: address_v4.hpp:54
ASIO_DECL bool is_multicast() const
Determine whether the address is a multicast address.
Definition: address_v4.ipp:152
ASIO_DECL unsigned long to_ulong() const
Get the address as an unsigned long in host byte order.
Definition: address_v4.ipp:73
static address_v4 broadcast()
Obtain an address object that represents the broadcast address.
Definition: address_v4.hpp:192
Implements IP version 4 style addresses.
Definition: address_v4.hpp:43
address_v4()
Default constructor.
Definition: address_v4.hpp:58
ASIO_DECL bool is_class_b() const
Determine whether the address is a class B address.
Definition: address_v4.ipp:142
friend bool operator!=(const address_v4 &a1, const address_v4 &a2)
Compare two addresses for inequality.
Definition: address_v4.hpp:150
friend bool operator<(const address_v4 &a1, const address_v4 &a2)
Compare addresses for ordering.
Definition: address_v4.hpp:156
ASIO_DECL bool is_unspecified() const
Determine whether the address is unspecified.
Definition: address_v4.ipp:132
friend bool operator<=(const address_v4 &a1, const address_v4 &a2)
Compare addresses for ordering.
Definition: address_v4.hpp:168
static ASIO_DECL address_v4 from_string(const char *str)
Create an address from an IP address string in dotted decimal form.
Definition: address_v4.ipp:98
ASIO_DECL std::string to_string() const
Get the address as a string in dotted decimal format.
Definition: address_v4.ipp:78
static address_v4 loopback()
Obtain an address object that represents the loopback address.
Definition: address_v4.hpp:186
ASIO_DECL bytes_type to_bytes() const
Get the address in bytes, in network byte order.
Definition: address_v4.ipp:61
address_v4(const address_v4 &other)
Copy constructor.
Definition: address_v4.hpp:70
ASIO_DECL bool is_class_c() const
Determine whether the address is a class C address.
Definition: address_v4.ipp:147
ASIO_DECL bool is_class_a() const
Determine whether the address is a class A address.
Definition: address_v4.ipp:137
Class to represent an error code value.
Definition: error_code.hpp:80
#define ASIO_DECL
Definition: config.hpp:43
friend bool operator>=(const address_v4 &a1, const address_v4 &a2)
Compare addresses for ordering.
Definition: address_v4.hpp:174
ASIO_DECL bool is_loopback() const
Determine whether the address is a loopback address.
Definition: address_v4.ipp:127
static address_v4 any()
Obtain an address object that represents any address.
Definition: address_v4.hpp:180
address_v4 & operator=(const address_v4 &other)
Assign from another address.
Definition: address_v4.hpp:84