mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 05:55:51 +00:00
Refactor and fix some object arithmetic comparisons
This commit is contained in:
@@ -334,7 +334,6 @@ private:
|
|||||||
|
|
||||||
/** Comparison. */
|
/** Comparison. */
|
||||||
/** @{ */
|
/** @{ */
|
||||||
int compare (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
|
||||||
bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
||||||
bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
||||||
bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
||||||
@@ -342,7 +341,6 @@ bool operator<= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
|||||||
bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
||||||
bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs);
|
||||||
|
|
||||||
int compare (IPAddress const& lhs, IPAddress const& rhs);
|
|
||||||
bool operator== (IPAddress const& lhs, IPAddress const& rhs);
|
bool operator== (IPAddress const& lhs, IPAddress const& rhs);
|
||||||
bool operator!= (IPAddress const& lhs, IPAddress const& rhs);
|
bool operator!= (IPAddress const& lhs, IPAddress const& rhs);
|
||||||
bool operator< (IPAddress const& lhs, IPAddress const& rhs);
|
bool operator< (IPAddress const& lhs, IPAddress const& rhs);
|
||||||
|
|||||||
@@ -554,58 +554,71 @@ IPAddress IPAddress::from_string_altform (std::string const& s)
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
int compare (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
||||||
|
{ return lhs.value == rhs.value; }
|
||||||
|
|
||||||
|
bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
||||||
|
{ return lhs.value < rhs.value; }
|
||||||
|
|
||||||
|
bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
||||||
|
{ return ! (lhs == rhs); }
|
||||||
|
|
||||||
|
bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
||||||
|
{ return rhs < lhs; }
|
||||||
|
|
||||||
|
bool operator<= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
||||||
|
{ return ! (rhs < lhs); }
|
||||||
|
|
||||||
|
bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
|
||||||
|
{ return ! (lhs < rhs); }
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool operator== (IPAddress const& lhs, IPAddress const& rhs)
|
||||||
{
|
{
|
||||||
if (lhs.value < rhs.value)
|
if (lhs.type() != rhs.type())
|
||||||
return -1;
|
return false;
|
||||||
else if (lhs.value > rhs.value)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) == 0; }
|
|
||||||
bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) != 0; }
|
|
||||||
bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) < 0; }
|
|
||||||
bool operator<= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) <= 0; }
|
|
||||||
bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) > 0; }
|
|
||||||
bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) >= 0; }
|
|
||||||
|
|
||||||
static int type_compare (IPAddress const& lhs, IPAddress const& rhs)
|
|
||||||
{
|
|
||||||
if (lhs.type() < rhs.type())
|
|
||||||
return -1;
|
|
||||||
else if (lhs.type() > rhs.type())
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int compare (IPAddress const& lhs, IPAddress const& rhs)
|
|
||||||
{
|
|
||||||
int const tc (type_compare (lhs, rhs));
|
|
||||||
|
|
||||||
if (tc < 0)
|
|
||||||
return -1;
|
|
||||||
else if (tc > 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
switch (lhs.type())
|
switch (lhs.type())
|
||||||
{
|
{
|
||||||
case IPAddress::none: return 0;
|
case IPAddress::none: return true;
|
||||||
case IPAddress::ipv4: return compare (lhs.v4(), rhs.v4());
|
case IPAddress::ipv4: return lhs.v4() == rhs.v4();
|
||||||
default:
|
|
||||||
case IPAddress::ipv6:
|
case IPAddress::ipv6:
|
||||||
break;
|
default:
|
||||||
};
|
bassertfalse;
|
||||||
bassertfalse;
|
}
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator== (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) == 0; }
|
bool operator< (IPAddress const& lhs, IPAddress const& rhs)
|
||||||
bool operator!= (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) != 0; }
|
{
|
||||||
bool operator< (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) < 0; }
|
if (lhs.type() > rhs.type())
|
||||||
bool operator<= (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) <= 0; }
|
return false;
|
||||||
bool operator> (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) > 0; }
|
if (lhs.type() < rhs.type())
|
||||||
bool operator>= (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) >= 0; }
|
return true;
|
||||||
|
switch (lhs.type())
|
||||||
|
{
|
||||||
|
case IPAddress::none: return true;
|
||||||
|
case IPAddress::ipv4: return lhs.v4() < rhs.v4();
|
||||||
|
case IPAddress::ipv6:
|
||||||
|
default:
|
||||||
|
bassertfalse;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!= (IPAddress const& lhs, IPAddress const& rhs)
|
||||||
|
{ return ! (lhs == rhs); }
|
||||||
|
|
||||||
|
bool operator> (IPAddress const& lhs, IPAddress const& rhs)
|
||||||
|
{ return rhs < lhs; }
|
||||||
|
|
||||||
|
bool operator<= (IPAddress const& lhs, IPAddress const& rhs)
|
||||||
|
{ return ! (rhs < lhs); }
|
||||||
|
|
||||||
|
bool operator>= (IPAddress const& lhs, IPAddress const& rhs)
|
||||||
|
{ return ! (lhs < rhs); }
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream &os, IPAddress::V4 const& addr)
|
std::ostream& operator<< (std::ostream &os, IPAddress::V4 const& addr)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user