mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Refactor and fix some object arithmetic comparisons
This commit is contained in:
@@ -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