refs #104 replaced all remaining hash-based comparisons with the multimethod compare()

This commit is contained in:
Mathew Sutcliffe
2014-02-17 15:39:01 +00:00
parent dd4e2c58f3
commit 2dd72c6d3e
6 changed files with 30 additions and 10 deletions

View File

@@ -97,7 +97,7 @@ namespace BlackMisc
bool CAircraft::operator ==(const CAircraft &other) const bool CAircraft::operator ==(const CAircraft &other) const
{ {
if (this == &other) return true; if (this == &other) return true;
return this->getValueHash() == other.getValueHash(); return compare(*this, other) == 0;
} }
/* /*

View File

@@ -100,7 +100,7 @@ namespace BlackMisc
bool CAircraftIcao::operator ==(const CAircraftIcao &other) const bool CAircraftIcao::operator ==(const CAircraftIcao &other) const
{ {
if (this == &other) return true; if (this == &other) return true;
return this->getValueHash() == other.getValueHash(); return compare(*this, other) == 0;
} }
/* /*

View File

@@ -44,9 +44,19 @@ namespace BlackMisc
/* /*
* Compare * Compare
*/ */
int CAircraftSituation::compareImpl(const CValueObject &/*otherBase*/) const int CAircraftSituation::compareImpl(const CValueObject &otherBase) const
{ {
qFatal("not implemented"); const auto &other = static_cast<const CAircraftSituation &>(otherBase);
int result;
if ((result = compare(this->m_position, other.m_position))) { return result; }
if ((result = compare(this->m_altitude, other.m_altitude))) { return result; }
if ((result = compare(this->m_heading, other.m_heading))) { return result; }
if ((result = compare(this->m_pitch, other.m_pitch))) { return result; }
if ((result = compare(this->m_bank, other.m_bank))) { return result; }
if ((result = compare(this->m_groundspeed, other.m_groundspeed))) { return result; }
if (this->m_timestamp < other.m_timestamp) { return -1; }
if (this->m_timestamp > other.m_timestamp) { return 1; }
return 0; return 0;
} }
@@ -84,7 +94,7 @@ namespace BlackMisc
bool CAircraftSituation::operator ==(const CAircraftSituation &other) const bool CAircraftSituation::operator ==(const CAircraftSituation &other) const
{ {
if (this == &other) return true; if (this == &other) return true;
return this->getValueHash() == other.getValueHash(); return compare(*this, other) == 0;
} }
/* /*

View File

@@ -90,7 +90,7 @@ namespace BlackMisc
bool CServer::operator ==(const CServer &other) const bool CServer::operator ==(const CServer &other) const
{ {
if (this == &other) return true; if (this == &other) return true;
return this->getValueHash() == other.getValueHash(); return compare(*this, other) == 0;
} }
/* /*

View File

@@ -54,6 +54,12 @@ namespace BlackMisc
{ {
const auto &other = static_cast<const CTextMessage &>(otherBase); const auto &other = static_cast<const CTextMessage &>(otherBase);
int result;
if ((result = compare(this->m_senderCallsign, other.m_senderCallsign))) { return result; }
if ((result = compare(this->m_recipientCallsign, other.m_recipientCallsign))) { return result; }
if ((result = compare(this->m_frequency, other.m_frequency))) { return result; }
if (this->m_received < other.m_received) { return -1; }
if (this->m_received > other.m_received) { return 1; }
return this->m_message.compare(other.m_message); return this->m_message.compare(other.m_message);
} }
@@ -229,7 +235,7 @@ namespace BlackMisc
bool CTextMessage::operator ==(const CTextMessage &other) const bool CTextMessage::operator ==(const CTextMessage &other) const
{ {
if (this == &other) return true; if (this == &other) return true;
return this->getValueHash() == other.getValueHash(); return compare(*this, other);
} }
/* /*

View File

@@ -55,9 +55,13 @@ namespace BlackMisc
/* /*
* Compare * Compare
*/ */
int CSettingsNetwork::compareImpl(const CValueObject &/*otherBase*/) const int CSettingsNetwork::compareImpl(const CValueObject &otherBase) const
{ {
qFatal("not implemented"); const auto &other = static_cast<const CSettingsNetwork &>(otherBase);
int result;
if ((result = compare(this->m_trafficNetworkServerCurrent, other.m_trafficNetworkServerCurrent))) { return result; }
if ((result = compare(this->m_trafficNetworkServers, other.m_trafficNetworkServers))) { return result; }
return 0; return 0;
} }
@@ -85,7 +89,7 @@ namespace BlackMisc
bool CSettingsNetwork::operator ==(const CSettingsNetwork &other) const bool CSettingsNetwork::operator ==(const CSettingsNetwork &other) const
{ {
if (this == &other) return true; if (this == &other) return true;
return this->getValueHash() == other.getValueHash(); return compare(*this, other) == 0;
} }
/* /*