mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
Ref T231, Ref T238 maxValue for PQs
Remark: max() as function name caused compile errors
This commit is contained in:
@@ -19,7 +19,6 @@ namespace BlackMisc
|
||||
{
|
||||
namespace PhysicalQuantities
|
||||
{
|
||||
|
||||
//! Physical unit length (length)
|
||||
class BLACKMISC_EXPORT CLength : public CPhysicalQuantity<CLengthUnit, CLength>
|
||||
{
|
||||
@@ -33,7 +32,6 @@ namespace BlackMisc
|
||||
//! \copydoc CPhysicalQuantity(const QString &unitString)
|
||||
CLength(const QString &unitString) : CPhysicalQuantity(unitString) {}
|
||||
};
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
|
||||
@@ -357,6 +357,22 @@ namespace BlackMisc
|
||||
return this->valueRoundedWithUnit(this->getUnit(), -1, i18n);
|
||||
}
|
||||
|
||||
template<class MU, class PQ>
|
||||
const PQ &CPhysicalQuantity<MU, PQ>::maxValue(const PQ &pq1, const PQ &pq2)
|
||||
{
|
||||
if (pq1.isNull()) { return pq2; }
|
||||
if (pq2.isNull()) { return pq1; }
|
||||
return pq1 > pq2 ? pq1 : pq2;
|
||||
}
|
||||
|
||||
template<class MU, class PQ>
|
||||
const PQ &CPhysicalQuantity<MU, PQ>::minValue(const PQ &pq1, const PQ &pq2)
|
||||
{
|
||||
if (pq1.isNull()) { return pq2; }
|
||||
if (pq2.isNull()) { return pq1; }
|
||||
return pq1 < pq2 ? pq1 : pq2;
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
uint CPhysicalQuantity<MU, PQ>::getValueHash() const
|
||||
{
|
||||
|
||||
@@ -47,11 +47,11 @@ namespace BlackMisc
|
||||
*/
|
||||
template <class MU, class PQ> class CPhysicalQuantity :
|
||||
public Mixin::DBusOperators<CPhysicalQuantity<MU, PQ>>,
|
||||
public Mixin::JsonOperators<CPhysicalQuantity<MU, PQ>>,
|
||||
public Mixin::Index<PQ>,
|
||||
public Mixin::MetaType<PQ>,
|
||||
public Mixin::String<PQ>,
|
||||
public Mixin::Icon<CPhysicalQuantity<MU, PQ>>
|
||||
public Mixin::JsonOperators<CPhysicalQuantity<MU, PQ>>,
|
||||
public Mixin::Index<PQ>,
|
||||
public Mixin::MetaType<PQ>,
|
||||
public Mixin::String<PQ>,
|
||||
public Mixin::Icon<CPhysicalQuantity<MU, PQ>>
|
||||
{
|
||||
//! \copydoc CValueObject::compare
|
||||
friend int compare(const PQ &a, const PQ &b) { return compareImpl(a, b); }
|
||||
@@ -234,6 +234,12 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Maximum of 2 quantities
|
||||
static const PQ &maxValue(const PQ &pq1, const PQ &pq2);
|
||||
|
||||
//! Minimum of 2 quantities
|
||||
static const PQ &minValue(const PQ &pq1, const PQ &pq2);
|
||||
|
||||
protected:
|
||||
//! Constructor with double
|
||||
CPhysicalQuantity(double value, MU unit);
|
||||
|
||||
Reference in New Issue
Block a user