mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +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:
@@ -152,6 +152,36 @@ namespace BlackMisc
|
||||
return str += "}";
|
||||
}
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::getMetaTypeId
|
||||
*/
|
||||
virtual int getMetaTypeId() const { return qMetaTypeId<C<T>>(); }
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::isA
|
||||
*/
|
||||
virtual bool isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<C<T>>()) { return true; }
|
||||
return CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::compareImpl
|
||||
*/
|
||||
virtual int compareImpl(const CValueObject &/*other*/) const
|
||||
{
|
||||
//const auto &o = static_cast<const CContainerBase &>(other);
|
||||
//if (derived().size() < o.derived().size()) { return -1; }
|
||||
//if (derived().size() > o.derived().size()) { return 1; }
|
||||
//for (auto i1 = derived().begin(), i2 = o.derived().begin(); i1 != derived().end() && i2 != o.derived().end(); ++i1, ++i2)
|
||||
//{
|
||||
// if (*i1 < *i2) { return -1; }
|
||||
// if (*i1 > *i2) { return 1; }
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument.beginArray(qMetaTypeId<T>());
|
||||
|
||||
Reference in New Issue
Block a user