mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-30 16:05:51 +00:00
Refactor and fix some object arithmetic comparisons
This commit is contained in:
@@ -334,7 +334,6 @@ private:
|
||||
|
||||
/** 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);
|
||||
@@ -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);
|
||||
|
||||
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);
|
||||
|
||||
@@ -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)
|
||||
return -1;
|
||||
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;
|
||||
|
||||
if (lhs.type() != rhs.type())
|
||||
return false;
|
||||
switch (lhs.type())
|
||||
{
|
||||
case IPAddress::none: return 0;
|
||||
case IPAddress::ipv4: return compare (lhs.v4(), rhs.v4());
|
||||
default:
|
||||
case IPAddress::none: return true;
|
||||
case IPAddress::ipv4: return lhs.v4() == rhs.v4();
|
||||
case IPAddress::ipv6:
|
||||
break;
|
||||
};
|
||||
bassertfalse;
|
||||
return 0;
|
||||
default:
|
||||
bassertfalse;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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; }
|
||||
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; }
|
||||
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; }
|
||||
bool operator< (IPAddress const& lhs, IPAddress const& rhs)
|
||||
{
|
||||
if (lhs.type() > rhs.type())
|
||||
return false;
|
||||
if (lhs.type() < rhs.type())
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,6 @@ struct Port
|
||||
SSLContext* context;
|
||||
};
|
||||
|
||||
int compare (Port const& lhs, Port const& rhs);
|
||||
bool operator== (Port const& lhs, Port const& rhs);
|
||||
bool operator!= (Port const& lhs, Port const& rhs);
|
||||
bool operator< (Port const& lhs, Port const& rhs);
|
||||
|
||||
@@ -56,35 +56,50 @@ Port::Port (
|
||||
{
|
||||
}
|
||||
|
||||
int compare (Port const& lhs, Port const& rhs)
|
||||
bool operator== (Port const& lhs, Port const& rhs)
|
||||
{
|
||||
int comp;
|
||||
|
||||
comp = compare (lhs.addr, rhs.addr);
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
|
||||
if (lhs.port < rhs.port)
|
||||
return -1;
|
||||
else if (lhs.port > rhs.port)
|
||||
return 1;
|
||||
|
||||
if (lhs.security < rhs.security)
|
||||
return -1;
|
||||
else if (lhs.security > rhs.security)
|
||||
return 1;
|
||||
|
||||
if (lhs.addr != rhs.addr)
|
||||
return false;
|
||||
if (lhs.port != rhs.port)
|
||||
return false;
|
||||
if (lhs.security != rhs.security)
|
||||
return false;
|
||||
// 'context' does not participate in the comparison
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator== (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) == 0; }
|
||||
bool operator!= (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) != 0; }
|
||||
bool operator< (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) < 0; }
|
||||
bool operator<= (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) <= 0; }
|
||||
bool operator> (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) > 0; }
|
||||
bool operator>= (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) >= 0; }
|
||||
bool operator< (Port const& lhs, Port const& rhs)
|
||||
{
|
||||
if (lhs.addr > rhs.addr)
|
||||
return false;
|
||||
else if (lhs.addr < rhs.addr)
|
||||
return true;
|
||||
|
||||
if (lhs.port > rhs.port)
|
||||
return false;
|
||||
else if (lhs.port < rhs.port)
|
||||
return true;
|
||||
|
||||
if (lhs.security > rhs.security)
|
||||
return false;
|
||||
else if (lhs.security < rhs.security)
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!= (Port const& lhs, Port const& rhs)
|
||||
{ return ! (lhs == rhs); }
|
||||
|
||||
bool operator> (Port const& lhs, Port const& rhs)
|
||||
{ return rhs < lhs; }
|
||||
|
||||
bool operator<= (Port const& lhs, Port const& rhs)
|
||||
{ return ! (rhs < lhs); }
|
||||
|
||||
bool operator>= (Port const& lhs, Port const& rhs)
|
||||
{ return ! (lhs < rhs); }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,16 @@ void ServerImpl::remove (Door& door)
|
||||
//
|
||||
// Thread
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
int ServerImpl::compare (Port const& lhs, Port const& rhs)
|
||||
{
|
||||
if (lhs < rhs)
|
||||
return -1;
|
||||
else if (lhs > rhs)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Updates our Door list based on settings.
|
||||
//
|
||||
|
||||
@@ -72,8 +72,11 @@ public:
|
||||
void handle_update ();
|
||||
void update ();
|
||||
void run ();
|
||||
|
||||
static int compare (Port const& lhs, Port const& rhs);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user