Ref T259, Ref T243 improvements of PQ

* null()
* allow chaining for makePositive
* abs()
This commit is contained in:
Klaus Basan
2018-03-07 01:28:08 +01:00
parent 67e8f94481
commit 5744c260c5
2 changed files with 27 additions and 4 deletions

View File

@@ -147,15 +147,25 @@ namespace BlackMisc
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::makePositive()
const PQ &CPhysicalQuantity<MU, PQ>::makePositive()
{
if (m_value < 0) { m_value *= -1.0; }
return *this->derived();
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::makeNegative()
const PQ &CPhysicalQuantity<MU, PQ>::makeNegative()
{
if (m_value > 0) { m_value *= -1.0; }
return *this->derived();
}
template<class MU, class PQ>
PQ CPhysicalQuantity<MU, PQ>::abs() const
{
if (m_value >= 0) { return *this->derived(); }
PQ copy(*this->derived());
return copy.makePositive();
}
template <class MU, class PQ>
@@ -373,6 +383,13 @@ namespace BlackMisc
return pq1 < pq2 ? pq1 : pq2;
}
template<class MU, class PQ>
const PQ &CPhysicalQuantity<MU, PQ>::null()
{
static const PQ n(0, MU::nullUnit());
return n;
}
template <class MU, class PQ>
uint CPhysicalQuantity<MU, PQ>::getValueHash() const
{

View File

@@ -193,10 +193,13 @@ namespace BlackMisc
bool isNegativeWithEpsilonConsidered() const;
//! Make value always positive
void makePositive();
const PQ &makePositive();
//! Make value always negative
void makeNegative();
const PQ &makeNegative();
//! Absolute value (always >=0)
PQ abs() const;
//! \copydoc BlackMisc::Mixin::DBusByMetaClass::marshallToDbus
void marshallToDbus(QDBusArgument &argument) const;
@@ -240,6 +243,9 @@ namespace BlackMisc
//! Minimum of 2 quantities
static const PQ &minValue(const PQ &pq1, const PQ &pq2);
//! NULL PQ
static const PQ &null();
protected:
//! Constructor with double
CPhysicalQuantity(double value, MU unit);