mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
IPAddress fixes and algorithm comparison functors
This commit is contained in:
@@ -325,6 +325,18 @@ public:
|
|||||||
|
|
||||||
struct key_equal;
|
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:
|
private:
|
||||||
Type m_type;
|
Type m_type;
|
||||||
uint16 m_port;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -581,7 +581,12 @@ bool operator== (IPAddress const& lhs, IPAddress const& rhs)
|
|||||||
switch (lhs.type())
|
switch (lhs.type())
|
||||||
{
|
{
|
||||||
case IPAddress::none: return true;
|
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:
|
case IPAddress::ipv6:
|
||||||
default:
|
default:
|
||||||
bassertfalse;
|
bassertfalse;
|
||||||
@@ -598,7 +603,12 @@ bool operator< (IPAddress const& lhs, IPAddress const& rhs)
|
|||||||
switch (lhs.type())
|
switch (lhs.type())
|
||||||
{
|
{
|
||||||
case IPAddress::none: return true;
|
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:
|
case IPAddress::ipv6:
|
||||||
default:
|
default:
|
||||||
bassertfalse;
|
bassertfalse;
|
||||||
|
|||||||
Reference in New Issue
Block a user