QxOrm  1.2.8
C++ Object Relational Mapping library
QxHashValue.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** http://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 #include <boost/tuple/tuple.hpp>
00052 #include <boost/tuple/tuple_comparison.hpp>
00053 #include <boost/tuple/tuple_io.hpp>
00054 
00055 inline std::size_t hash_value(const QString & s)      { return qHash(s); }
00056 inline std::size_t hash_value(const QDate & d)        { return qHash(d.toJulianDay()); }
00057 inline std::size_t hash_value(const QTime & t)        { return qHash(t.toString()); }
00058 inline std::size_t hash_value(const QDateTime & dt)   { return qHash(dt.toString()); }
00059 inline std::size_t hash_value(const QVariant & v)     { return qHash(v.toString()); }
00060 
00061 template <typename T0, typename T1>
00062 inline std::size_t hash_value(const QPair<T0, T1> & p)
00063 {
00064    std::size_t seed = 0;
00065    boost::hash_combine(seed, p.first);
00066    boost::hash_combine(seed, p.second);
00067    return seed;
00068 }
00069 
00070 namespace boost {
00071 namespace tuples {
00072 
00073 template <typename T0, typename T1>
00074 inline std::size_t hash_value(const boost::tuple<T0, T1> & tu)
00075 {
00076    std::size_t seed = 0;
00077    boost::hash_combine(seed, boost::get<0>(tu));
00078    boost::hash_combine(seed, boost::get<1>(tu));
00079    return seed;
00080 }
00081 
00082 template <typename T0, class T1, typename T2>
00083 inline std::size_t hash_value(const boost::tuple<T0, T1, T2> & tu)
00084 {
00085    std::size_t seed = 0;
00086    boost::hash_combine(seed, boost::get<0>(tu));
00087    boost::hash_combine(seed, boost::get<1>(tu));
00088    boost::hash_combine(seed, boost::get<2>(tu));
00089    return seed;
00090 }
00091 
00092 template <typename T0, typename T1, typename T2, typename T3>
00093 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3> & tu)
00094 {
00095    std::size_t seed = 0;
00096    boost::hash_combine(seed, boost::get<0>(tu));
00097    boost::hash_combine(seed, boost::get<1>(tu));
00098    boost::hash_combine(seed, boost::get<2>(tu));
00099    boost::hash_combine(seed, boost::get<3>(tu));
00100    return seed;
00101 }
00102 
00103 template <typename T0, typename T1, typename T2, typename T3, typename T4>
00104 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4> & tu)
00105 {
00106    std::size_t seed = 0;
00107    boost::hash_combine(seed, boost::get<0>(tu));
00108    boost::hash_combine(seed, boost::get<1>(tu));
00109    boost::hash_combine(seed, boost::get<2>(tu));
00110    boost::hash_combine(seed, boost::get<3>(tu));
00111    boost::hash_combine(seed, boost::get<4>(tu));
00112    return seed;
00113 }
00114 
00115 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00116 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5> & tu)
00117 {
00118    std::size_t seed = 0;
00119    boost::hash_combine(seed, boost::get<0>(tu));
00120    boost::hash_combine(seed, boost::get<1>(tu));
00121    boost::hash_combine(seed, boost::get<2>(tu));
00122    boost::hash_combine(seed, boost::get<3>(tu));
00123    boost::hash_combine(seed, boost::get<4>(tu));
00124    boost::hash_combine(seed, boost::get<5>(tu));
00125    return seed;
00126 }
00127 
00128 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00129 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
00130 {
00131    std::size_t seed = 0;
00132    boost::hash_combine(seed, boost::get<0>(tu));
00133    boost::hash_combine(seed, boost::get<1>(tu));
00134    boost::hash_combine(seed, boost::get<2>(tu));
00135    boost::hash_combine(seed, boost::get<3>(tu));
00136    boost::hash_combine(seed, boost::get<4>(tu));
00137    boost::hash_combine(seed, boost::get<5>(tu));
00138    boost::hash_combine(seed, boost::get<6>(tu));
00139    return seed;
00140 }
00141 
00142 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00143 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
00144 {
00145    std::size_t seed = 0;
00146    boost::hash_combine(seed, boost::get<0>(tu));
00147    boost::hash_combine(seed, boost::get<1>(tu));
00148    boost::hash_combine(seed, boost::get<2>(tu));
00149    boost::hash_combine(seed, boost::get<3>(tu));
00150    boost::hash_combine(seed, boost::get<4>(tu));
00151    boost::hash_combine(seed, boost::get<5>(tu));
00152    boost::hash_combine(seed, boost::get<6>(tu));
00153    boost::hash_combine(seed, boost::get<7>(tu));
00154    return seed;
00155 }
00156 
00157 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00158 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
00159 {
00160    std::size_t seed = 0;
00161    boost::hash_combine(seed, boost::get<0>(tu));
00162    boost::hash_combine(seed, boost::get<1>(tu));
00163    boost::hash_combine(seed, boost::get<2>(tu));
00164    boost::hash_combine(seed, boost::get<3>(tu));
00165    boost::hash_combine(seed, boost::get<4>(tu));
00166    boost::hash_combine(seed, boost::get<5>(tu));
00167    boost::hash_combine(seed, boost::get<6>(tu));
00168    boost::hash_combine(seed, boost::get<7>(tu));
00169    boost::hash_combine(seed, boost::get<8>(tu));
00170    return seed;
00171 }
00172 
00173 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00174 inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
00175 {
00176    std::size_t seed = 0;
00177    boost::hash_combine(seed, boost::get<0>(tu));
00178    boost::hash_combine(seed, boost::get<1>(tu));
00179    boost::hash_combine(seed, boost::get<2>(tu));
00180    boost::hash_combine(seed, boost::get<3>(tu));
00181    boost::hash_combine(seed, boost::get<4>(tu));
00182    boost::hash_combine(seed, boost::get<5>(tu));
00183    boost::hash_combine(seed, boost::get<6>(tu));
00184    boost::hash_combine(seed, boost::get<7>(tu));
00185    boost::hash_combine(seed, boost::get<8>(tu));
00186    boost::hash_combine(seed, boost::get<9>(tu));
00187    return seed;
00188 }
00189 
00190 } // namespace tuples
00191 } // namespace boost
00192 
00193 #endif // _QX_HASH_VALUE_H_