mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
Ref T259, Ref T243 improvements of PQ
* null() * allow chaining for makePositive * abs()
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user