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
@@ -12,6 +12,8 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
// forward declaration
|
||||
class CValueMap;
|
||||
|
||||
/*!
|
||||
* \brief Base class for value objects.
|
||||
@@ -132,6 +134,21 @@ namespace BlackMisc
|
||||
*/
|
||||
std::string toStdString(bool i18n = false) const;
|
||||
|
||||
/*!
|
||||
* \brief Value hash, allows comparisons between QVariants
|
||||
* \return
|
||||
*/
|
||||
virtual uint getValueHash() const = 0;
|
||||
|
||||
/*!
|
||||
* Compares with QVariant with this object
|
||||
* and returns an integer less than, equal to, or greater than zero
|
||||
* if this is less than, equal to, or greater than QVariant.
|
||||
* \remarks allows sorting among QVariants, not all classes implement this
|
||||
* \return
|
||||
*/
|
||||
virtual int compare(const QVariant &qv) const;
|
||||
|
||||
/*!
|
||||
* \brief Virtual method to return QVariant, used with DBUS QVariant lists
|
||||
* \return
|
||||
@@ -216,6 +233,48 @@ namespace BlackMisc
|
||||
return argument << static_cast<CValueObject const &>(uc);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Allow comparison with QVariant, e.g.
|
||||
* QVariant == CFrequency ?
|
||||
*/
|
||||
template <class T> typename std::enable_if<std::is_base_of<CValueObject, T>::value, bool>::type
|
||||
operator==(const QVariant &variant, const T &uc)
|
||||
{
|
||||
if (!variant.canConvert<T>()) return false;
|
||||
T vuc = variant.value<T>();
|
||||
return vuc == uc;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Allow comparison with QVariant, e.g.
|
||||
* QVariant != CFrequency ?
|
||||
*/
|
||||
template <class T> typename std::enable_if<std::is_base_of<CValueObject, T>::value, bool>::type
|
||||
operator!=(const QVariant &variant, const T &uc)
|
||||
{
|
||||
return !(variant == uc);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Allow comparison with QVariant, e.g.
|
||||
* QVariant == CFrequency ?
|
||||
*/
|
||||
template <class T> typename std::enable_if<std::is_base_of<CValueObject, T>::value, bool>::type
|
||||
operator==(const T &uc, const QVariant &variant)
|
||||
{
|
||||
return variant == uc;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Allow comparison with QVariant, e.g.
|
||||
* QVariant != CFrequency ?
|
||||
*/
|
||||
template <class T> typename std::enable_if<std::is_base_of<CValueObject, T>::value, bool>::type
|
||||
operator!=(const T &uc, const QVariant &variant)
|
||||
{
|
||||
return variant != uc;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user