]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/hashset.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHashSet class
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HASHSET_H_
13 #define _WX_HASHSET_H_
15 #include "wx/hashmap.h"
17 // see comment in wx/hashmap.h which also applies to different standard hash
21 (defined(HAVE_STD_UNORDERED_SET) || defined(HAVE_TR1_UNORDERED_SET))
23 #if defined(HAVE_STD_UNORDERED_SET)
24 #include <unordered_set>
25 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
26 typedef std::unordered_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME
27 #elif defined(HAVE_TR1_UNORDERED_SET)
28 #include <tr1/unordered_set>
29 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
30 typedef std::tr1::unordered_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME
32 #error Update this code: unordered_set is available, but I do not know where.
35 #elif wxUSE_STL && defined(HAVE_STL_HASH_MAP)
37 #if defined(HAVE_EXT_HASH_MAP)
38 #include <ext/hash_set>
39 #elif defined(HAVE_HASH_MAP)
43 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
44 typedef WX_HASH_MAP_NAMESPACE::hash_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME
46 #else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
48 // this is a complex way of defining an easily inlineable identity function...
49 #define _WX_DECLARE_HASH_SET_KEY_EX( KEY_T, CLASSNAME, CLASSEXP ) \
52 typedef KEY_T key_type; \
53 typedef const key_type const_key_type; \
54 typedef const_key_type& const_key_reference; \
57 const_key_reference operator()( const_key_reference key ) const \
60 /* the dummy assignment operator is needed to suppress compiler */ \
61 /* warnings from hash table class' operator=(): gcc complains about */ \
62 /* "statement with no effect" without it */ \
63 CLASSNAME& operator=(const CLASSNAME&) { return *this; } \
66 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
67 _WX_DECLARE_HASH_SET_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \
68 _WX_DECLARE_HASHTABLE( KEY_T, KEY_T, HASH_T, CLASSNAME##_wxImplementation_KeyEx, KEY_EQ_T, CLASSNAME##_wxImplementation_HashTable, CLASSEXP, grow_lf70, never_shrink ) \
69 CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \
72 _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \
74 wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \
75 key_equal eq = key_equal() ) \
76 : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \
77 CLASSNAME##_wxImplementation_KeyEx() ) {} \
79 Insert_Result insert( const key_type& key ) \
82 Node *node = GetOrCreateNode( key, created ); \
83 return Insert_Result( iterator( node, this ), created ); \
86 const_iterator find( const const_key_type& key ) const \
88 return const_iterator( GetNode( key ), this ); \
91 iterator find( const const_key_type& key ) \
93 return iterator( GetNode( key ), this ); \
96 size_type erase( const key_type& k ) \
97 { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \
98 void erase( const iterator& it ) { erase( *it ); } \
99 void erase( const const_iterator& it ) { erase( *it ); } \
101 /* count() == 0 | 1 */ \
102 size_type count( const const_key_type& key ) \
103 { return GetNode( key ) ? 1 : 0; } \
106 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
108 // these macros are to be used in the user code
109 #define WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \
110 _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, class )
112 // and these do exactly the same thing but should be used inside the
114 #define WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL) \
115 _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL )
117 #define WX_DECLARE_EXPORTED_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \
118 WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, \
119 CLASSNAME, class WXDLLIMPEXP_CORE )
121 // delete all hash elements
123 // NB: the class declaration of the hash elements must be visible from the
124 // place where you use this macro, otherwise the proper destructor may not
125 // be called (a decent compiler should give a warning about it, but don't
127 #define WX_CLEAR_HASH_SET(type, hashset) \
129 type::iterator it, en; \
130 for( it = (hashset).begin(), en = (hashset).end(); it != en; ++it ) \
135 #endif // _WX_HASHSET_H_