]> git.lyx.org Git - lyx.git/blob - src/support/metahash.h
Make Thesaurus check for more general dictionaries (en-v2.idx)
[lyx.git] / src / support / metahash.h
1 // -*- C++ -*-
2 /**
3  * \file methash.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Peter Kümmel
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * Code by Tor Brede Vekterli 
12  * http://arcticinteractive.com/2009/04/18/compile-time-string-hashing-boost-mpl/
13  * (Boost 1.0 license.)
14  *
15  */
16
17 #ifndef LYX_META_HASH_H
18 #define LYX_META_HASH_H
19
20 #include <boost/mpl/string.hpp>
21 #include <boost/mpl/fold.hpp>
22 #include <boost/mpl/size_t.hpp>
23 #include <boost/functional/hash.hpp>
24
25
26
27 namespace lyx {
28 namespace support {
29
30 #ifdef _MSC_VER
31 #pragma warning(push)
32 // disable addition overflow warning
33 #pragma warning(disable:4307)
34 #endif
35
36     template <typename Seed, typename Value>
37     struct hash_combine
38     {
39       typedef boost::mpl::size_t<
40         Seed::value ^ (static_cast<std::size_t>(Value::value)
41                 + 0x9e3779b9 + (Seed::value << 6) + (Seed::value >> 2))
42       > type;
43     };
44
45 #ifdef _MSC_VER
46 #pragma warning(pop)
47 #endif
48
49     // Hash any sequence of integral wrapper types
50     template <typename Sequence>
51     struct hash_sequence
52       : boost::mpl::fold<
53             Sequence
54           , boost::mpl::size_t<0> 
55                   , hash_combine<boost::mpl::_1, boost::mpl::_2>
56         >::type
57     {};
58
59     // For hashing std::strings et al that don't include the zero-terminator
60     template <typename String>
61     struct hash_string : hash_sequence<String>
62     {};
63
64     // Hash including terminating zero for char arrays
65     template <typename String>
66     struct hash_cstring
67       : hash_combine< hash_sequence<String>, boost::mpl::size_t<0> >::type
68     {};
69
70
71 }
72
73 #endif