Ref T231, Ref T238 maxValue for PQs

Remark: max() as function name caused compile errors
This commit is contained in:
Klaus Basan
2018-01-26 22:22:03 +01:00
parent 7809734d36
commit 844436e744
3 changed files with 27 additions and 7 deletions

View File

@@ -19,7 +19,6 @@ namespace BlackMisc
{ {
namespace PhysicalQuantities namespace PhysicalQuantities
{ {
//! Physical unit length (length) //! Physical unit length (length)
class BLACKMISC_EXPORT CLength : public CPhysicalQuantity<CLengthUnit, CLength> class BLACKMISC_EXPORT CLength : public CPhysicalQuantity<CLengthUnit, CLength>
{ {
@@ -33,7 +32,6 @@ namespace BlackMisc
//! \copydoc CPhysicalQuantity(const QString &unitString) //! \copydoc CPhysicalQuantity(const QString &unitString)
CLength(const QString &unitString) : CPhysicalQuantity(unitString) {} CLength(const QString &unitString) : CPhysicalQuantity(unitString) {}
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -357,6 +357,22 @@ namespace BlackMisc
return this->valueRoundedWithUnit(this->getUnit(), -1, i18n); 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> template <class MU, class PQ>
uint CPhysicalQuantity<MU, PQ>::getValueHash() const uint CPhysicalQuantity<MU, PQ>::getValueHash() const
{ {

View File

@@ -234,6 +234,12 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::String::toQString //! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const; 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: protected:
//! Constructor with double //! Constructor with double
CPhysicalQuantity(double value, MU unit); CPhysicalQuantity(double value, MU unit);