mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Ref T268, compare for PQs
This commit is contained in:
@@ -500,8 +500,13 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
int CPhysicalQuantity<MU, PQ>::compareImpl(const PQ &a, const PQ &b)
|
||||
{
|
||||
if (a.isNull() > b.isNull()) { return -1; }
|
||||
if (a.isNull() < b.isNull()) { return 1; }
|
||||
// fetch "null" as we do not know how expensive it is
|
||||
const bool aIsNull = a.isNull();
|
||||
const bool bIsNull = b.isNull();
|
||||
|
||||
if (aIsNull && bIsNull) { return 0; }
|
||||
if (aIsNull > bIsNull) { return -1; }
|
||||
if (aIsNull < bIsNull) { return 1; }
|
||||
|
||||
if (a < b) { return -1; }
|
||||
else if (a > b) { return 1; }
|
||||
|
||||
@@ -228,6 +228,9 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
|
||||
int comparePropertyByIndex(const CPropertyIndex &index, const PQ &pq) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
@@ -237,8 +240,8 @@ namespace BlackMisc
|
||||
//! Parse value from string
|
||||
void parseFromString(const QString &value);
|
||||
|
||||
//! Compare
|
||||
int comparePropertyByIndex(const CPropertyIndex &index, const PQ &pq) const;
|
||||
//! Compare with other PQ
|
||||
int compare(const PQ &other) const { return compareImpl(*this->derived(), other); }
|
||||
|
||||
//! Maximum of 2 quantities
|
||||
static const PQ &maxValue(const PQ &pq1, const PQ &pq2);
|
||||
@@ -246,6 +249,9 @@ namespace BlackMisc
|
||||
//! Minimum of 2 quantities
|
||||
static const PQ &minValue(const PQ &pq1, const PQ &pq2);
|
||||
|
||||
//! Implementation of compare
|
||||
static int compare(const PQ &a, const PQ &b) { return compareImpl(a, b); }
|
||||
|
||||
//! NULL PQ
|
||||
static const PQ &null();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user