Code

aaf7719591714f8182dc959b76a8704bd6df755d
[inkscape.git] / src / util / unordered-containers.h
1 /** @file
2  * @brief Compatibility wrapper for unordered containers.
3  */
4 /* Authors:
5  *   Jon A. Cruz <jon@joncruz.org>
6  *   Krzysztof KosiƄski <tweenk.pl@gmail.com>
7  *
8  * Copyright (C) 2010 Authors
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifndef SEEN_INK_UTIL_UNORDERED_CONTAINERS_H
13 #define SEEN_INK_UTIL_UNORDERED_CONTAINERS_H
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #ifndef DOXYGEN_SHOULD_SKIP_THIS
20 #if defined(HAVE_TR1_UNORDERED_SET)
22 # include <tr1/unordered_set>
23 # include <tr1/unordered_map>
24 # define INK_UNORDERED_SET std::tr1::unordered_set
25 # define INK_UNORDERED_MAP std::tr1::unordered_map
26 # define INK_HASH std::tr1::hash
28 #elif defined(HAVE_BOOST_UNORDERED_SET)
29 # include <boost/unordered_set.hpp>
30 # include <boost/unordered_map.hpp>
31 # define INK_UNORDERED_SET boost::unordered_set
32 # define INK_UNORDERED_MAP boost::unordered_map
33 # define INK_HASH boost::hash
35 #elif defined(HAVE_EXT_HASH_SET)
37 # include <functional>
38 # include <ext/hash_set>
39 # include <ext/hash_map>
40 # define INK_UNORDERED_SET __gnu_cxx::hash_set
41 # define INK_UNORDERED_MAP __gnu_cxx::hash_map
42 # define INK_HASH __gnu_cxx::hash
44 namespace __gnu_cxx {
45 // hash function for pointers
46 // TR1 and Boost have this defined by default, __gnu_cxx doesn't
47 template<typename T>
48 struct hash<T *> : public std::unary_function<T *, std::size_t> {
49     std::size_t operator()(T *p) const {
50         // Taken from Boost
51         std::size_t x = static_cast<std::size_t>(reinterpret_cast<std::ptrdiff_t>(p));
52         return x + (x >> 3);
53     }
54 };
55 } // namespace __gnu_cxx
56 #endif
58 #else
59 /// Name (with namespace) of the unordered set template.
60 #define INK_UNORDERED_SET
61 /// Name (with namespace) of the unordered map template.
62 #define INK_UNORDERED_MAP
63 /// Name (with namespace) of the hash template.
64 #define INK_HASH
66 #endif
68 #endif // SEEN_SET_TYPES_H
69 /*
70   Local Variables:
71   mode:c++
72   c-file-style:"stroustrup"
73   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74   indent-tabs-mode:nil
75   fill-column:99
76   End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :