Remove address_cast.

This commit is contained in:
Christopher Kohlhoff 2015-05-10 18:38:09 +10:00
parent 15803ab00b
commit c406fa7ce7
7 changed files with 7 additions and 127 deletions

View File

@ -90,13 +90,11 @@ public:
return type_ == ipv6;
}
#if !defined(ASIO_NO_DEPRECATED)
/// Get the address as an IP version 4 address.
ASIO_DECL asio::ip::address_v4 to_v4() const;
/// Get the address as an IP version 6 address.
ASIO_DECL asio::ip::address_v6 to_v6() const;
#endif // !defined(ASIO_NO_DEPRECATED)
/// Get the address as a string in dotted decimal format.
ASIO_DECL std::string to_string() const;
@ -167,18 +165,6 @@ public:
}
private:
// Helper function to get the underlying IPv4 address.
friend asio::ip::address_v4 get_v4_helper(const address& a)
{
return a.ipv4_address_;
}
// Helper function to get the underlying IPv4 address.
friend asio::ip::address_v6 get_v6_helper(const address& a)
{
return a.ipv6_address_;
}
// The type of the address.
enum { ipv4, ipv6 } type_;
@ -219,99 +205,6 @@ ASIO_DECL address make_address(const std::string& str);
ASIO_DECL address make_address(
const std::string& str, asio::error_code& ec);
/** @defgroup address_cast asio::ip::address_cast
*
* @brief The asio::ip::address_cast function is used to convert between
* address types.
*/
/*@{*/
/// Cast a version-independent address to itself.
template <typename T>
inline T address_cast(const address& addr,
typename enable_if<is_same<T, address>::value>::type* = 0)
{
return addr;
}
/// Cast a version-independent address to an IPv4 address.
/**
* @throws bad_address_cast if @c a does not represent an IPv4 address.
*/
template <typename T>
inline T address_cast(const address& addr,
typename enable_if<is_same<T, address_v4>::value>::type* = 0)
{
if (!addr.is_v4())
{
bad_address_cast ex;
asio::detail::throw_exception(ex);
}
return get_v4_helper(addr);
}
/// Cast a version-independent address to an IPv6 address.
/**
* @throws bad_address_cast if @c a does not represent an IPv6 address.
*/
template <typename T>
inline T address_cast(const address& addr,
typename enable_if<is_same<T, address_v6>::value>::type* = 0)
{
if (!addr.is_v6())
{
bad_address_cast ex;
asio::detail::throw_exception(ex);
}
return get_v6_helper(addr);
}
/// Cast an IPv4 address to a version-independent address.
template <typename T>
inline T address_cast(const address_v4& addr,
typename enable_if<is_same<T, address>::value>::type* = 0)
{
return address(addr);
}
/// Cast an IPv4 address to itself.
template <typename T>
inline T address_cast(const address_v4& addr,
typename enable_if<is_same<T, address_v4>::value>::type* = 0)
{
return addr;
}
/// Cast from IPv4 to IPV6 address is not permitted.
template <typename T>
bad_address_cast address_cast(const address_v4&,
typename enable_if<is_same<T, address_v6>::value>::type* = 0)
ASIO_DELETED;
/// Cast an IPv6 address to a version-independent address.
template <typename T>
inline T address_cast(const address_v6& addr,
typename enable_if<is_same<T, address>::value>::type* = 0)
{
return address(addr);
}
/// Cast an IPv6 address to itself.
template <typename T>
inline T address_cast(const address_v6& addr,
typename enable_if<is_same<T, address_v6>::value>::type* = 0)
{
return addr;
}
/// Cast from IPv6 to IPv4 address is not permitted.
template <typename T>
bad_address_cast address_cast(const address_v6&,
typename enable_if<is_same<T, address_v4>::value>::type* = 0)
ASIO_DELETED;
/*@}*/
#if !defined(ASIO_NO_IOSTREAM)
/// Output an address as a string.

View File

@ -80,8 +80,7 @@ endpoint::endpoint(const asio::ip::address& addr,
asio::detail::socket_ops::host_to_network_short(port_num);
data_.v4.sin_addr.s_addr =
asio::detail::socket_ops::host_to_network_long(
static_cast<asio::detail::u_long_type>(
address_cast<address_v4>(addr).to_ulong()));
addr.to_v4().to_ulong());
}
else
{
@ -89,7 +88,7 @@ endpoint::endpoint(const asio::ip::address& addr,
data_.v6.sin6_port =
asio::detail::socket_ops::host_to_network_short(port_num);
data_.v6.sin6_flowinfo = 0;
asio::ip::address_v6 v6_addr = address_cast<address_v6>(addr);
asio::ip::address_v6 v6_addr = addr.to_v6();
asio::ip::address_v6::bytes_type bytes = v6_addr.to_bytes();
memcpy(data_.v6.sin6_addr.s6_addr, bytes.data(), 16);
data_.v6.sin6_scope_id =

View File

@ -398,7 +398,7 @@ public:
if (multicast_address.is_v6())
{
using namespace std; // For memcpy.
address_v6 ipv6_address = address_cast<address_v6>(multicast_address);
address_v6 ipv6_address = multicast_address.to_v6();
address_v6::bytes_type bytes = ipv6_address.to_bytes();
memcpy(ipv6_value_.ipv6mr_multiaddr.s6_addr, bytes.data(), 16);
ipv6_value_.ipv6mr_interface = ipv6_address.scope_id();
@ -407,7 +407,7 @@ public:
{
ipv4_value_.imr_multiaddr.s_addr =
asio::detail::socket_ops::host_to_network_long(
address_cast<address_v4>(multicast_address).to_ulong());
multicast_address.to_v4().to_ulong());
ipv4_value_.imr_interface.s_addr =
asio::detail::socket_ops::host_to_network_long(
address_v4::any().to_ulong());

View File

@ -134,7 +134,6 @@ address make_address(const std::string& str,
return make_address(str.c_str(), ec);
}
#if !defined(ASIO_NO_DEPRECATED)
asio::ip::address_v4 address::to_v4() const
{
if (type_ != ipv4)
@ -154,7 +153,6 @@ asio::ip::address_v6 address::to_v6() const
}
return ipv6_address_;
}
#endif // !defined(ASIO_NO_DEPRECATED)
std::string address::to_string() const
{

View File

@ -78,8 +78,7 @@ bool rfc2818_verification::operator()(
{
if (address.is_v4() && ip_address->length == 4)
{
ip::address_v4::bytes_type bytes =
ip::address_cast<ip::address_v4>(address).to_bytes();
ip::address_v4::bytes_type bytes = address.to_v4().to_bytes();
if (memcmp(bytes.data(), ip_address->data, 4) == 0)
{
GENERAL_NAMES_free(gens);
@ -88,8 +87,7 @@ bool rfc2818_verification::operator()(
}
else if (address.is_v6() && ip_address->length == 16)
{
ip::address_v6::bytes_type bytes =
ip::address_cast<ip::address_v6>(address).to_bytes();
ip::address_v6::bytes_type bytes = address.to_v6().to_bytes();
if (memcmp(bytes.data(), ip_address->data, 16) == 0)
{
GENERAL_NAMES_free(gens);

View File

@ -48,8 +48,7 @@ public:
port_low_byte_ = port & 0xff;
// Save IP address in network byte order.
address_ = asio::ip::address_cast<asio::ip::address_v4>(
endpoint.address()).to_bytes();
address_ = endpoint.address().to_v4().to_bytes();
}
boost::array<asio::const_buffer, 7> buffers() const

View File

@ -105,13 +105,6 @@ void test()
addr1 = ip::make_address(string_value);
addr1 = ip::make_address(string_value, ec);
// address casts.
addr_v4_value = ip::address_cast<ip::address_v4>(addr1);
addr1 = ip::address_cast<ip::address>(addr_v4_value);
addr_v6_value = ip::address_cast<ip::address_v6>(addr1);
addr1 = ip::address_cast<ip::address>(addr_v6_value);
// address I/O.
std::ostringstream os;