QxOrm  1.4.5
C++ Object Relational Mapping library
QxHashValue.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://www.qxorm.com/
00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
00005 **
00006 ** This file is part of the QxOrm library
00007 **
00008 ** This software is provided 'as-is', without any express or implied
00009 ** warranty. In no event will the authors be held liable for any
00010 ** damages arising from the use of this software
00011 **
00012 ** Commercial Usage
00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
00014 ** accordance with the commercial license agreement provided with the
00015 ** Software or, alternatively, in accordance with the terms contained in
00016 ** a written agreement between you and Lionel Marty
00017 **
00018 ** GNU General Public License Usage
00019 ** Alternatively, this file may be used under the terms of the GNU
00020 ** General Public License version 3.0 as published by the Free Software
00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
00022 ** packaging of this file. Please review the following information to
00023 ** ensure the GNU General Public License version 3.0 requirements will be
00024 ** met : http://www.gnu.org/copyleft/gpl.html
00025 **
00026 ** If you are unsure which license is appropriate for your use, or
00027 ** if you have questions regarding the use of this file, please contact :
00028 ** contact@qxorm.com
00029 **
00030 ****************************************************************************/
00031 
00032 #ifndef _QX_HASH_VALUE_H_
00033 #define _QX_HASH_VALUE_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <QtCore/qstring.h>
00047 #include <QtCore/qdatetime.h>
00048 #include <QtCore/qvariant.h>
00049 #include <QtCore/qpair.h>
00050 
00051 inline std::size_t hash_value(const QString & s)      { return qHash(s); }
00052 inline std::size_t hash_value(const QDate & d)        { return qHash(d.toJulianDay()); }
00053 inline std::size_t hash_value(const QTime & t)        { return qHash(t.toString()); }
00054 inline std::size_t hash_value(const QDateTime & dt)   { return qHash(dt.toString()); }
00055 inline std::size_t hash_value(const QVariant & v)     { return qHash(v.toString()); }
00056 
00057 inline uint qHash(const QDate & d)                    { return static_cast<uint>(hash_value(d)); }
00058 inline uint qHash(const QTime & t)                    { return static_cast<uint>(hash_value(t)); }
00059 inline uint qHash(const QDateTime & dt)               { return static_cast<uint>(hash_value(dt)); }
00060 inline uint qHash(const QVariant & v)                 { return static_cast<uint>(hash_value(v)); }
00061 
00062 #ifndef QT_NO_STL
00063 inline uint qHash(const std::string & s)              { QString tmp = QString::fromStdString(s); return qHash(tmp); }
00064 inline uint qHash(const std::wstring & s)             { QString tmp = QString::fromStdWString(s); return qHash(tmp); }
00065 #else // QT_NO_STL
00066 inline uint qHash(const std::string & s)              { QString tmp = QString::fromLatin1(s.data(), int(s.size())); return qHash(tmp); }
00067 inline uint qHash(const std::wstring & s)             { qAssert(false); /* Need STL compatibility ! */ return 0; }
00068 #endif // QT_NO_STL
00069 
00070 namespace qx {
00071 template <class T>
00072 inline void hash_combine(std::size_t & seed, const T & t)
00073 { seed ^= qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2); }
00074 } // namespace qx
00075 
00076 template <typename T0, typename T1>
00077 inline std::size_t hash_value(const QPair<T0, T1> & p)
00078 {
00079    std::size_t seed = 0;
00080    qx::hash_combine(seed, p.first);
00081    qx::hash_combine(seed, p.second);
00082    return seed;
00083 }
00084 
00085 #ifdef _QX_ENABLE_BOOST
00086 
00087 namespace boost {
00088 namespace tuples {
00089 
00090 template <typename T0, typename T1>
00091 inline std::size_t hash_value(const boost::tuple<T0, T1> & tu)
00092 {
00093    std::size_t seed = 0;
00094    qx::hash_combine(seed, boost::get<0>(tu));
00095    qx::hash_combine(seed, boost::get<1>(tu));
00096    return seed;
00097 }
00098 
00099 template <typename T0, class T1, typename T2>
00100 inline std::size_t hash_value(const boost::tuple<T0, T1, T2> & tu)
00101 {
00102    std::size_t seed = 0;
00103    qx::hash_combine(seed, boost::get<0>(tu));
00104    qx::hash_combine(seed, boost::get<1>(tu));
00105    qx::hash_combine(seed, boost::get<2>(tu));
00106    return seed;
00107 }
00108 
00109 template <typename T0, typename T1, typename T2, typename T3>
00110 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3> & tu)
00111 {
00112    std::size_t seed = 0;
00113    qx::hash_combine(seed, boost::get<0>(tu));
00114    qx::hash_combine(seed, boost::get<1>(tu));
00115    qx::hash_combine(seed, boost::get<2>(tu));
00116    qx::hash_combine(seed, boost::get<3>(tu));
00117    return seed;
00118 }
00119 
00120 template <typename T0, typename T1, typename T2, typename T3, typename T4>
00121 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4> & tu)
00122 {
00123    std::size_t seed = 0;
00124    qx::hash_combine(seed, boost::get<0>(tu));
00125    qx::hash_combine(seed, boost::get<1>(tu));
00126    qx::hash_combine(seed, boost::get<2>(tu));
00127    qx::hash_combine(seed, boost::get<3>(tu));
00128    qx::hash_combine(seed, boost::get<4>(tu));
00129    return seed;
00130 }
00131 
00132 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00133 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5> & tu)
00134 {
00135    std::size_t seed = 0;
00136    qx::hash_combine(seed, boost::get<0>(tu));
00137    qx::hash_combine(seed, boost::get<1>(tu));
00138    qx::hash_combine(seed, boost::get<2>(tu));
00139    qx::hash_combine(seed, boost::get<3>(tu));
00140    qx::hash_combine(seed, boost::get<4>(tu));
00141    qx::hash_combine(seed, boost::get<5>(tu));
00142    return seed;
00143 }
00144 
00145 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00146 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
00147 {
00148    std::size_t seed = 0;
00149    qx::hash_combine(seed, boost::get<0>(tu));
00150    qx::hash_combine(seed, boost::get<1>(tu));
00151    qx::hash_combine(seed, boost::get<2>(tu));
00152    qx::hash_combine(seed, boost::get<3>(tu));
00153    qx::hash_combine(seed, boost::get<4>(tu));
00154    qx::hash_combine(seed, boost::get<5>(tu));
00155    qx::hash_combine(seed, boost::get<6>(tu));
00156    return seed;
00157 }
00158 
00159 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00160 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
00161 {
00162    std::size_t seed = 0;
00163    qx::hash_combine(seed, boost::get<0>(tu));
00164    qx::hash_combine(seed, boost::get<1>(tu));
00165    qx::hash_combine(seed, boost::get<2>(tu));
00166    qx::hash_combine(seed, boost::get<3>(tu));
00167    qx::hash_combine(seed, boost::get<4>(tu));
00168    qx::hash_combine(seed, boost::get<5>(tu));
00169    qx::hash_combine(seed, boost::get<6>(tu));
00170    qx::hash_combine(seed, boost::get<7>(tu));
00171    return seed;
00172 }
00173 
00174 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00175 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
00176 {
00177    std::size_t seed = 0;
00178    qx::hash_combine(seed, boost::get<0>(tu));
00179    qx::hash_combine(seed, boost::get<1>(tu));
00180    qx::hash_combine(seed, boost::get<2>(tu));
00181    qx::hash_combine(seed, boost::get<3>(tu));
00182    qx::hash_combine(seed, boost::get<4>(tu));
00183    qx::hash_combine(seed, boost::get<5>(tu));
00184    qx::hash_combine(seed, boost::get<6>(tu));
00185    qx::hash_combine(seed, boost::get<7>(tu));
00186    qx::hash_combine(seed, boost::get<8>(tu));
00187    return seed;
00188 }
00189 
00190 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00191 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
00192 {
00193    std::size_t seed = 0;
00194    qx::hash_combine(seed, boost::get<0>(tu));
00195    qx::hash_combine(seed, boost::get<1>(tu));
00196    qx::hash_combine(seed, boost::get<2>(tu));
00197    qx::hash_combine(seed, boost::get<3>(tu));
00198    qx::hash_combine(seed, boost::get<4>(tu));
00199    qx::hash_combine(seed, boost::get<5>(tu));
00200    qx::hash_combine(seed, boost::get<6>(tu));
00201    qx::hash_combine(seed, boost::get<7>(tu));
00202    qx::hash_combine(seed, boost::get<8>(tu));
00203    qx::hash_combine(seed, boost::get<9>(tu));
00204    return seed;
00205 }
00206 
00207 } // namespace tuples
00208 } // namespace boost
00209 
00210 template <typename T0, typename T1>
00211 inline uint qHash(const boost::tuple<T0, T1> & tu)
00212 { return static_cast<uint>(hash_value(tu)); }
00213 
00214 template <typename T0, class T1, typename T2>
00215 inline uint qHash(const boost::tuple<T0, T1, T2> & tu)
00216 { return static_cast<uint>(hash_value(tu)); }
00217 
00218 template <typename T0, typename T1, typename T2, typename T3>
00219 inline uint qHash(const boost::tuple<T0, T1, T2, T3> & tu)
00220 { return static_cast<uint>(hash_value(tu)); }
00221 
00222 template <typename T0, typename T1, typename T2, typename T3, typename T4>
00223 inline uint qHash(const boost::tuple<T0, T1, T2, T3, T4> & tu)
00224 { return static_cast<uint>(hash_value(tu)); }
00225 
00226 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00227 inline uint qHash(const boost::tuple<T0, T1, T2, T3, T4, T5> & tu)
00228 { return static_cast<uint>(hash_value(tu)); }
00229 
00230 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00231 inline uint qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
00232 { return static_cast<uint>(hash_value(tu)); }
00233 
00234 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00235 inline uint qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
00236 { return static_cast<uint>(hash_value(tu)); }
00237 
00238 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00239 inline uint qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
00240 { return static_cast<uint>(hash_value(tu)); }
00241 
00242 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00243 inline uint qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
00244 { return static_cast<uint>(hash_value(tu)); }
00245 
00246 #endif // _QX_ENABLE_BOOST
00247 
00248 template <typename T0, typename T1>
00249 inline std::size_t hash_value(const std::tuple<T0, T1> & tu)
00250 {
00251    std::size_t seed = 0;
00252    qx::hash_combine(seed, std::get<0>(tu));
00253    qx::hash_combine(seed, std::get<1>(tu));
00254    return seed;
00255 }
00256 
00257 template <typename T0, class T1, typename T2>
00258 inline std::size_t hash_value(const std::tuple<T0, T1, T2> & tu)
00259 {
00260    std::size_t seed = 0;
00261    qx::hash_combine(seed, std::get<0>(tu));
00262    qx::hash_combine(seed, std::get<1>(tu));
00263    qx::hash_combine(seed, std::get<2>(tu));
00264    return seed;
00265 }
00266 
00267 template <typename T0, typename T1, typename T2, typename T3>
00268 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3> & tu)
00269 {
00270    std::size_t seed = 0;
00271    qx::hash_combine(seed, std::get<0>(tu));
00272    qx::hash_combine(seed, std::get<1>(tu));
00273    qx::hash_combine(seed, std::get<2>(tu));
00274    qx::hash_combine(seed, std::get<3>(tu));
00275    return seed;
00276 }
00277 
00278 template <typename T0, typename T1, typename T2, typename T3, typename T4>
00279 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4> & tu)
00280 {
00281    std::size_t seed = 0;
00282    qx::hash_combine(seed, std::get<0>(tu));
00283    qx::hash_combine(seed, std::get<1>(tu));
00284    qx::hash_combine(seed, std::get<2>(tu));
00285    qx::hash_combine(seed, std::get<3>(tu));
00286    qx::hash_combine(seed, std::get<4>(tu));
00287    return seed;
00288 }
00289 
00290 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00291 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5> & tu)
00292 {
00293    std::size_t seed = 0;
00294    qx::hash_combine(seed, std::get<0>(tu));
00295    qx::hash_combine(seed, std::get<1>(tu));
00296    qx::hash_combine(seed, std::get<2>(tu));
00297    qx::hash_combine(seed, std::get<3>(tu));
00298    qx::hash_combine(seed, std::get<4>(tu));
00299    qx::hash_combine(seed, std::get<5>(tu));
00300    return seed;
00301 }
00302 
00303 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00304 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
00305 {
00306    std::size_t seed = 0;
00307    qx::hash_combine(seed, std::get<0>(tu));
00308    qx::hash_combine(seed, std::get<1>(tu));
00309    qx::hash_combine(seed, std::get<2>(tu));
00310    qx::hash_combine(seed, std::get<3>(tu));
00311    qx::hash_combine(seed, std::get<4>(tu));
00312    qx::hash_combine(seed, std::get<5>(tu));
00313    qx::hash_combine(seed, std::get<6>(tu));
00314    return seed;
00315 }
00316 
00317 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00318 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
00319 {
00320    std::size_t seed = 0;
00321    qx::hash_combine(seed, std::get<0>(tu));
00322    qx::hash_combine(seed, std::get<1>(tu));
00323    qx::hash_combine(seed, std::get<2>(tu));
00324    qx::hash_combine(seed, std::get<3>(tu));
00325    qx::hash_combine(seed, std::get<4>(tu));
00326    qx::hash_combine(seed, std::get<5>(tu));
00327    qx::hash_combine(seed, std::get<6>(tu));
00328    qx::hash_combine(seed, std::get<7>(tu));
00329    return seed;
00330 }
00331 
00332 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00333 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
00334 {
00335    std::size_t seed = 0;
00336    qx::hash_combine(seed, std::get<0>(tu));
00337    qx::hash_combine(seed, std::get<1>(tu));
00338    qx::hash_combine(seed, std::get<2>(tu));
00339    qx::hash_combine(seed, std::get<3>(tu));
00340    qx::hash_combine(seed, std::get<4>(tu));
00341    qx::hash_combine(seed, std::get<5>(tu));
00342    qx::hash_combine(seed, std::get<6>(tu));
00343    qx::hash_combine(seed, std::get<7>(tu));
00344    qx::hash_combine(seed, std::get<8>(tu));
00345    return seed;
00346 }
00347 
00348 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00349 inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
00350 {
00351    std::size_t seed = 0;
00352    qx::hash_combine(seed, std::get<0>(tu));
00353    qx::hash_combine(seed, std::get<1>(tu));
00354    qx::hash_combine(seed, std::get<2>(tu));
00355    qx::hash_combine(seed, std::get<3>(tu));
00356    qx::hash_combine(seed, std::get<4>(tu));
00357    qx::hash_combine(seed, std::get<5>(tu));
00358    qx::hash_combine(seed, std::get<6>(tu));
00359    qx::hash_combine(seed, std::get<7>(tu));
00360    qx::hash_combine(seed, std::get<8>(tu));
00361    qx::hash_combine(seed, std::get<9>(tu));
00362    return seed;
00363 }
00364 
00365 template <typename T0, typename T1>
00366 inline uint qHash(const std::tuple<T0, T1> & tu)
00367 { return static_cast<uint>(hash_value(tu)); }
00368 
00369 template <typename T0, class T1, typename T2>
00370 inline uint qHash(const std::tuple<T0, T1, T2> & tu)
00371 { return static_cast<uint>(hash_value(tu)); }
00372 
00373 template <typename T0, typename T1, typename T2, typename T3>
00374 inline uint qHash(const std::tuple<T0, T1, T2, T3> & tu)
00375 { return static_cast<uint>(hash_value(tu)); }
00376 
00377 template <typename T0, typename T1, typename T2, typename T3, typename T4>
00378 inline uint qHash(const std::tuple<T0, T1, T2, T3, T4> & tu)
00379 { return static_cast<uint>(hash_value(tu)); }
00380 
00381 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00382 inline uint qHash(const std::tuple<T0, T1, T2, T3, T4, T5> & tu)
00383 { return static_cast<uint>(hash_value(tu)); }
00384 
00385 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00386 inline uint qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
00387 { return static_cast<uint>(hash_value(tu)); }
00388 
00389 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00390 inline uint qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
00391 { return static_cast<uint>(hash_value(tu)); }
00392 
00393 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00394 inline uint qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
00395 { return static_cast<uint>(hash_value(tu)); }
00396 
00397 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00398 inline uint qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
00399 { return static_cast<uint>(hash_value(tu)); }
00400 
00401 #endif // _QX_HASH_VALUE_H_