mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +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:
@@ -429,15 +429,32 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* metaTypeId
|
||||
*/
|
||||
int CAtcStation::getMetaTypeId() const
|
||||
{
|
||||
return qMetaTypeId<CAtcStation>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CAtcStation::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CAtcStation>()) { return true; }
|
||||
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CAtcStation::compare(const QVariant &qv) const
|
||||
int CAtcStation::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
Q_ASSERT(qv.canConvert<CAtcStation>());
|
||||
Q_ASSERT(!qv.isNull() && qv.isValid());
|
||||
CAtcStation atc = qv.value<CAtcStation>();
|
||||
return this->getCallsign().compare(atc.getCallsign());
|
||||
const auto &other = static_cast<const CAtcStation &>(otherBase);
|
||||
|
||||
return this->getCallsign().asString().compare(other.getCallsign().asString(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user