destructor call and some cleanup

This commit is contained in:
aleks-f
2013-01-24 23:34:40 -06:00
parent f9243c2073
commit 69f5d4e25e
2 changed files with 17 additions and 14 deletions

View File

@@ -86,10 +86,10 @@ public:
virtual unsigned prefixLength() const = 0; virtual unsigned prefixLength() const = 0;
virtual IPAddressImpl* clone() const = 0; virtual IPAddressImpl* clone() const = 0;
virtual ~IPAddressImpl();
protected: protected:
IPAddressImpl(); IPAddressImpl();
virtual ~IPAddressImpl();
private: private:
IPAddressImpl(const IPAddressImpl&); IPAddressImpl(const IPAddressImpl&);

View File

@@ -64,7 +64,7 @@ namespace Net {
IPAddress::IPAddress() IPAddress::IPAddress()
{ {
new ((void*) _memory) IPv4AddressImpl(); new (_memory) IPv4AddressImpl();
} }
@@ -80,10 +80,10 @@ IPAddress::IPAddress(const IPAddress& addr)
IPAddress::IPAddress(Family family) IPAddress::IPAddress(Family family)
{ {
if (family == IPv4) if (family == IPv4)
new ((void*) _memory) IPv4AddressImpl(); new (_memory) IPv4AddressImpl();
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
else if (family == IPv6) else if (family == IPv6)
new ((void*) _memory) IPv6AddressImpl(); new (_memory) IPv6AddressImpl();
#endif #endif
else else
throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
@@ -149,10 +149,10 @@ IPAddress::IPAddress(const std::string& addr, Family family)
IPAddress::IPAddress(const void* addr, poco_socklen_t length) IPAddress::IPAddress(const void* addr, poco_socklen_t length)
{ {
if (length == sizeof(struct in_addr)) if (length == sizeof(struct in_addr))
new ((void*) _memory) IPv4AddressImpl(addr); new (_memory) IPv4AddressImpl(addr);
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
else if (length == sizeof(struct in6_addr)) else if (length == sizeof(struct in6_addr))
new ((void*) _memory) IPv6AddressImpl(addr); new (_memory) IPv6AddressImpl(addr);
#endif #endif
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()"); else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
} }
@@ -161,10 +161,10 @@ IPAddress::IPAddress(const void* addr, poco_socklen_t length)
IPAddress::IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope) IPAddress::IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope)
{ {
if (length == sizeof(struct in_addr)) if (length == sizeof(struct in_addr))
new ((void*) _memory) IPv4AddressImpl(addr); new (_memory) IPv4AddressImpl(addr);
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
else if (length == sizeof(struct in6_addr)) else if (length == sizeof(struct in6_addr))
new ((void*) _memory) IPv6AddressImpl(addr, scope); new (_memory) IPv6AddressImpl(addr, scope);
#endif #endif
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()"); else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
} }
@@ -175,13 +175,13 @@ IPAddress::IPAddress(unsigned prefix, Family family)
if (family == IPv4) if (family == IPv4)
{ {
if (prefix <= 32) if (prefix <= 32)
new ((void*) _memory) IPv4AddressImpl(prefix); new (_memory) IPv4AddressImpl(prefix);
} }
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
else if (family == IPv6) else if (family == IPv6)
{ {
if (prefix <= 128) if (prefix <= 128)
new ((void*) _memory) IPv6AddressImpl(prefix); new (_memory) IPv6AddressImpl(prefix);
} }
#endif #endif
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
@@ -194,10 +194,11 @@ IPAddress::IPAddress(const SOCKET_ADDRESS& socket_address)
{ {
ADDRESS_FAMILY family = socket_address.lpSockaddr->sa_family; ADDRESS_FAMILY family = socket_address.lpSockaddr->sa_family;
if (family == AF_INET) if (family == AF_INET)
new ((void*) _memory) IPv4AddressImpl(&reinterpret_cast<const struct sockaddr_in*>(socket_address.lpSockaddr)->sin_addr); new (_memory) IPv4AddressImpl(&reinterpret_cast<const struct sockaddr_in*>(socket_address.lpSockaddr)->sin_addr);
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
else if (family == AF_INET6) else if (family == AF_INET6)
new ((void*) _memory) IPv6AddressImpl(&reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_addr, reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_scope_id); new (_memory) IPv6AddressImpl(&reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_addr,
reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_scope_id);
#endif #endif
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
} }
@@ -208,10 +209,11 @@ IPAddress::IPAddress(const struct sockaddr& sockaddr)
{ {
unsigned short family = sockaddr.sa_family; unsigned short family = sockaddr.sa_family;
if (family == AF_INET) if (family == AF_INET)
new ((void*) _memory) IPv4AddressImpl(&reinterpret_cast<const struct sockaddr_in*>(&sockaddr)->sin_addr); new (_memory) IPv4AddressImpl(&reinterpret_cast<const struct sockaddr_in*>(&sockaddr)->sin_addr);
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
else if (family == AF_INET6) else if (family == AF_INET6)
new ((void*) _memory) IPv6AddressImpl(&reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_addr, reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_scope_id); new (_memory) IPv6AddressImpl(&reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_addr,
reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_scope_id);
#endif #endif
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
} }
@@ -219,6 +221,7 @@ IPAddress::IPAddress(const struct sockaddr& sockaddr)
IPAddress::~IPAddress() IPAddress::~IPAddress()
{ {
pImpl()->~IPAddressImpl();
} }