IPAddress fixes and algorithm comparison functors

This commit is contained in:
Vinnie Falco
2013-11-30 06:36:41 -08:00
parent 130c7c5c58
commit 4c843b6c66
2 changed files with 36 additions and 2 deletions

View File

@@ -325,6 +325,18 @@ public:
struct key_equal;
/** LessThanComparable functor that ignores the port. */
struct LessWithoutPort
{
bool operator() (IPAddress const& lhs, IPAddress const& rhs) const;
};
/** EqualityComparable functor that ignores the port. */
struct EqualWithoutPort
{
bool operator() (IPAddress const& lhs, IPAddress const& rhs) const;
};
private:
Type m_type;
uint16 m_port;
@@ -370,6 +382,18 @@ struct IPAddress::key_equal
}
};
inline bool IPAddress::LessWithoutPort::operator() (
IPAddress const& lhs, IPAddress const& rhs) const
{
return lhs.withPort (0) < rhs.withPort (0);
}
inline bool IPAddress::EqualWithoutPort::operator() (
IPAddress const& lhs, IPAddress const& rhs) const
{
return lhs.withPort (0) == rhs.withPort (0);
}
}
//------------------------------------------------------------------------------

View File

@@ -581,7 +581,12 @@ bool operator== (IPAddress const& lhs, IPAddress const& rhs)
switch (lhs.type())
{
case IPAddress::none: return true;
case IPAddress::ipv4: return lhs.v4() == rhs.v4();
case IPAddress::ipv4:
if (lhs.v4() != rhs.v4())
return false;
if (lhs.port() != rhs.port())
return false;
return true;
case IPAddress::ipv6:
default:
bassertfalse;
@@ -598,7 +603,12 @@ bool operator< (IPAddress const& lhs, IPAddress const& rhs)
switch (lhs.type())
{
case IPAddress::none: return true;
case IPAddress::ipv4: return lhs.v4() < rhs.v4();
case IPAddress::ipv4:
if (lhs.v4() < rhs.v4())
return true;
if (lhs.v4() > rhs.v4())
return false;
return lhs.port() < rhs.port();
case IPAddress::ipv6:
default:
bassertfalse;