mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
refs #584 Moved hash related stuff to dictionary.h
This also means moving Mixin::Icon from CContainerBase one step down the inheritance hierarchy to resolve what would otherwise have been a circular include dependency.
This commit is contained in:
@@ -468,6 +468,45 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
namespace Mixin
|
||||
{
|
||||
/*!
|
||||
* CRTP class template from which a derived class can inherit common methods dealing with hashing instances by metatuple.
|
||||
*
|
||||
* \tparam Derived Must be registered with BLACK_DECLARE_TUPLE_CONVERSION.
|
||||
*/
|
||||
template <class Derived>
|
||||
class HashByTuple : private Private::EncapsulationBreaker
|
||||
{
|
||||
public:
|
||||
//! qHash overload, needed for storing value in a QSet.
|
||||
friend uint qHash(const Derived &value, uint seed = 0)
|
||||
{
|
||||
return ::qHash(hashImpl(value), seed);
|
||||
}
|
||||
|
||||
private:
|
||||
static uint hashImpl(const Derived &value)
|
||||
{
|
||||
return BlackMisc::qHash(toMetaTuple(value)) ^ baseHash(static_cast<const BaseOfT<Derived> *>(&value));
|
||||
}
|
||||
|
||||
template <typename T> static uint baseHash(const T *base) { return qHash(*base); }
|
||||
static uint baseHash(const void *) { return 0; }
|
||||
};
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculate a single hash value based on a list of individual hash values
|
||||
* \param values
|
||||
* \param className add a hash value for class name on top
|
||||
* \return
|
||||
*/
|
||||
BLACKMISC_EXPORT uint calculateHash(const QList<uint> &values, const char *className);
|
||||
|
||||
//! Hash value, but with int list
|
||||
BLACKMISC_EXPORT uint calculateHash(const QList<int> &values, const char *className);
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
#endif // BLACKMISC_DICTIONARY_H
|
||||
|
||||
Reference in New Issue
Block a user