mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
refs #84 removed the CValueObject::compare method and added a friend function BlackMisc::compare to replace it.
The new compare is implemented using "multimethods" described in the book Advanced C++ Programming Styles and Idioms by James Coplien. First, the isA method is used to determine which of the values being compared is the most general. (For example, CLength is more general than CAltitude.) Then the compareImpl method is called on the most general value, with the other value as an argument. If there is not a direct inheritance relation between the two values (or they are the same class) then the comparison is invalid and a assert is triggered.
This commit is contained in:
@@ -98,21 +98,31 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
* metaTypeId
|
||||
*/
|
||||
int CCallsign::compare(const QVariant &qv) const
|
||||
int CCallsign::getMetaTypeId() const
|
||||
{
|
||||
Q_ASSERT(qv.canConvert<CCallsign>());
|
||||
Q_ASSERT(!qv.isNull() && qv.isValid());
|
||||
return this->compare(qv.value<CCallsign>());
|
||||
return qMetaTypeId<CCallsign>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CCallsign::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CCallsign>()) { return true; }
|
||||
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CCallsign::compare(const CCallsign &callsign) const
|
||||
int CCallsign::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
return this->m_callsign.compare(callsign.asString(), Qt::CaseInsensitive);
|
||||
const auto &other = static_cast<const CCallsign &>(otherBase);
|
||||
|
||||
return this->m_callsign.compare(other.asString(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user