mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +08:00
using hashes to perform comparisons between blackmisc value objects stored inside of QVariant
refs #81
This commit is contained in:
committed by
Mathew Sutcliffe
parent
67a5dbfe48
commit
a280d239e6
@@ -254,6 +254,36 @@ namespace BlackMisc
|
||||
return this->valueRoundedWithUnit(this->getUnit(), -1, i18n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
template <class MU, class PQ> uint CPhysicalQuantity<MU, PQ>::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << this->m_unit.getValueHash();
|
||||
hashs << qHash(static_cast<long>(this->m_value));
|
||||
return BlackMisc::calculateHash(hashs, "PQ");
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
template <class MU, class PQ> int CPhysicalQuantity<MU, PQ>::compare(const QVariant &qv) const
|
||||
{
|
||||
Q_ASSERT(qv.canConvert<PQ>());
|
||||
Q_ASSERT(!qv.isNull() && qv.isValid());
|
||||
return this->compare(qv.value<PQ>());
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
template <class MU, class PQ> int CPhysicalQuantity<MU, PQ>::compare(const PQ &other) const
|
||||
{
|
||||
if (other == (*this)) return 0;
|
||||
return ((*this) < other) ? -1 : 1;
|
||||
}
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CPhysicalQuantity<CLengthUnit, CLength>;
|
||||
|
||||
Reference in New Issue
Block a user