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:
Mathew Sutcliffe
2016-02-08 00:29:08 +00:00
parent c7a0aa2fb4
commit 3bdcd7e386
12 changed files with 100 additions and 107 deletions

View File

@@ -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